bfdz49 发表于 2026-2-18 17:11:08

文件工具加密解密

今天没有事情做 做了个文件加密工具 有一些人辛辛苦苦改出来的东西一下子被别人复制
#CryptoTool 加密解密工具使用说明

## 简介

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

---

##版本说明

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

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

---

##C++ 版本使用

### 编译

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

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

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

### 命令行使用

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

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

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

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

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

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

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

### 交互模式

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

```bash
CryptoTool.exe
```

---

##Python 版本使用

### 安装依赖

```bash
pip install cryptography
```

### 命令行使用

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

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

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

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

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

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

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

### 交互模式

```bash
python crypto_tool.py
```

---

## &#128203; 算法说明

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

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

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

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

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

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

---

## 使用示例

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

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

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

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

```python
from crypto_tool import CryptoTool

crypto = CryptoTool()

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

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

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

```python
from crypto_tool import CryptoTool

crypto = CryptoTool()

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

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

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

```python
from crypto_tool import CryptoTool

crypto = CryptoTool()

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

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

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

---

##安全提示

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

---

## &#128279; 集成到项目

### C++ 集成

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

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

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

### Python 集成

```python
from crypto_tool import CryptoTool

crypto = CryptoTool()

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

---

##常见问题

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

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

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

---

##文件清单

- `CryptoTool.cpp` - C++ 加密工具源码
- `crypto_tool.py` - Python 加密工具源码
- `加密工具使用说明.md` - 本说明文档
/**
*\file                CryptoTool.cpp
*\version        1.0
*\author        CryptoTool
*\date                2024
*\brief        加密解密工具程序
*
* 支持: XOR加密、Base64编解码、RC4流加密、文件加密
*
*/

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <sstream>

// =============================================================================
// 工具函数
// =============================================================================

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

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

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

class XorCrypto {
public:
    // XOR加密/解密 (密钥相同)
    static std::string Encrypt(const std::string& plaintext, const std::string& key) {
      if (key.empty()) return plaintext;
      
      std::string result = plaintext;
      size_t keyLen = key.length();
      
      for (size_t i = 0; i < result.length(); i++) {
            result ^= key;
      }
      return result;
    }
   
    // XOR解密 = 加密 (对称算法)
    static std::string Decrypt(const std::string& ciphertext, const std::string& key) {
      return Encrypt(ciphertext, key); // XOR是对称的
    }
   
    // 文件加密
    static bool EncryptFile(const std::string& inputFile, const std::string& outputFile,
                            const std::string& key) {
      std::ifstream in(inputFile, std::ios::binary);
      std::ofstream out(outputFile, std::ios::binary);
      
      if (!in || !out) return false;
      
      char ch;
      size_t keyIndex = 0;
      size_t keyLen = key.length();
      
      while (in.get(ch)) {
            ch ^= key;
            out.put(ch);
            keyIndex++;
      }
      
      return true;
    }
};

// =============================================================================
// 2. Base64 编解码
// =============================================================================

class Base64 {
private:
    static const char* base64Chars;
   
public:
    // Base64编码
    static std::string Encode(const std::string& input) {
      std::string encoded;
      int i = 0;
      unsigned char charArray3, charArray4;
      
      for (size_t in_len = input.length(), pos = 0; pos < in_len; ) {
            charArray3 = input;
            if (i == 3) {
                charArray4 = (charArray3 & 0xfc) >> 2;
                charArray4 = ((charArray3 & 0x03) << 4) + ((charArray3 & 0xf0) >> 4);
                charArray4 = ((charArray3 & 0x0f) << 2) + ((charArray3 & 0xc0) >> 6);
                charArray4 = charArray3 & 0x3f;
               
                for (i = 0; i < 4; i++)
                  encoded += base64Chars];
                i = 0;
            }
      }
      
