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;
}
相关推荐
apocelipes14 小时前
常用编程语言和库的正则表达式性能对比
c语言·c++·python·性能优化·golang·开发工具和环境
郝学胜_神的一滴2 天前
CMake 034:生成器表达式:解耦构建时序、精简分支逻辑的终极利器
c++·cmake
见过夏天3 天前
C++ 基础入门完全指南
c++
用户805533698034 天前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
BadBadBad__AK4 天前
线段树维护区间 k 次方和
c++·数学·算法·stl
卷无止境5 天前
Eigen 库如何借助 OpenMP 加速计算
c++·后端
卷无止境5 天前
OpenMPI、MPICH 与 OpenMP:关系、核心概念与架构全解
c++·后端
郝学胜_神的一滴6 天前
CMake 30:循环语法全解|foreach_while双循环精讲、迭代技巧与实战避坑指南
c++·cmake
卷无止境8 天前
C++ 的Eigen 库全解析
c++
卷无止境8 天前
现代 C++特性大盘点:一门脱胎换骨的老语言
c++·后端