C++ 一种简单的软件验证码 程序授权使用 收费付费使用 无需注册 用机器码得到一个加密值 再对比加密值是否一致 只需加密
#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;
}