      if (i) {
            for (int j = i; j < 3; j++)
                charArray3 = '\0';
            
            charArray4 = (charArray3 & 0xfc) >> 2;
            charArray4 = ((charArray3 & 0x03) << 4) + ((charArray3 & 0xf0) >> 4);
            charArray4 = ((charArray3 & 0x0f) << 2) + ((charArray3 & 0xc0) >> 6);
            
            for (int j = 0; j < (i + 1); j++)
                encoded += base64Chars];
            
            while ((i++ < 3))
                encoded += '=';
      }
      
      return encoded;
    }
   
    // Base64解码
    static std::string Decode(const std::string& encoded) {
      std::string decoded;
      int in_len = encoded.length();
      int i = 0, j = 0, in_ = 0;
      unsigned char charArray4, charArray3;
      
      while (in_len-- && (encoded != '=') &&
               (isalnum(encoded) || encoded == '+' || encoded == '/')) {
            
            charArray4 = encoded; in_++;
            if (i == 4) {
                for (i = 0; i < 4; i++)
                  charArray4 = (unsigned char)strchr(base64Chars, charArray4) - base64Chars;
               
                charArray3 = (charArray4 << 2) + ((charArray4 & 0x30) >> 4);
                charArray3 = ((charArray4 & 0xf) << 4) + ((charArray4 & 0x3c) >> 2);
                charArray3 = ((charArray4 & 0x3) << 6) + charArray4;
               
                for (i = 0; i < 3; i++)
                  decoded += charArray3;
                i = 0;
            }
      }
      
      if (i) {
            for (j = 0; j < i; j++)
                charArray4 = (unsigned char)strchr(base64Chars, charArray4) - base64Chars;
            
            charArray3 = (charArray4 << 2) + ((charArray4 & 0x30) >> 4);
            charArray3 = ((charArray4 & 0xf) << 4) + ((charArray4 & 0x3c) >> 2);
            
            for (j = 0; j < (i - 1); j++)
                decoded += charArray3;
      }
      
      return decoded;
    }
};

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

// =============================================================================
// 3. RC4 流加密
// =============================================================================

class RC4 {
private:
    unsigned char S;
    int i, j;
   
    void swap(unsigned char& a, unsigned char& b) {
      unsigned char temp = a;
      a = b;
      b = temp;
    }
   
public:
    // 初始化密钥调度算法 (KSA)
    void SetKey(const std::string& key) {
      for (int k = 0; k < 256; k++) {
            S = k;
      }
      
      int j = 0;
      int keyLen = key.length();
      
      for (int k = 0; k < 256; k++) {
            j = (j + S + (unsigned char)key) % 256;
            swap(S, S);
      }
      
      i = 0;
      j = 0;
    }
   
    // 生成伪随机字节流 (PRGA)
    unsigned char GenerateByte() {
      i = (i + 1) % 256;
      j = (j + S) % 256;
      swap(S, S);
      return S[(S + S) % 256];
    }
   
    // 加密/解密数据
    std::string Crypt(const std::string& data, const std::string& key) {
      SetKey(key);
      std::string result = data;
      for (size_t k = 0; k < result.length(); k++) {
            result ^= GenerateByte();
      }
      return result;
    }
   
    // RC4加密
    static std::string Encrypt(const std::string& plaintext, const std::string& key) {
      RC4 rc4;
      return rc4.Crypt(plaintext, key);
    }
   
    // RC4解密 (与加密相同)
    static std::string Decrypt(const std::string& ciphertext, const std::string& key) {
      RC4 rc4;
      return rc4.Crypt(ciphertext, key);
    }
};

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

class Caesar {
public:
    // 加密: 每个字符向后移动shift位
    static std::string Encrypt(const std::string& plaintext, int shift) {
      std::string result = plaintext;
      for (size_t i = 0; i < result.length(); i++) {
            if (isalpha(result)) {
                char base = isupper(result) ? 'A' : 'a';
                result = (result - base + shift) % 26 + base;
            }
      }
      return result;
    }
   
    // 解密: 向前移动shift位
    static std::string Decrypt(const std::string& ciphertext, int shift) {
      return Encrypt(ciphertext, 26 - (shift % 26));
    }
};

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

