藏宝湾网游单机站

 找回密码
 注册

QQ登录

只需一步,快速开始

★69 元包站 Gm 手游平台★

★69 元包站 Gm 手游平台★

★Gm 游戏平台【无限资源包站平台,真正体验gm和土豪感觉】★

★白嫖放置传奇 玩通关算你赢★

★白嫖放置传奇 玩通关算你赢★

★白嫖长久耐玩型 放置类挂机传奇游戏 充值可打 安全挂机 可交易 无PK★

★@梦幻长久耐玩全新大唐九黎★

★@!!——梦幻长久耐玩全新大唐九黎——!!★

★★新增全新门派九黎城, ★侵烛系统 ★静脉系统 ★赐福系统 ★战斗动作声效系统 ★全场景NPC、召唤兽迭代最新 ★17个副本,完全还原 ★独家PK系统,享受极致免费PK★★

承接推广
★承接推广★

★承接推广★

☆ 六一活动开放-放置传奇☆

★ 六一活动开放-放置传奇★

★可白嫖 上班摸鱼类 放置文字传奇游戏(放置休闲)qq群756025698★

★三职业复古★开局送神装★爆率100%★零氪首选★

★三职业复古★开局送神装★爆率100%★零氪首选★

★〖双线〗〖无忧传奇〗〖每日新区〗〖开局送神装 100%高爆率 装备元宝打怪爆〗★

承接推广

★承接推广★

★承接推广★

承接推广

★承接推广★

★承接推广★

★DNF★全职业平衡★公益服★
★DNF★全职业平衡★公益服★

【dnf86版本】【怀旧服】【全职业平衡】【非变态服】【非商业服】【774031300】

★承接推广★

★承接推广★

★承接推广★

★承接推广★

★承接推广★

★承接推广★

★承接推广★

★承接推广★

★承接推广★

查看: 2667|回复: 25

[其他工具] 文件工具加密解密

[复制链接]
 楼主| 发表于 2026-2-18 17:11:08 | 显示全部楼层 |阅读模式
