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;
}
相关推荐
小糖学代码2 小时前
LLM系列:1.python入门:15.JSON 数据处理与操作
开发语言·python·json·aigc
handler012 小时前
从源码到二进制:深度拆解 Linux 下 C 程序的编译与链接全流程
linux·c语言·开发语言·c++·笔记·学习
小白学大数据3 小时前
现代Python爬虫开发范式:基于Asyncio的高可用架构实战
开发语言·爬虫·python·架构
渔舟小调3 小时前
P19 | 前端加密通信层 pikachuNetwork.js 完整实现
开发语言·前端·javascript
不爱吃炸鸡柳3 小时前
数据结构精讲:树 → 二叉树 → 堆 从入门到实战
开发语言·数据结构
网络安全许木3 小时前
自学渗透测试第21天(基础命令复盘与DVWA熟悉)
开发语言·网络安全·渗透测试·php
t***5443 小时前
如何在Dev-C++中使用Clang编译器
开发语言·c++
码界筑梦坊3 小时前
93-基于Python的中药药材数据可视化分析系统
开发语言·python·信息可视化
Qbw20043 小时前
【Linux】进程地址空间
linux·c++
Cosmoshhhyyy4 小时前
《Effective Java》解读第49条:检查参数的有效性
java·开发语言