class MD5 {
private:
    typedef unsigned int uint32;
   
    uint32 state;
    uint32 count;
    unsigned char buffer;
   
    void init() {
      state = 0x67452301;
      state = 0xEFCDAB89;
      state = 0x98BADCFE;
      state = 0x10325476;
      count = count = 0;
    }
   
    static uint32 F(uint32 x, uint32 y, uint32 z) { return (x & y) | (~x & z); }
    static uint32 G(uint32 x, uint32 y, uint32 z) { return (x & z) | (y & ~z); }
    static uint32 H(uint32 x, uint32 y, uint32 z) { return x ^ y ^ z; }
    static uint32 I(uint32 x, uint32 y, uint32 z) { return y ^ (x | ~z); }
   
    static uint32 rotateLeft(uint32 x, int n) { return (x << n) | (x >> (32 - n)); }
   
    void transform(const unsigned char block) {
      uint32 a = state, b = state, c = state, d = state;
      uint32 x;
      
      for (int i = 0; i < 16; i++)
            x = ((uint32)block) | (((uint32)block) << 8) |
                   (((uint32)block) << 16) | (((uint32)block) << 24);
      
      // Round 1
      FF(a, b, c, d, x, 7, 0xD76AA478);
      FF(d, a, b, c, x, 12, 0xE8C7B756);
      FF(c, d, a, b, x, 17, 0x242070DB);
      FF(b, c, d, a, x, 22, 0xC1BDCEEE);
      FF(a, b, c, d, x, 7, 0xF57C0FAF);
      FF(d, a, b, c, x, 12, 0x4787C62A);
      FF(c, d, a, b, x, 17, 0xA8304613);
      FF(b, c, d, a, x, 22, 0xFD469501);
      FF(a, b, c, d, x, 7, 0x698098D8);
      FF(d, a, b, c, x, 12, 0x8B44F7AF);
      FF(c, d, a, b, x, 17, 0xFFFF5BB1);
      FF(b, c, d, a, x, 22, 0x895CD7BE);
      FF(a, b, c, d, x, 7, 0x6B901122);
      FF(d, a, b, c, x, 12, 0xFD987193);
      FF(c, d, a, b, x, 17, 0xA679438E);
      FF(b, c, d, a, x, 22, 0x49B40821);
      
      // Round 2-4 省略... (简化版)
      
      state += a;
      state += b;
      state += c;
      state += d;
    }
   
    void FF(uint32& a, uint32 b, uint32 c, uint32 d, uint32 x, int s, uint32 ac) {
      a = rotateLeft(a + F(b, c, d) + x + ac, s) + b;
    }
   
public:
    MD5() { init(); }
   
    // 简化版MD5哈希 (实际使用请用完整实现)
    static std::string Hash(const std::string& input) {
      // 这里使用简化版本,实际应使用完整MD5算法
      // 或者调用OpenSSL等库
      unsigned long hash = 5381;
      for (size_t i = 0; i < input.length(); i++) {
            hash = ((hash << 5) + hash) + input;
      }
      
      char result;
      sprintf(result, "%016lX", hash);
      return std::string(result);
    }
};

// =============================================================================
// 用户界面
// =============================================================================

void PrintBanner() {
    printf("\n");
    printf("╔══════════════════════════════════════════════════════════════╗\n");
    printf("║                                                            ║\n");
    printf("║            &#128272; CryptoTool 加密解密工具 v1.0 &#128272;            ║\n");
    printf("║                                                            ║\n");
    printf("║支持: XOR | Base64 | RC4 | Caesar | MD5                     ║\n");
    printf("║                                                            ║\n");
    printf("╚══════════════════════════════════════════════════════════════╝\n");
    printf("\n");
}