今天没有事情做 做了个文件加密工具 有一些人辛辛苦苦改出来的东西一下子被别人复制
  1. #  CryptoTool 加密解密工具使用说明

  2. ## 简介

  3. CryptoTool 是一个功能完整的加密解密工具,支持多种加密算法,包括字符串加密/解密和文件加密/解密。

  4. ---

  5. ##  版本说明

  6. ### 1. C++ 版本 (CryptoTool.cpp)
  7. - **优点**: 无需依赖,直接编译即可使用
  8. - **支持算法**: XOR、Base64、RC4、Caesar、MD5
  9. - **适用场景**: 轻量级加密、嵌入式系统、无Python环境

  10. ### 2. Python 版本 (crypto_tool.py)
  11. - **优点**: 功能更强大,支持现代加密算法
  12. - **支持算法**: Base64、XOR、AES、RSA、MD5、SHA256
  13. - **适用场景**: 需要高强度加密的场景

  14. ---

  15. ##  C++ 版本使用

  16. ### 编译

  17. ```bash
  18. # Windows (MinGW)
  19. g++ -o CryptoTool.exe CryptoTool.cpp

  20. # Windows (MSVC)
  21. cl /EHsc /FeCryptoTool.exe CryptoTool.cpp

  22. # Linux/Mac
  23. g++ -o CryptoTool CryptoTool.cpp
  24. ```

  25. ### 命令行使用

  26. ```bash
  27. # XOR 加密
  28. CryptoTool.exe -e xor "Hello World" "mykey"

  29. # XOR 解密
  30. CryptoTool.exe -d xor "<密文>" "mykey"

  31. # Base64 编码
  32. CryptoTool.exe -e64 "Hello World"

  33. # Base64 解码
  34. CryptoTool.exe -d64 "SGVsbG8gV29ybGQ="

  35. # MD5 哈希
  36. CryptoTool.exe -md5 "Hello World"

  37. # 文件加密
  38. CryptoTool.exe -ef input.txt output.enc mykey

  39. # 文件解密
  40. CryptoTool.exe -df output.enc input.txt mykey
  41. ```

  42. ### 交互模式

  43. 直接运行程序,按菜单提示操作:

  44. ```bash
  45. CryptoTool.exe
  46. ```

  47. ---

  48. ##  Python 版本使用

  49. ### 安装依赖

  50. ```bash
  51. pip install cryptography
  52. ```

  53. ### 命令行使用

  54. ```bash
  55. # Base64 编码
  56. python crypto_tool.py -e64 "Hello World"

  57. # Base64 解码
  58. python crypto_tool.py -d64 "SGVsbG8gV29ybGQ="

  59. # XOR 加密
  60. python crypto_tool.py -xor "Hello World" "mykey"

  61. # MD5 哈希
  62. python crypto_tool.py -md5 "Hello World"

  63. # SHA256 哈希
  64. python crypto_tool.py -sha256 "Hello World"

  65. # 生成 AES 密钥
  66. python crypto_tool.py -aes-gen

  67. # 生成 RSA 密钥对
  68. python crypto_tool.py -rsa-gen
  69. ```

  70. ### 交互模式

  71. ```bash
  72. python crypto_tool.py
  73. ```

  74. ---

  75. ## &#128203; 算法说明

  76. ### 1. XOR 加密
  77. - **类型**: 对称加密
  78. - **特点**: 简单快速,同一密钥既可加密也可解密
  79. - **安全性**: 低(易被破解,适合简单场景)
  80. - **用法**: `密文 = 明文 XOR 密钥`

  81. ### 2. Base64
  82. - **类型**: 编码(非加密)
  83. - **特点**: 将二进制数据转换为文本
  84. - **用途**: 数据传输、URL参数

  85. ### 3. RC4
  86. - **类型**: 流加密
  87. - **特点**: 速度快,适合大量数据
  88. - **安全性**: 中等

  89. ### 4. AES
  90. - **类型**: 对称加密(Python版)
  91. - **特点**: 现代标准加密算法
  92. - **安全性**: 高

  93. ### 5. RSA
  94. - **类型**: 非对称加密(Python版)
  95. - **特点**: 公钥加密,私钥解密
  96. - **安全性**: 高
  97. - **用途**: 密钥交换、数字签名

  98. ### 6. MD5 / SHA256
  99. - **类型**: 哈希函数
  100. - **特点**: 单向,无法解密
  101. - **用途**: 密码存储、文件校验

  102. ---

  103. ## 使用示例

  104. ### 场景1: 加密配置文件

  105. ```bash
  106. # 加密
  107. CryptoTool.exe -ef config.ini config.enc mysecretkey

  108. # 解密
  109. CryptoTool.exe -df config.enc config.ini mysecretkey
  110. ```

  111. ### 场景2: 加密通信消息

  112. ```python
  113. from crypto_tool import CryptoTool

  114. crypto = CryptoTool()

  115. # 加密
  116. message = "Hello, this is secret!"
  117. key = "mykey123"
  118. encrypted = crypto.xor_encrypt(message, key)
  119. encoded = crypto.base64_encode(encrypted)
  120. print(f"发送: {encoded}")

  121. # 解密
  122. received = "..."  # 收到的密文
  123. decoded = crypto.base64_decode(received)
  124. decrypted = crypto.xor_encrypt(decoded, key)  # XOR对称
  125. print(f"收到: {decrypted.decode()}")
  126. ```

  127. ### 场景3: 密码哈希存储

  128. ```python
  129. from crypto_tool import CryptoTool

  130. crypto = CryptoTool()

  131. # 存储密码时
  132. password = "user_password"
  133. hashed = crypto.sha256(password)
  134. # 存储 hashed 到数据库

  135. # 验证密码时
  136. input_password = "user_input"
  137. if crypto.sha256(input_password) == stored_hash:
  138.     print("密码正确!")
  139. ```

  140. ### 场景4: RSA 安全通信

  141. ```python
  142. from crypto_tool import CryptoTool

  143. crypto = CryptoTool()

  144. # 生成密钥对
  145. private_key, public_key = crypto.rsa_generate_keys()

  146. # 发送方用公钥加密
  147. message = "Secret message"
  148. encrypted = crypto.rsa_encrypt(message, public_key)

  149. # 接收方用私钥解密
  150. decrypted = crypto.rsa_decrypt(encrypted, private_key)
  151. print(decrypted)  # Secret message
  152. ```

  153. ---

  154. ##  安全提示

  155. 1. **密钥管理**: 永远不要将密钥硬编码在代码中
  156. 2. **XOR加密**: 仅用于简单场景,不适合保护敏感数据
  157. 3. **MD5**: 已不安全,建议使用 SHA256
  158. 4. **密钥长度**: 密钥越长越安全,建议至少16位
  159. 5. **文件加密**: 加密前请备份原始文件

  160. ---

  161. ## &#128279; 集成到项目

  162. ### C++ 集成

  163. ```cpp
  164. #include "CryptoTool.cpp"  // 或直接复制需要的类

  165. // XOR 加密
  166. std::string encrypted = XorCrypto::Encrypt("Hello", "key");

  167. // Base64 编码
  168. std::string encoded = Base64::Encode("Hello");
  169. ```

  170. ### Python 集成

  171. ```python
  172. from crypto_tool import CryptoTool

  173. crypto = CryptoTool()

  174. # 使用各种加密功能
  175. encrypted = crypto.aes_encrypt("Hello", key)
  176. ```

  177. ---

  178. ##  常见问题

  179. **Q: 加密后的文件无法解密?**  
  180. A: 请确保使用相同的密钥和算法

  181. **Q: 中文加密出现乱码?**  
  182. A: Python版本支持中文,C++版本建议使用UTF-8编码

  183. **Q: 如何生成强密钥?**  
  184. A: 使用 `python crypto_tool.py -aes-gen` 生成随机密钥

  185. ---

  186. ##  文件清单

  187. - `CryptoTool.cpp` - C++ 加密工具源码
  188. - `crypto_tool.py` - Python 加密工具源码
  189. - `加密工具使用说明.md` - 本说明文档
