今天没有事情做 做了个文件加密工具 有一些人辛辛苦苦改出来的东西一下子被别人复制
# 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
```
---
## 📋 算法说明
### 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. **文件加密**: 加密前请备份原始文件
---
## 🔗 集成到项目
### 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[i];
}
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[i] ^= key[i % keyLen];
}
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[keyIndex % keyLen];
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[3], charArray4[4];
for (size_t in_len = input.length(), pos = 0; pos < in_len; ) {
charArray3[i++] = input[pos++];
if (i == 3) {
charArray4[0] = (charArray3[0] & 0xfc) >> 2;
charArray4[1] = ((charArray3[0] & 0x03) << 4) + ((charArray3[1] & 0xf0) >> 4);
charArray4[2] = ((charArray3[1] & 0x0f) << 2) + ((charArray3[2] & 0xc0) >> 6);
charArray4[3] = charArray3[2] & 0x3f;
for (i = 0; i < 4; i++)
encoded += base64Chars[charArray4[i]];
i = 0;
}
}
if (i) {
for (int j = i; j < 3; j++)
charArray3[j] = '\0';
charArray4[0] = (charArray3[0] & 0xfc) >> 2;
charArray4[1] = ((charArray3[0] & 0x03) << 4) + ((charArray3[1] & 0xf0) >> 4);
charArray4[2] = ((charArray3[1] & 0x0f) << 2) + ((charArray3[2] & 0xc0) >> 6);
for (int j = 0; j < (i + 1); j++)
encoded += base64Chars[charArray4[j]];
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[4], charArray3[3];
while (in_len-- && (encoded[in_] != '=') &&
(isalnum(encoded[in_]) || encoded[in_] == '+' || encoded[in_] == '/')) {
charArray4[i++] = encoded[in_]; in_++;
if (i == 4) {
for (i = 0; i < 4; i++)
charArray4[i] = (unsigned char)strchr(base64Chars, charArray4[i]) - base64Chars;
charArray3[0] = (charArray4[0] << 2) + ((charArray4[1] & 0x30) >> 4);
charArray3[1] = ((charArray4[1] & 0xf) << 4) + ((charArray4[2] & 0x3c) >> 2);
charArray3[2] = ((charArray4[2] & 0x3) << 6) + charArray4[3];
for (i = 0; i < 3; i++)
decoded += charArray3[i];
i = 0;
}
}
if (i) {
for (j = 0; j < i; j++)
charArray4[j] = (unsigned char)strchr(base64Chars, charArray4[j]) - base64Chars;
charArray3[0] = (charArray4[0] << 2) + ((charArray4[1] & 0x30) >> 4);
charArray3[1] = ((charArray4[1] & 0xf) << 4) + ((charArray4[2] & 0x3c) >> 2);
for (j = 0; j < (i - 1); j++)
decoded += charArray3[j];
}
return decoded;
}
};
const char* Base64::base64Chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
// =============================================================================
// 3. RC4 流加密
// =============================================================================
class RC4 {
private:
unsigned char S[256];
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] = k;
}
int j = 0;
int keyLen = key.length();
for (int k = 0; k < 256; k++) {
j = (j + S[k] + (unsigned char)key[k % keyLen]) % 256;
swap(S[k], S[j]);
}
i = 0;
j = 0;
}
// 生成伪随机字节流 (PRGA)
unsigned char GenerateByte() {
i = (i + 1) % 256;
j = (j + S[i]) % 256;
swap(S[i], S[j]);
return S[(S[i] + S[j]) % 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[k] ^= 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[i])) {
char base = isupper(result[i]) ? 'A' : 'a';
result[i] = (result[i] - 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[4];
uint32 count[2];
unsigned char buffer[64];
void init() {
state[0] = 0x67452301;
state[1] = 0xEFCDAB89;
state[2] = 0x98BADCFE;
state[3] = 0x10325476;
count[0] = count[1] = 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[64]) {
uint32 a = state[0], b = state[1], c = state[2], d = state[3];
uint32 x[16];
for (int i = 0; i < 16; i++)
x[i] = ((uint32)block[i * 4]) | (((uint32)block[i * 4 + 1]) << 8) |
(((uint32)block[i * 4 + 2]) << 16) | (((uint32)block[i * 4 + 3]) << 24);
// Round 1
FF(a, b, c, d, x[0], 7, 0xD76AA478);
FF(d, a, b, c, x[1], 12, 0xE8C7B756);
FF(c, d, a, b, x[2], 17, 0x242070DB);
FF(b, c, d, a, x[3], 22, 0xC1BDCEEE);
FF(a, b, c, d, x[4], 7, 0xF57C0FAF);
FF(d, a, b, c, x[5], 12, 0x4787C62A);
FF(c, d, a, b, x[6], 17, 0xA8304613);
FF(b, c, d, a, x[7], 22, 0xFD469501);
FF(a, b, c, d, x[8], 7, 0x698098D8);
FF(d, a, b, c, x[9], 12, 0x8B44F7AF);
FF(c, d, a, b, x[10], 17, 0xFFFF5BB1);
FF(b, c, d, a, x[11], 22, 0x895CD7BE);
FF(a, b, c, d, x[12], 7, 0x6B901122);
FF(d, a, b, c, x[13], 12, 0xFD987193);
FF(c, d, a, b, x[14], 17, 0xA679438E);
FF(b, c, d, a, x[15], 22, 0x49B40821);
// Round 2-4 省略... (简化版)
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += 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[i];
}
char result[17];
sprintf(result, "%016lX", hash);
return std::string(result);
}
};
// =============================================================================
// 用户界面
// =============================================================================
void PrintBanner() {
printf("\n");
printf("╔══════════════════════════════════════════════════════════════╗\n");
printf("║ ║\n");
printf("║ 🔐 CryptoTool 加密解密工具 v1.0 🔐 ║\n");
printf("║ ║\n");
printf("║ 支持: XOR | Base64 | RC4 | Caesar | MD5 ║\n");
printf("║ ║\n");
printf("╚══════════════════════════════════════════════════════════════╝\n");
printf("\n");
}
void PrintMenu() {
printf("\n");
printf("┌─────────────────────────────────────────────────────────────┐\n");
printf("│ [1] XOR加密 [2] XOR解密 [3] Base64编码 │\n");
printf("│ [4] Base64解码 [5] RC4加密 [6] RC4解密 │\n");
printf("│ [7] Caesar加密 [8] Caesar解密 [9] MD5哈希 │\n");
printf("│ [10] 文件加密 [11] 文件解密 [0] 退出 │\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[1];
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[2];
std::string text = argv[3];
std::string key = (argc >= 5) ? argv[4] : "";
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[4]);
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[2];
std::string text = argv[3];
std::string key = (argc >= 5) ? argv[4] : "";
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[2];
std::string result = Base64::Encode(text);
printf("Base64编码结果: %s\n", result.c_str());
return 0;
}
if (mode == "-d64" && argc >= 3) {
std::string text = argv[2];
std::string result = Base64::Decode(text);
printf("Base64解码结果: %s\n", result.c_str());
return 0;
}
if (mode == "-md5" && argc >= 3) {
std::string text = argv[2];
std::string result = MD5::Hash(text);
printf("MD5哈希结果: %s\n", result.c_str());
return 0;
}
if (mode == "-ef" && argc >= 5) {
std::string inputFile = argv[2];
std::string outputFile = argv[3];
std::string key = argv[4];
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[2];
std::string outputFile = argv[3];
std::string key = argv[4];
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
*/
![[其他工具] 文件工具加密解密](http://static.527wan.top/wp-content/uploads/2026/02/eb942f673620260218180103.png)
本站使用静态缓存,登录后获取实时最新资源下载。推荐使用账号密码登录。
如遇夸克/网盘资源失效,请发帖反馈。站长会积极补链,同时在您的帖子下方评论告知。
© 版权声明
资源来源于互联网,供学习交流。如涉侵权,请邮件联系,将予七日内处理。
请在下载后24小时内删除,切勿商用。使用者需自行承担相应法律责任,发布者概不负责。
请在下载后24小时内删除,切勿商用。使用者需自行承担相应法律责任,发布者概不负责。
THE END













暂无评论内容