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;
}
相关推荐
孤寂大仙v几秒前
【C++】STL----list常见用法
开发语言·c++·list
她似晚风般温柔7891 小时前
Uniapp + Vue3 + Vite +Uview + Pinia 分商家实现购物车功能(最新附源码保姆级)
开发语言·javascript·uni-app
咩咩大主教1 小时前
C++基于select和epoll的TCP服务器
linux·服务器·c语言·开发语言·c++·tcp/ip·io多路复用
FuLLovers1 小时前
2024-09-13 冯诺依曼体系结构 OS管理 进程
linux·开发语言
everyStudy2 小时前
JS中判断字符串中是否包含指定字符
开发语言·前端·javascript
luthane2 小时前
python 实现average mean平均数算法
开发语言·python·算法
Ylucius3 小时前
动态语言? 静态语言? ------区别何在?java,js,c,c++,python分给是静态or动态语言?
java·c语言·javascript·c++·python·学习
凡人的AI工具箱3 小时前
AI教你学Python 第11天 : 局部变量与全局变量
开发语言·人工智能·后端·python
sleP4o3 小时前
Python操作MySQL
开发语言·python·mysql
是店小二呀3 小时前
【C++】C++ STL探索:Priority Queue与仿函数的深入解析
开发语言·c++·后端