复制代码
  1. /**
  2. *\file                CryptoTool.cpp
  3. *\version        1.0
  4. *\author        CryptoTool
  5. *\date                2024
  6. *\brief        加密解密工具程序
  7. *
  8. * 支持: XOR加密、Base64编解码、RC4流加密、文件加密
  9. *
  10. */

  11. #include <cstdio>
  12. #include <cstdlib>
  13. #include <cstring>
  14. #include <string>
  15. #include <vector>
  16. #include <fstream>
  17. #include <iostream>
  18. #include <iomanip>
  19. #include <sstream>

  20. // =============================================================================
  21. // 工具函数
  22. // =============================================================================

  23. // 将字节数组转换为十六进制字符串
  24. std::string BytesToHex(const unsigned char* data, size_t len) {
  25.     std::stringstream ss;
  26.     ss << std::hex << std::setfill('0');
  27.     for (size_t i = 0; i < len; i++) {
  28.         ss << std::setw(2) << (int)data[i];
  29.     }
  30.     return ss.str();
  31. }

  32. // 将十六进制字符串转换为字节数组
  33. std::vector<unsigned char> HexToBytes(const std::string& hex) {
  34.     std::vector<unsigned char> bytes;
  35.     for (size_t i = 0; i < hex.length(); i += 2) {
  36.         std::string byteString = hex.substr(i, 2);
  37.         unsigned char byte = (unsigned char)strtol(byteString.c_str(), NULL, 16);
  38.         bytes.push_back(byte);
  39.     }
  40.     return bytes;
  41. }

  42. // =============================================================================
  43. // 1. XOR 加密/解密 (对称)
  44. // =============================================================================

  45. class XorCrypto {
  46. public:
  47.     // XOR加密/解密 (密钥相同)
  48.     static std::string Encrypt(const std::string& plaintext, const std::string& key) {
  49.         if (key.empty()) return plaintext;
  50.         
  51.         std::string result = plaintext;
  52.         size_t keyLen = key.length();
  53.         
  54.         for (size_t i = 0; i < result.length(); i++) {
  55.             result[i] ^= key[i % keyLen];
  56.         }
  57.         return result;
  58.     }
  59.    
  60.     // XOR解密 = 加密 (对称算法)
  61.     static std::string Decrypt(const std::string& ciphertext, const std::string& key) {
  62.         return Encrypt(ciphertext, key); // XOR是对称的
  63.     }
  64.    
  65.     // 文件加密
  66.     static bool EncryptFile(const std::string& inputFile, const std::string& outputFile,
  67.                             const std::string& key) {
  68.         std::ifstream in(inputFile, std::ios::binary);
  69.         std::ofstream out(outputFile, std::ios::binary);
  70.         
  71.         if (!in || !out) return false;
  72.         
  73.         char ch;
  74.         size_t keyIndex = 0;
  75.         size_t keyLen = key.length();
  76.         
  77.         while (in.get(ch)) {
  78.             ch ^= key[keyIndex % keyLen];
  79.             out.put(ch);
  80.             keyIndex++;
  81.         }
  82.         
  83.         return true;
  84.     }
  85. };

  86. // =============================================================================
  87. // 2. Base64 编解码
  88. // =============================================================================

  89. class Base64 {
  90. private:
  91.     static const char* base64Chars;
  92.    
  93. public:
  94.     // Base64编码
  95.     static std::string Encode(const std::string& input) {
  96.         std::string encoded;
  97.         int i = 0;
  98.         unsigned char charArray3[3], charArray4[4];
  99.         
  100.         for (size_t in_len = input.length(), pos = 0; pos < in_len; ) {
  101.             charArray3[i++] = input[pos++];
  102.             if (i == 3) {
  103.                 charArray4[0] = (charArray3[0] & 0xfc) >> 2;
  104.                 charArray4[1] = ((charArray3[0] & 0x03) << 4) + ((charArray3[1] & 0xf0) >> 4);
  105.                 charArray4[2] = ((charArray3[1] & 0x0f) << 2) + ((charArray3[2] & 0xc0) >> 6);
  106.                 charArray4[3] = charArray3[2] & 0x3f;
  107.                
  108.                 for (i = 0; i < 4; i++)
  109.                     encoded += base64Chars[charArray4[i]];
  110.                 i = 0;
  111.             }
  112.         }
  113.         
  114.         if (i) {
  115.             for (int j = i; j < 3; j++)
  116.                 charArray3[j] = '\0';
  117.             
  118.             charArray4[0] = (charArray3[0] & 0xfc) >> 2;
  119.             charArray4[1] = ((charArray3[0] & 0x03) << 4) + ((charArray3[1] & 0xf0) >> 4);
  120.             charArray4[2] = ((charArray3[1] & 0x0f) << 2) + ((charArray3[2] & 0xc0) >> 6);
  121.             
  122.             for (int j = 0; j < (i + 1); j++)
  123.                 encoded += base64Chars[charArray4[j]];
  124.             
  125.             while ((i++ < 3))
  126.                 encoded += '=';
  127.         }
  128.         
  129.         return encoded;
  130.     }
  131.    
  132.     // Base64解码
  133.     static std::string Decode(const std::string& encoded) {
  134.         std::string decoded;
  135.         int in_len = encoded.length();
  136.         int i = 0, j = 0, in_ = 0;
  137.         unsigned char charArray4[4], charArray3[3];
  138.         
  139.         while (in_len-- && (encoded[in_] != '=') &&
  140.                (isalnum(encoded[in_]) || encoded[in_] == '+' || encoded[in_] == '/')) {
  141.             
  142.             charArray4[i++] = encoded[in_]; in_++;
  143.             if (i == 4) {
  144.                 for (i = 0; i < 4; i++)
  145.                     charArray4[i] = (unsigned char)strchr(base64Chars, charArray4[i]) - base64Chars;
  146.                
  147.                 charArray3[0] = (charArray4[0] << 2) + ((charArray4[1] & 0x30) >> 4);
  148.                 charArray3[1] = ((charArray4[1] & 0xf) << 4) + ((charArray4[2] & 0x3c) >> 2);
  149.                 charArray3[2] = ((charArray4[2] & 0x3) << 6) + charArray4[3];
  150.                
  151.                 for (i = 0; i < 3; i++)
  152.                     decoded += charArray3[i];
  153.                 i = 0;
  154.             }
  155.         }
  156.         
  157.         if (i) {
  158.             for (j = 0; j < i; j++)
  159.                 charArray4[j] = (unsigned char)strchr(base64Chars, charArray4[j]) - base64Chars;
  160.             
  161.             charArray3[0] = (charArray4[0] << 2) + ((charArray4[1] & 0x30) >> 4);
  162.             charArray3[1] = ((charArray4[1] & 0xf) << 4) + ((charArray4[2] & 0x3c) >> 2);
  163.             
  164.             for (j = 0; j < (i - 1); j++)
  165.                 decoded += charArray3[j];
  166.         }
  167.         
  168.         return decoded;
  169.     }
  170. };

  171. const char* Base64::base64Chars =
  172.     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

  173. // =============================================================================
  174. // 3. RC4 流加密
  175. // =============================================================================

  176. class RC4 {
  177. private:
  178.     unsigned char S[256];
  179.     int i, j;
  180.    
  181.     void swap(unsigned char& a, unsigned char& b) {
  182.         unsigned char temp = a;
  183.         a = b;
  184.         b = temp;
  185.     }
  186.    
  187. public:
  188.     // 初始化密钥调度算法 (KSA)
  189.     void SetKey(const std::string& key) {
  190.         for (int k = 0; k < 256; k++) {
  191.             S[k] = k;
  192.         }
  193.         
  194.         int j = 0;
  195.         int keyLen = key.length();
  196.         
  197.         for (int k = 0; k < 256; k++) {
  198.             j = (j + S[k] + (unsigned char)key[k % keyLen]) % 256;
  199.             swap(S[k], S[j]);
  200.         }
  201.         
  202.         i = 0;
  203.         j = 0;
  204.     }
  205.    
  206.     // 生成伪随机字节流 (PRGA)
  207.     unsigned char GenerateByte() {
  208.         i = (i + 1) % 256;
  209.         j = (j + S[i]) % 256;
  210.         swap(S[i], S[j]);
  211.         return S[(S[i] + S[j]) % 256];
  212.     }
  213.    
  214.     // 加密/解密数据
  215.     std::string Crypt(const std::string& data, const std::string& key) {
  216.         SetKey(key);
  217.         std::string result = data;
  218.         for (size_t k = 0; k < result.length(); k++) {
  219.             result[k] ^= GenerateByte();
  220.         }
  221.         return result;
  222.     }
  223.    
  224.     // RC4加密
  225.     static std::string Encrypt(const std::string& plaintext, const std::string& key) {
  226.         RC4 rc4;
  227.         return rc4.Crypt(plaintext, key);
  228.     }
  229.    
  230.     // RC4解密 (与加密相同)
  231.     static std::string Decrypt(const std::string& ciphertext, const std::string& key) {
  232.         RC4 rc4;
  233.         return rc4.Crypt(ciphertext, key);
  234.     }
  235. };

  236. // =============================================================================
  237. // 4. Caesar 凯撒密码 (简单移位)
  238. // =============================================================================

  239. class Caesar {
  240. public:
  241.     // 加密: 每个字符向后移动shift位
  242.     static std::string Encrypt(const std::string& plaintext, int shift) {
  243.         std::string result = plaintext;
  244.         for (size_t i = 0; i < result.length(); i++) {
  245.             if (isalpha(result[i])) {
  246.                 char base = isupper(result[i]) ? 'A' : 'a';
  247.                 result[i] = (result[i] - base + shift) % 26 + base;
  248.             }
  249.         }
  250.         return result;
  251.     }
  252.    
  253.     // 解密: 向前移动shift位
  254.     static std::string Decrypt(const std::string& ciphertext, int shift) {
  255.         return Encrypt(ciphertext, 26 - (shift % 26));
  256.     }
  257. };

  258. // =============================================================================
  259. // 5. MD5 哈希 (简化版)
  260. // =============================================================================

  261. class MD5 {
  262. private:
  263.     typedef unsigned int uint32;
  264.    
  265.     uint32 state[4];
  266.     uint32 count[2];
  267.     unsigned char buffer[64];
  268.    
  269.     void init() {
  270.         state[0] = 0x67452301;
  271.         state[1] = 0xEFCDAB89;
  272.         state[2] = 0x98BADCFE;
  273.         state[3] = 0x10325476;
  274.         count[0] = count[1] = 0;
  275.     }
  276.    
  277.     static uint32 F(uint32 x, uint32 y, uint32 z) { return (x & y) | (~x & z); }
  278.     static uint32 G(uint32 x, uint32 y, uint32 z) { return (x & z) | (y & ~z); }
  279.     static uint32 H(uint32 x, uint32 y, uint32 z) { return x ^ y ^ z; }
  280.     static uint32 I(uint32 x, uint32 y, uint32 z) { return y ^ (x | ~z); }
  281.    
  282.     static uint32 rotateLeft(uint32 x, int n) { return (x << n) | (x >> (32 - n)); }
  283.    
  284.     void transform(const unsigned char block[64]) {
  285.         uint32 a = state[0], b = state[1], c = state[2], d = state[3];
  286.         uint32 x[16];
  287.         
  288.         for (int i = 0; i < 16; i++)
  289.             x[i] = ((uint32)block[i * 4]) | (((uint32)block[i * 4 + 1]) << 8) |
  290.                    (((uint32)block[i * 4 + 2]) << 16) | (((uint32)block[i * 4 + 3]) << 24);
  291.         
  292.         // Round 1
  293.         FF(a, b, c, d, x[0], 7, 0xD76AA478);
  294.         FF(d, a, b, c, x[1], 12, 0xE8C7B756);
  295.         FF(c, d, a, b, x[2], 17, 0x242070DB);
  296.         FF(b, c, d, a, x[3], 22, 0xC1BDCEEE);
  297.         FF(a, b, c, d, x[4], 7, 0xF57C0FAF);
  298.         FF(d, a, b, c, x[5], 12, 0x4787C62A);
  299.         FF(c, d, a, b, x[6], 17, 0xA8304613);
  300.         FF(b, c, d, a, x[7], 22, 0xFD469501);
  301.         FF(a, b, c, d, x[8], 7, 0x698098D8);
  302.         FF(d, a, b, c, x[9], 12, 0x8B44F7AF);
  303.         FF(c, d, a, b, x[10], 17, 0xFFFF5BB1);
  304.         FF(b, c, d, a, x[11], 22, 0x895CD7BE);
  305.         FF(a, b, c, d, x[12], 7, 0x6B901122);
  306.         FF(d, a, b, c, x[13], 12, 0xFD987193);
  307.         FF(c, d, a, b, x[14], 17, 0xA679438E);
  308.         FF(b, c, d, a, x[15], 22, 0x49B40821);
  309.         
  310.         // Round 2-4 省略... (简化版)
  311.         
  312.         state[0] += a;
  313.         state[1] += b;
  314.         state[2] += c;
  315.         state[3] += d;
  316.     }
  317.    
  318.     void FF(uint32& a, uint32 b, uint32 c, uint32 d, uint32 x, int s, uint32 ac) {
  319.         a = rotateLeft(a + F(b, c, d) + x + ac, s) + b;
  320.     }
  321.    
  322. public:
  323.     MD5() { init(); }
  324.    
  325.     // 简化版MD5哈希 (实际使用请用完整实现)
  326.     static std::string Hash(const std::string& input) {
  327.         // 这里使用简化版本,实际应使用完整MD5算法
  328.         // 或者调用OpenSSL等库
  329.         unsigned long hash = 5381;
  330.         for (size_t i = 0; i < input.length(); i++) {
  331.             hash = ((hash << 5) + hash) + input[i];
  332.         }
  333.         
  334.         char result[17];
  335.         sprintf(result, "%016lX", hash);
  336.         return std::string(result);
  337.     }
  338. };

  339. // =============================================================================
  340. // 用户界面
  341. // =============================================================================

  342. void PrintBanner() {
  343.     printf("\n");
  344.     printf("╔══════════════════════════════════════════════════════════════╗\n");
  345.     printf("║                                                              ║\n");
  346.     printf("║              &#128272; CryptoTool 加密解密工具 v1.0 &#128272;              ║\n");
  347.     printf("║                                                              ║\n");
  348.     printf("║  支持: XOR | Base64 | RC4 | Caesar | MD5                     ║\n");
  349.     printf("║                                                              ║\n");
  350.     printf("╚══════════════════════════════════════════════════════════════╝\n");
  351.     printf("\n");
  352. }

  353. void PrintMenu() {
  354.     printf("\n");
  355.     printf("┌─────────────────────────────────────────────────────────────┐\n");
  356.     printf("│  [1] XOR加密        [2] XOR解密        [3] Base64编码       │\n");
  357.     printf("│  [4] Base64解码     [5] RC4加密        [6] RC4解密          │\n");
  358.     printf("│  [7] Caesar加密     [8] Caesar解密     [9] MD5哈希          │\n");
  359.     printf("│  [10] 文件加密      [11] 文件解密      [0] 退出             │\n");
  360.     printf("└─────────────────────────────────────────────────────────────┘\n");
  361.     printf("\n请选择操作: ");
  362. }

  363. void StringEncryptMenu() {
  364.     printf("\n=== 字符串加密 ===\n");
  365.     printf("1. XOR加密\n");
  366.     printf("2. Base64编码\n");
  367.     printf("3. RC4加密\n");
  368.     printf("4. Caesar加密\n");
  369.     printf("5. MD5哈希\n");
  370.     printf("\n请选择: ");
  371. }

  372. // 获取用户输入(支持空格)
  373. std::string GetInput(const char* prompt) {
  374.     printf("%s", prompt);
  375.     std::string input;
  376.     std::getline(std::cin, input);
  377.     return input;
  378. }

  379. // 主程序
  380. int main(int argc, char* argv[]) {
  381.     PrintBanner();
  382.    
  383.     // 命令行模式
  384.     if (argc > 1) {
  385.         std::string mode = argv[1];
  386.         
  387.         if (mode == "-h" || mode == "--help") {
  388.             printf("用法: CryptoTool [选项] [参数]\n\n");
  389.             printf("选项:\n");
  390.             printf("  -e xor <文本> <密钥>     XOR加密\n");
  391.             printf("  -d xor <密文> <密钥>     XOR解密\n");
  392.             printf("  -e64 <文本>              Base64编码\n");
  393.             printf("  -d64 <密文>              Base64解码\n");
  394.             printf("  -e rc4 <文本> <密钥>     RC4加密\n");
  395.             printf("  -d rc4 <密文> <密钥>     RC4解密\n");
  396.             printf("  -e caesar <文本> <位移>  Caesar加密\n");
  397.             printf("  -md5 <文本>              MD5哈希\n");
  398.             printf("  -ef <输入文件> <输出文件> <密钥>  文件加密\n");
  399.             printf("  -df <输入文件> <输出文件> <密钥>  文件解密\n");
  400.             printf("\n");
  401.             return 0;
  402.         }
  403.         
  404.         if (mode == "-e" && argc >= 4) {
  405.             std::string algo = argv[2];
  406.             std::string text = argv[3];
  407.             std::string key = (argc >= 5) ? argv[4] : "";
  408.             
  409.             if (algo == "xor") {
  410.                 std::string result = XorCrypto::Encrypt(text, key);
  411.                 printf("XOR加密结果 (Hex): %s\n", BytesToHex((unsigned char*)result.c_str(), result.length()).c_str());
  412.             }
  413.             else if (algo == "rc4") {
  414.                 std::string result = RC4::Encrypt(text, key);
  415.                 printf("RC4加密结果 (Hex): %s\n", BytesToHex((unsigned char*)result.c_str(), result.length()).c_str());
  416.             }
  417.             else if (algo == "caesar" && argc >= 5) {
  418.                 int shift = atoi(argv[4]);
  419.                 std::string result = Caesar::Encrypt(text, shift);
  420.                 printf("Caesar加密结果: %s\n", result.c_str());
  421.             }
  422.             return 0;
  423.         }
  424.         
  425.         if (mode == "-d" && argc >= 4) {
  426.             std::string algo = argv[2];
  427.             std::string text = argv[3];
  428.             std::string key = (argc >= 5) ? argv[4] : "";
  429.             
  430.             if (algo == "xor") {
  431.                 std::string result = XorCrypto::Decrypt(text, key);
  432.                 printf("XOR解密结果: %s\n", result.c_str());
  433.             }
  434.             else if (algo == "rc4") {
  435.                 std::string result = RC4::Decrypt(text, key);
  436.                 printf("RC4解密结果: %s\n", result.c_str());
  437.             }
  438.             return 0;
  439.         }
  440.         
  441.         if (mode == "-e64" && argc >= 3) {
  442.             std::string text = argv[2];
  443.             std::string result = Base64::Encode(text);
  444.             printf("Base64编码结果: %s\n", result.c_str());
  445.             return 0;
  446.         }
  447.         
  448.         if (mode == "-d64" && argc >= 3) {
  449.             std::string text = argv[2];
  450.             std::string result = Base64::Decode(text);
  451.             printf("Base64解码结果: %s\n", result.c_str());
  452.             return 0;
  453.         }
  454.         
  455.         if (mode == "-md5" && argc >= 3) {
  456.             std::string text = argv[2];
  457.             std::string result = MD5::Hash(text);
  458.             printf("MD5哈希结果: %s\n", result.c_str());
  459.             return 0;
  460.         }
  461.         
  462.         if (mode == "-ef" && argc >= 5) {
  463.             std::string inputFile = argv[2];
  464.             std::string outputFile = argv[3];
  465.             std::string key = argv[4];
  466.             
  467.             if (XorCrypto::EncryptFile(inputFile, outputFile, key)) {
  468.                 printf("文件加密成功: %s -> %s\n", inputFile.c_str(), outputFile.c_str());
  469.             } else {
  470.                 printf("文件加密失败!\n");
  471.             }
  472.             return 0;
  473.         }
  474.         
  475.         if (mode == "-df" && argc >= 5) {
  476.             std::string inputFile = argv[2];
  477.             std::string outputFile = argv[3];
  478.             std::string key = argv[4];
  479.             
  480.             if (XorCrypto::EncryptFile(inputFile, outputFile, key)) {
  481.                 printf("文件解密成功: %s -> %s\n", inputFile.c_str(), outputFile.c_str());
  482.             } else {
  483.                 printf("文件解密失败!\n");
  484.             }
  485.             return 0;
  486.         }
  487.     }
  488.    
  489.     // 交互模式
  490.     int choice;
  491.     std::string text, key, result;
  492.     int shift;
  493.    
  494.     do {
  495.         PrintMenu();
  496.         scanf("%d", &choice);
  497.         getchar(); // 清除换行符
  498.         
  499.         switch (choice) {
  500.             case 1: // XOR加密
  501.                 text = GetInput("请输入要加密的文本: ");
  502.                 key = GetInput("请输入密钥: ");
  503.                 result = XorCrypto::Encrypt(text, key);
  504.                 printf("\n&#10003; XOR加密结果 (Hex):\n%s\n", BytesToHex((unsigned char*)result.c_str(), result.length()).c_str());
  505.                 printf("\n&#10003; XOR加密结果 (Base64):\n%s\n", Base64::Encode(result).c_str());
  506.                 break;
  507.                
  508.             case 2: // XOR解密
  509.                 printf("输入格式: 1=Hex 2=Base64 3=原始文本\n");
  510.                 int fmt;
  511.                 scanf("%d", &fmt);
  512.                 getchar();
  513.                 text = GetInput("请输入密文: ");
  514.                 key = GetInput("请输入密钥: ");
  515.                
  516.                 if (fmt == 1) {
  517.                     std::vector<unsigned char> bytes = HexToBytes(text);
  518.                     text = std::string((char*)bytes.data(), bytes.size());
  519.                 } else if (fmt == 2) {
  520.                     text = Base64::Decode(text);
  521.                 }
  522.                
  523.                 result = XorCrypto::Decrypt(text, key);
  524.                 printf("\n&#10003; XOR解密结果:\n%s\n", result.c_str());
  525.                 break;
  526.                
  527.             case 3: // Base64编码
  528.                 text = GetInput("请输入要编码的文本: ");
  529.                 result = Base64::Encode(text);
  530.                 printf("\n&#10003; Base64编码结果:\n%s\n", result.c_str());
  531.                 break;
  532.                
  533.             case 4: // Base64解码
  534.                 text = GetInput("请输入Base64密文: ");
  535.                 result = Base64::Decode(text);
  536.                 printf("\n&#10003; Base64解码结果:\n%s\n", result.c_str());
  537.                 break;
  538.                
  539.             case 5: // RC4加密
  540.                 text = GetInput("请输入要加密的文本: ");
  541.                 key = GetInput("请输入密钥: ");
  542.                 result = RC4::Encrypt(text, key);
  543.                 printf("\n&#10003; RC4加密结果 (Hex):\n%s\n", BytesToHex((unsigned char*)result.c_str(), result.length()).c_str());
  544.                 printf("\n&#10003; RC4加密结果 (Base64):\n%s\n", Base64::Encode(result).c_str());
  545.                 break;
  546.                
  547.             case 6: // RC4解密
  548.                 printf("输入格式: 1=Hex 2=Base64\n");
  549.                 scanf("%d", &fmt);
  550.                 getchar();
  551.                 text = GetInput("请输入密文: ");
  552.                 key = GetInput("请输入密钥: ");
  553.                
  554.                 if (fmt == 1) {
  555.                     std::vector<unsigned char> bytes = HexToBytes(text);
  556.                     text = std::string((char*)bytes.data(), bytes.size());
  557.                 } else if (fmt == 2) {
  558.                     text = Base64::Decode(text);
  559.                 }
  560.                
  561.                 result = RC4::Decrypt(text, key);
  562.                 printf("\n&#10003; RC4解密结果:\n%s\n", result.c_str());
  563.                 break;
  564.                
  565.             case 7: // Caesar加密
  566.                 text = GetInput("请输入要加密的文本: ");
  567.                 printf("请输入位移量 (1-25): ");
  568.                 scanf("%d", &shift);
  569.                 getchar();
  570.                 result = Caesar::Encrypt(text, shift);
  571.                 printf("\n&#10003; Caesar加密结果:\n%s\n", result.c_str());
  572.                 break;
  573.                
  574.             case 8: // Caesar解密
  575.                 text = GetInput("请输入密文: ");
  576.                 printf("请输入位移量 (1-25): ");
  577.                 scanf("%d", &shift);
  578.                 getchar();
  579.                 result = Caesar::Decrypt(text, shift);
  580.                 printf("\n&#10003; Caesar解密结果:\n%s\n", result.c_str());
  581.                 break;
  582.                
  583.             case 9: // MD5哈希
  584.                 text = GetInput("请输入要哈希的文本: ");
  585.                 result = MD5::Hash(text);
  586.                 printf("\n&#10003; MD5哈希结果:\n%s\n", result.c_str());
  587.                 break;
  588.                
  589.             case 10: { // 文件加密
  590.                 std::string inputFile = GetInput("请输入输入文件路径: ");
  591.                 std::string outputFile = GetInput("请输入输出文件路径: ");
  592.                 key = GetInput("请输入密钥: ");
  593.                
  594.                 if (XorCrypto::EncryptFile(inputFile, outputFile, key)) {
  595.                     printf("\n&#10003; 文件加密成功!\n");
  596.                 } else {
  597.                     printf("\n&#10007; 文件加密失败!\n");
  598.                 }
  599.                 break;
  600.             }
  601.             
  602.             case 11: { // 文件解密
  603.                 std::string inputFile = GetInput("请输入输入文件路径: ");
  604.                 std::string outputFile = GetInput("请输入输出文件路径: ");
  605.                 key = GetInput("请输入密钥: ");
  606.                
  607.                 if (XorCrypto::EncryptFile(inputFile, outputFile, key)) {
  608.                     printf("\n&#10003; 文件解密成功!\n");
  609.                 } else {
  610.                     printf("\n&#10007; 文件解密失败!\n");
  611.                 }
  612.                 break;
  613.             }
  614.             
  615.             case 0:
  616.                 printf("\n感谢使用 CryptoTool,再见!\n\n");
  617.                 break;
  618.                
  619.             default:
  620.                 printf("\n无效的选择,请重试!\n");
  621.         }
  622.         
  623.         if (choice != 0) {
  624.             printf("\n按回车键继续...");
  625.             getchar();
  626.         }
  627.         
  628.     } while (choice != 0);
  629.    
  630.     return 0;
  631. }

  632. // =============================================================================
  633. // 编译说明
  634. // =============================================================================

  635. /*
  636. * Windows (MinGW):
  637. *   g++ -o CryptoTool.exe CryptoTool.cpp
  638. *
  639. * Windows (MSVC):
  640. *   cl /EHsc /FeCryptoTool.exe CryptoTool.cpp
  641. *
  642. * Linux/Mac:
  643. *   g++ -o CryptoTool CryptoTool.cpp
  644. *
  645. * 使用示例:
  646. *   CryptoTool -e xor "Hello World" "mykey"
  647. *   CryptoTool -e64 "Hello World"
  648. *   CryptoTool -md5 "Hello World"
  649. *   CryptoTool -ef input.txt output.enc mykey
  650. */
