版本比较
W密码编辑器 v2.0.0 发布说明
正文
增加 34 行删除 34 行
29 行未改动3031323334353637383940414211 行未改动5455565758596061626364656667686910 行未改动808182838485868788899091929394959697989910010110210310 行未改动11411511611711811912012112212312412512612712812913013113213313413513612 行未改动1491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881894 行未改动1941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342357 行未改动2432442452462472482492502512522532542552562572582592602612622632642652 行未改动26826927027127227327427527627727827928028128228328428528628728828929029129229329429529667 行未改动29 行未改动string trim(const string& str);int main() {int choice;do {showMainMenu();choice = getValidatedInteger("请选择操作 [1-5]: ");switch(choice) {case 1:encryptText();break;11 行未改动break;default:cout << "无效选择,请重新输入!" << endl;}if (choice != 5) {cout << "\n按回车键继续...";cin.ignore();cin.get();}} while (choice != 5);return 0;}void showMainMenu() {10 行未改动}void encryptText() {cout << "\n【文本加密】" << endl;// 获取密钥int key = getValidatedInteger("请输入加密密钥(整数): ");cin.ignore(); // 清除输入缓冲区// 获取要加密的文本string text;cout << "请输入要加密的文本: ";getline(cin, text);if (text.empty()) {cout << "输入不能为空!" << endl;return;}// 执行加密cout << "加密结果(数字序列): ";for (char c : text) {size_t pos = HANZI_SET.find(c);10 行未改动}void decryptText() {cout << "\n【文本解密】" << endl;// 获取密钥int key = getValidatedInteger("请输入解密密钥(整数): ");// 获取数字序列数量int count = getValidatedInteger("请输入要解密的数据数量: ");vector<int> numbers;cout << "请输入数字序列(用空格分隔): ";for (int i = 0; i < count; i++) {int num;cin >> num;numbers.push_back(num);}// 执行解密cout << "解密结果: ";for (int num : numbers) {if (num >= 0 && num < HANZI_SET.size()) {12 行未改动}void encryptFile() {cout << "\n【文件加密】" << endl;// 获取密钥int key = getValidatedInteger("请输入加密密钥(整数): ");cin.ignore(); // 清除输入缓冲区// 获取文件路径string sourcePath, targetPath;cout << "请输入源文件路径: ";getline(cin, sourcePath);cout << "请输入目标文件路径: ";getline(cin, targetPath);// 打开文件ifstream sourceFile(sourcePath);if (!sourceFile) {cout << "无法打开源文件!" << endl;return;}ofstream targetFile(targetPath);if (!targetFile) {cout << "无法创建目标文件!" << endl;sourceFile.close();return;}// 读取源文件内容stringstream buffer;buffer << sourceFile.rdbuf();string content = buffer.str();sourceFile.close();// 加密内容for (char c : content) {size_t pos = HANZI_SET.find(c);if (pos != string::npos) {4 行未改动// 对于不在字符集中的字符,输出-1标记targetFile << "-1 ";}}targetFile.close();cout << "文件加密完成!结果已保存到: " << targetPath << endl;}void decryptFile() {cout << "\n【文件解密】" << endl;// 获取密钥int key = getValidatedInteger("请输入解密密钥(整数): ");cin.ignore(); // 清除输入缓冲区// 获取文件路径string sourcePath, targetPath;cout << "请输入源文件路径: ";getline(cin, sourcePath);cout << "请输入目标文件路径: ";getline(cin, targetPath);// 打开文件ifstream sourceFile(sourcePath);if (!sourceFile) {cout << "无法打开源文件!" << endl;return;}ofstream targetFile(targetPath);if (!targetFile) {cout << "无法创建目标文件!" << endl;sourceFile.close();return;}// 解密内容int num;while (sourceFile >> num) {if (num >= 0 && num < HANZI_SET.size()) {7 行未改动// 处理无效数字targetFile << "#";}}sourceFile.close();targetFile.close();cout << "文件解密完成!结果已保存到: " << targetPath << endl;}// 获取验证过的整数输入int getValidatedInteger(const string& prompt) {string input;int result;while (true) {cout << prompt;cin >> input;if (isAllDigits(input)) {try {result = stoi(input);break;2 行未改动}} else {cout << "请输入有效的整数!" << endl;}// 清除错误状态和输入缓冲区cin.clear();cin.ignore(numeric_limits<streamsize>::max(), '\n');}return result;}// 检查字符串是否全部由数字组成bool isAllDigits(const string& str) {return all_of(str.begin(), str.end(), [](char c) {return isdigit(c) || (c == '-' && &c == &str[0]); // 允许负号只在开头});}`// 去除字符串两端的空白字符string trim(const string& str) {size_t start = str.find_first_not_of(" \t\n\r");if (start == string::npos) return "";size_t end = str.find_last_not_of(" \t\n\r");return str.substr(start, end - start + 1);}```67 行未改动29 行未改动3031323334353637383940414211 行未改动5455565758596061626364656667686910 行未改动808182838485868788899091929394959697989910010110210310 行未改动11411511611711811912012112212312412512612712812913013113213313413513612 行未改动1491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881894 行未改动1941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342357 行未改动2432442452462472482492502512522532542552562572582592602612622632642652 行未改动26826927027127227327427527627727827928028128228328428528628728828929029129229329429529667 行未改动29 行未改动string trim(const string& str);int main() {int choice;do {showMainMenu();choice = getValidatedInteger("请选择操作 [1-5]: ");switch(choice) {case 1:encryptText();break;11 行未改动break;default:cout << "无效选择,请重新输入!" << endl;}if (choice != 5) {cout << "\n按回车键继续...";cin.ignore();cin.get();}} while (choice != 5);return 0;}void showMainMenu() {10 行未改动}void encryptText() {cout << "\n【文本加密】" << endl;// 获取密钥int key = getValidatedInteger("请输入加密密钥(整数): ");cin.ignore(); // 清除输入缓冲区// 获取要加密的文本string text;cout << "请输入要加密的文本: ";getline(cin, text);if (text.empty()) {cout << "输入不能为空!" << endl;return;}// 执行加密cout << "加密结果(数字序列): ";for (char c : text) {size_t pos = HANZI_SET.find(c);10 行未改动}void decryptText() {cout << "\n【文本解密】" << endl;// 获取密钥int key = getValidatedInteger("请输入解密密钥(整数): ");// 获取数字序列数量int count = getValidatedInteger("请输入要解密的数据数量: ");vector<int> numbers;cout << "请输入数字序列(用空格分隔): ";for (int i = 0; i < count; i++) {int num;cin >> num;numbers.push_back(num);}// 执行解密cout << "解密结果: ";for (int num : numbers) {if (num >= 0 && num < HANZI_SET.size()) {12 行未改动}void encryptFile() {cout << "\n【文件加密】" << endl;// 获取密钥int key = getValidatedInteger("请输入加密密钥(整数): ");cin.ignore(); // 清除输入缓冲区// 获取文件路径string sourcePath, targetPath;cout << "请输入源文件路径: ";getline(cin, sourcePath);cout << "请输入目标文件路径: ";getline(cin, targetPath);// 打开文件ifstream sourceFile(sourcePath);if (!sourceFile) {cout << "无法打开源文件!" << endl;return;}ofstream targetFile(targetPath);if (!targetFile) {cout << "无法创建目标文件!" << endl;sourceFile.close();return;}// 读取源文件内容stringstream buffer;buffer << sourceFile.rdbuf();string content = buffer.str();sourceFile.close();// 加密内容for (char c : content) {size_t pos = HANZI_SET.find(c);if (pos != string::npos) {4 行未改动// 对于不在字符集中的字符,输出-1标记targetFile << "-1 ";}}targetFile.close();cout << "文件加密完成!结果已保存到: " << targetPath << endl;}void decryptFile() {cout << "\n【文件解密】" << endl;// 获取密钥int key = getValidatedInteger("请输入解密密钥(整数): ");cin.ignore(); // 清除输入缓冲区// 获取文件路径string sourcePath, targetPath;cout << "请输入源文件路径: ";getline(cin, sourcePath);cout << "请输入目标文件路径: ";getline(cin, targetPath);// 打开文件ifstream sourceFile(sourcePath);if (!sourceFile) {cout << "无法打开源文件!" << endl;return;}ofstream targetFile(targetPath);if (!targetFile) {cout << "无法创建目标文件!" << endl;sourceFile.close();return;}// 解密内容int num;while (sourceFile >> num) {if (num >= 0 && num < HANZI_SET.size()) {7 行未改动// 处理无效数字targetFile << "#";}}sourceFile.close();targetFile.close();cout << "文件解密完成!结果已保存到: " << targetPath << endl;}// 获取验证过的整数输入int getValidatedInteger(const string& prompt) {string input;int result;while (true) {cout << prompt;cin >> input;if (isAllDigits(input)) {try {result = stoi(input);break;2 行未改动}} else {cout << "请输入有效的整数!" << endl;}// 清除错误状态和输入缓冲区cin.clear();cin.ignore(numeric_limits<streamsize>::max(), '\n');}return result;}// 检查字符串是否全部由数字组成bool isAllDigits(const string& str) {return all_of(str.begin(), str.end(), [](char c) {return isdigit(c) || (c == '-' && &c == &str[0]); // 允许负号只在开头});}`// 去除字符串两端的空白字符string trim(const string& str) {size_t start = str.find_first_not_of(" \t\n\r");if (start == string::npos) return "";size_t end = str.find_last_not_of(" \t\n\r");return str.substr(start, end - start + 1);}```67 行未改动