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;
}
相关推荐
SHolmes18544 分钟前
给定某日的上班时间段,计算当日的工作时间总时长(Python)
开发语言·前端·python
咖啡の猫12 分钟前
Python字典元素的增、删、改操作
java·开发语言·python
PyGata20 分钟前
CMake学习笔记(二):CMake拷贝文件夹
c++·笔记·学习
Lucky小小吴20 分钟前
JAVA漫谈反序列化篇——笔记
java·开发语言·笔记
仰泳的熊猫25 分钟前
1150 Travelling Salesman Problem
数据结构·c++·算法·pat考试
ytttr87343 分钟前
基于 C# WinForm 实现的 电影院售票系统
开发语言·c#
智者知已应修善业1 小时前
【蓝桥杯龟兔赛跑】2024-2-12
c语言·c++·经验分享·笔记·算法·职场和发展·蓝桥杯
Tony Bai1 小时前
Goroutine “气泡”宇宙——Go 并发模型的新维度
开发语言·后端·golang
im_AMBER1 小时前
Leetcode 82 每个字符最多出现两次的最长子字符串 | 删掉一个元素以后全为 1 的最长子数组
c++·笔记·学习·算法·leetcode
CHPCWWHSU1 小时前
CesiumforUnreal环境准备
c++·cesium·unreal·osg