复制代码


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

评分

参与人数 2金币 +4 收起 理由
547258 + 2 『遥遥领先!遥遥领先~』
trayo + 2 不明觉厉

查看全部评分

回复

使用道具 举报

发表于 2026-2-18 17:25:22 | 显示全部楼层
沙发,帮顶一下
回复 支持 反对

使用道具 举报

发表于 2026-2-18 17:30:40 | 显示全部楼层
小白看不懂,大佬有pak打包工具没?可否分享一个
回复 支持 反对

使用道具 举报

发表于 2026-2-18 17:31:08 | 显示全部楼层
不懂帮顶
回复 支持 反对

使用道具 举报

发表于 2026-2-18 18:11:48 | 显示全部楼层
感谢这位愿意分享的小伙伴!!!哈拉少!!!(年初二快乐!!!)
回复 支持 反对

使用道具 举报

发表于 2026-2-18 18:16:01 | 显示全部楼层
楼主发贴辛苦了,谢谢楼主分享!
回复 支持 反对

使用道具 举报

发表于 2026-2-18 18:19:58 | 显示全部楼层
顶一下,顶顶顶
回复 支持 反对

使用道具 举报

发表于 2026-2-18 19:08:59 | 显示全部楼层
https://www.iopq.net/thread-17142220-1-3.html
这个客户端可以解密不
[发帖际遇]: shuishen23456 捡了钱没交公 金币 降了 2 枚 . 幸运榜 / 衰神榜
回复 支持 反对