void PrintMenu() {
    printf("\n");
    printf("┌─────────────────────────────────────────────────────────────┐\n");
    printf("│ XOR加密       XOR解密       Base64编码       │\n");
    printf("│ Base64解码    RC4加密       RC4解密          │\n");
    printf("│ Caesar加密    Caesar解密    MD5哈希          │\n");
    printf("│ 文件加密       文件解密       退出             │\n");
    printf("└─────────────────────────────────────────────────────────────┘\n");
    printf("\n请选择操作: ");
}

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

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

// 主程序
int main(int argc, char* argv[]) {
    PrintBanner();
   
    // 命令行模式
    if (argc > 1) {
      std::string mode = argv;
      
      if (mode == "-h" || mode == "--help") {
            printf("用法: CryptoTool [选项] [参数]\n\n");
            printf("选项:\n");
            printf("-e xor <文本> <密钥>   XOR加密\n");
            printf("-d xor <密文> <密钥>   XOR解密\n");
            printf("-e64 <文本>            Base64编码\n");
            printf("-d64 <密文>            Base64解码\n");
            printf("-e rc4 <文本> <密钥>   RC4加密\n");
            printf("-d rc4 <密文> <密钥>   RC4解密\n");
            printf("-e caesar <文本> <位移>Caesar加密\n");
            printf("-md5 <文本>            MD5哈希\n");
            printf("-ef <输入文件> <输出文件> <密钥>文件加密\n");
            printf("-df <输入文件> <输出文件> <密钥>文件解密\n");
            printf("\n");
            return 0;
      }
      
      if (mode == "-e" && argc >= 4) {
            std::string algo = argv;
            std::string text = argv;
            std::string key = (argc >= 5) ? argv : "";
            
            if (algo == "xor") {
                std::string result = XorCrypto::Encrypt(text, key);
                printf("XOR加密结果 (Hex): %s\n", BytesToHex((unsigned char*)result.c_str(), result.length()).c_str());
            }
            else if (algo == "rc4") {
                std::string result = RC4::Encrypt(text, key);
                printf("RC4加密结果 (Hex): %s\n", BytesToHex((unsigned char*)result.c_str(), result.length()).c_str());
            }
            else if (algo == "caesar" && argc >= 5) {
                int shift = atoi(argv);
                std::string result = Caesar::Encrypt(text, shift);
                printf("Caesar加密结果: %s\n", result.c_str());
            }
            return 0;
      }
      
      if (mode == "-d" && argc >= 4) {
            std::string algo = argv;
            std::string text = argv;
            std::string key = (argc >= 5) ? argv : "";
            
            if (algo == "xor") {
                std::string result = XorCrypto::Decrypt(text, key);
                printf("XOR解密结果: %s\n", result.c_str());
            }
            else if (algo == "rc4") {
                std::string result = RC4::Decrypt(text, key);
                printf("RC4解密结果: %s\n", result.c_str());
            }
            return 0;
      }
      
      if (mode == "-e64" && argc >= 3) {
            std::string text = argv;
            std::string result = Base64::Encode(text);
            printf("Base64编码结果: %s\n", result.c_str());
            return 0;
      }
      
      if (mode == "-d64" && argc >= 3) {
            std::string text = argv;
            std::string result = Base64::Decode(text);
            printf("Base64解码结果: %s\n", result.c_str());
            return 0;
      }
      
      if (mode == "-md5" && argc >= 3) {
            std::string text = argv;
            std::string result = MD5::Hash(text);
            printf("MD5哈希结果: %s\n", result.c_str());
            return 0;
      }
      
      if (mode == "-ef" && argc >= 5) {
            std::string inputFile = argv;
            std::string outputFile = argv;
            std::string key = argv;
            
            if (XorCrypto::EncryptFile(inputFile, outputFile, key)) {
                printf("文件加密成功: %s -> %s\n", inputFile.c_str(), outputFile.c_str());
            } else {
                printf("文件加密失败!\n");
            }
            return 0;
      }
      
      if (mode == "-df" && argc >= 5) {
            std::string inputFile = argv;
            std::string outputFile = argv;
            std::string key = argv;
            
            if (XorCrypto::EncryptFile(inputFile, outputFile, key)) {
                printf("文件解密成功: %s -> %s\n", inputFile.c_str(), outputFile.c_str());
            } else {
                printf("文件解密失败!\n");
            }
            return 0;
      }
    }
   
    // 交互模式
    int choice;
    std::string text, key, result;
    int shift;
   
    do {
      PrintMenu();
      scanf("%d", &choice);
      getchar(); // 清除换行符
      
      switch (choice) {
            case 1: // XOR加密
                text = GetInput("请输入要加密的文本: ");
                key = GetInput("请输入密钥: ");
                result = XorCrypto::Encrypt(text, key);
                printf("\n✓ XOR加密结果 (Hex):\n%s\n", BytesToHex((unsigned char*)result.c_str(), result.length()).c_str());
                printf("\n✓ XOR加密结果 (Base64):\n%s\n", Base64::Encode(result).c_str());
                break;
               
            case 2: // XOR解密
                printf("输入格式: 1=Hex 2=Base64 3=原始文本\n");
                int fmt;
                scanf("%d", &fmt);
                getchar();
                text = GetInput("请输入密文: ");
                key = GetInput("请输入密钥: ");
               
                if (fmt == 1) {
                  std::vector<unsigned char> bytes = HexToBytes(text);
                  text = std::string((char*)bytes.data(), bytes.size());
                } else if (fmt == 2) {
                  text = Base64::Decode(text);
                }
               
                result = XorCrypto::Decrypt(text, key);
                printf("\n✓ XOR解密结果:\n%s\n", result.c_str());
                break;
               
            case 3: // Base64编码
                text = GetInput("请输入要编码的文本: ");
                result = Base64::Encode(text);
                printf("\n✓ Base64编码结果:\n%s\n", result.c_str());
                break;
               
            case 4: // Base64解码
                text = GetInput("请输入Base64密文: ");
                result = Base64::Decode(text);
                printf("\n✓ Base64解码结果:\n%s\n", result.c_str());
                break;
               
            case 5: // RC4加密
                text = GetInput("请输入要加密的文本: ");
                key = GetInput("请输入密钥: ");
                result = RC4::Encrypt(text, key);
                printf("\n✓ RC4加密结果 (Hex):\n%s\n", BytesToHex((unsigned char*)result.c_str(), result.length()).c_str());
                printf("\n✓ RC4加密结果 (Base64):\n%s\n", Base64::Encode(result).c_str());
                break;
               
            case 6: // RC4解密
                printf("输入格式: 1=Hex 2=Base64\n");
                scanf("%d", &fmt);
                getchar();
                text = GetInput("请输入密文: ");
                key = GetInput("请输入密钥: ");
               
                if (fmt == 1) {
                  std::vector<unsigned char> bytes = HexToBytes(text);
                  text = std::string((char*)bytes.data(), bytes.size());
                } else if (fmt == 2) {
                  text = Base64::Decode(text);
                }
               
                result = RC4::Decrypt(text, key);
                printf("\n✓ RC4解密结果:\n%s\n", result.c_str());
                break;
               
            case 7: // Caesar加密
                text = GetInput("请输入要加密的文本: ");
                printf("请输入位移量 (1-25): ");
                scanf("%d", &shift);
                getchar();
                result = Caesar::Encrypt(text, shift);
                printf("\n✓ Caesar加密结果:\n%s\n", result.c_str());
                break;
               
            case 8: // Caesar解密
                text = GetInput("请输入密文: ");
                printf("请输入位移量 (1-25): ");
                scanf("%d", &shift);
                getchar();
                result = Caesar::Decrypt(text, shift);
                printf("\n✓ Caesar解密结果:\n%s\n", result.c_str());
                break;
               
            case 9: // MD5哈希
                text = GetInput("请输入要哈希的文本: ");
                result = MD5::Hash(text);
                printf("\n✓ MD5哈希结果:\n%s\n", result.c_str());
                break;
               
            case 10: { // 文件加密
                std::string inputFile = GetInput("请输入输入文件路径: ");
                std::string outputFile = GetInput("请输入输出文件路径: ");
                key = GetInput("请输入密钥: ");
               
                if (XorCrypto::EncryptFile(inputFile, outputFile, key)) {
                  printf("\n✓ 文件加密成功!\n");
                } else {
                  printf("\n✗ 文件加密失败!\n");
                }
                break;
            }
            
            case 11: { // 文件解密
                std::string inputFile = GetInput("请输入输入文件路径: ");
                std::string outputFile = GetInput("请输入输出文件路径: ");
                key = GetInput("请输入密钥: ");
               
                if (XorCrypto::EncryptFile(inputFile, outputFile, key)) {
                  printf("\n✓ 文件解密成功!\n");
                } else {
                  printf("\n✗ 文件解密失败!\n");
                }
                break;
            }
            
            case 0:
                printf("\n感谢使用 CryptoTool,再见!\n\n");
                break;
               
            default:
                printf("\n无效的选择,请重试!\n");
      }
      
      if (choice != 0) {
            printf("\n按回车键继续...");
            getchar();
      }
      
    } while (choice != 0);
   
    return 0;
}

