C++ 一种简单的软件验证码 程序授权使用 收费付费使用 无需注册 用机器码得到一个加密值 再对比加密值是否一致 只需加密

简单软件授权方案

1、获取机器码,发给软件开发者

2、开发者用机器码加密得到一个密文 发给使用者

3、使用者 用这个密文 与本地计算密文比较密文是否一致,一致就把密文写入到注册表,下次登录从注册表读密文对比。

(最重要的是密文生成的方法保密)(只需加密,不用解密)

cpp 复制代码
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>

std::string encryptDecrypt(const std::string& input, const char key) {
	std::string output = input;

	for (size_t i = 0; i < input.size(); ++i) {
		output[i] = input[i] ^ key;
	}

	return output;
}
std::string toHexString(const std::string& input) {
	std::stringstream ss;
	for (const auto& c : input) {
		ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(c);
	}
	return ss.str();
}
std::string fromHexString(const std::string& input) {
	std::string output;
	std::stringstream ss;
	for (size_t i = 0; i < input.size(); i += 2) {
		int value;
		ss << std::hex << input.substr(i, 2);
		ss >> value;
		output.push_back(static_cast<char>(value));
		ss.clear();
	}
	return output;
}

int main(int argc, char* argv[]) {
	std::string input = "Hello, World!";

	if (argc != 2) {
		std::cout << "Usage: " << " <filename> <orignal string>" << std::endl;
		std::cout << "示例: <filename> "<<input << std::endl;
	}
	else
	{
		input = argv[1];
	}

	std::cout << "原字符串: " << input << std::endl;
	char key = 'K';

	std::string encrypted = encryptDecrypt(input, key);
	std::cout << "加密后的字符串: " << encrypted << std::endl;

	std::string hexString = toHexString(encrypted);
	std::cout << "加密后的16进制字符串: " << hexString << std::endl;

	std::string decrypted = encryptDecrypt(fromHexString(hexString), key);
	std::cout << "解密后的字符串: " << decrypted << std::endl;

	return 0;
}
相关推荐
xiaoye37082 小时前
Java 自动装箱 / 拆箱 原理详解
java·开发语言
ZTLJQ4 小时前
数据的基石:Python中关系型数据库完全解析
开发语言·数据库·python
夏霞4 小时前
c# signlar 客户端传递参数给服务端配置方法
开发语言·c#
迷藏4944 小时前
**发散创新:基于 Rust的开源权限管理系统设计与实战**在现代软件架构中,**权限控制**早已不
java·开发语言·rust·开源
2301_818419015 小时前
C++中的解释器模式变体
开发语言·c++·算法
爱学习的大牛1235 小时前
windows tcpview 类似功能 c++
c++
摇滚侠5 小时前
Java 项目《谷粒商城-1》架构师级Java 项目实战,对标阿里 P6-P7,全网最强,实操版本
java·开发语言
biter down5 小时前
C++11 统一列表初始化+std::initializer_list
开发语言·c++
ShineWinsu6 小时前
爬虫对抗:ZLibrary反爬机制实战分析技术文章大纲
c++
telllong6 小时前
BeeWare:Python原生移动应用开发
开发语言·python