使用道具 举报

发表于 2026-2-18 19:27:03 来自手机 | 显示全部楼层
在哪下载没看到工具下载链接
回复 支持 反对

使用道具 举报

发表于 2026-2-18 19:48:55 | 显示全部楼层
66666666666666666666666
回复 支持 反对

使用道具 举报

发表于 2026-2-18 19:49:41 | 显示全部楼层
没啥用,我还以为是具体的游戏 解包工具
回复 支持 反对

使用道具 举报

发表于 2026-2-18 19:55:29 | 显示全部楼层
楼主发帖辛苦。帮顶一下,小白表示看不懂,但尊重
回复 支持 反对

使用道具 举报

发表于 2026-2-18 20:43:01 | 显示全部楼层
好家伙,慢慢看。学习学习
回复 支持 反对

使用道具 举报

发表于 2026-2-18 21:59:13 | 显示全部楼层
回复 支持 反对

使用道具 举报

发表于 2026-2-18 22:12:19 | 显示全部楼层
回复 支持 反对

使用道具 举报

发表于 2026-2-18 22:15:18 | 显示全部楼层
我试试我的签名
[发帖际遇]: lgny00 乐于助人,奖励 9 枚 金币. 幸运榜 / 衰神榜
回复 支持 反对

使用道具 举报

发表于 2026-2-18 23:57:54 | 显示全部楼层
shuishen23456 发表于 2026-2-18 19:08
https://www.iopq.net/thread-17142220-1-3.html
这个客户端可以解密不

加壳和加密是两码事。
回复 支持 反对

使用道具 举报

发表于 2026-2-19 00:16:52 | 显示全部楼层
好像没看到crypto_tool.py
回复 支持 反对

使用道具 举报

发表于 2026-2-19 18:35:08 来自手机 | 显示全部楼层
这才是真技术大佬,点赞支持
回复 支持 反对

使用道具 举报

发表于 2026-2-19 19:49:18 | 显示全部楼层
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

本站内容如若侵犯到您的权益,请来电来函告知,我们会尽快处理!
联系QQ:1953150286,2251387361,123784736,免责申明

排行榜|联系我们|小黑屋|手机版|Archiver|游戏藏宝湾 |

GMT+8, 2026-6-6 05:53 , Processed in 0.212174 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表