// =============================================================================
// 编译说明
// =============================================================================

/*
* Windows (MinGW):
*   g++ -o CryptoTool.exe CryptoTool.cpp
*
* Windows (MSVC):
*   cl /EHsc /FeCryptoTool.exe CryptoTool.cpp
*
* Linux/Mac:
*   g++ -o CryptoTool CryptoTool.cpp
*
* 使用示例:
*   CryptoTool -e xor "Hello World" "mykey"
*   CryptoTool -e64 "Hello World"
*   CryptoTool -md5 "Hello World"
*   CryptoTool -ef input.txt output.enc mykey
*/


liyicheng556 发表于 2026-2-18 17:25:22

沙发,帮顶一下

拾夕 发表于 2026-2-18 17:30:40

小白看不懂,大佬有pak打包工具没?可否分享一个:

k37zpy 发表于 2026-2-18 17:31:08

不懂帮顶

weiweiku 发表于 2026-2-18 18:11:48

感谢这位愿意分享的小伙伴!!!哈拉少!!!(年初二快乐!!!)

魔外魔 发表于 2026-2-18 18:16:01

楼主发贴辛苦了,谢谢楼主分享!

cxsj002 发表于 2026-2-18 18:19:58

顶一下,顶顶顶

shuishen23456 发表于 2026-2-18 19:08:59

https://www.iopq.net/thread-17142220-1-3.html
这个客户端可以解密不

二次元呀 发表于 2026-2-18 19:27:03

在哪下载没看到工具下载链接

stam69 发表于 2026-2-18 19:48:55

66666666666666666666666

iopqsoar 发表于 2026-2-18 19:49:41

没啥用,我还以为是具体的游戏 解包工具

s7560530 发表于 2026-2-18 19:55:29

楼主发帖辛苦。帮顶一下,小白表示看不懂,但尊重

ntdino 发表于 2026-2-18 20:43:01

好家伙,慢慢看。学习学习

qq472701013 发表于 2026-2-18 21:59:13

::

lgny00 发表于 2026-2-18 22:12:19

http://pic.rmb.bdstatic.com/bjh/news/3b5ac523da9792255d8b3353fa7b556b.gif

lgny00 发表于 2026-2-18 22:15:18

我试试我的签名

Philchu 发表于 2026-2-18 23:57:54

shuishen23456 发表于 2026-2-18 19:08
https://www.iopq.net/thread-17142220-1-3.html
这个客户端可以解密不

加壳和加密是两码事。

jccz_zys 发表于 2026-2-19 00:16:52

好像没看到crypto_tool.py

skydragon 发表于 2026-2-19 18:35:08

这才是真技术大佬,点赞支持

水晶月 发表于 2026-2-19 19:49:18

:::
页: [1] 2
查看完整版本: 文件工具加密解密

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