寻找C语言加密算法源码ing
最近写C语言程序需要加密功能,在网上查了一下,能找到的加密算法是TEA加密,但也是C++的所以麻烦问一下诸位有没有更好的推荐
P.S.在下对密码学一点都不了解,所以这次就功利一点,只要C语言加密算法源代码,写程序时直接拿来就用吧
(* ̄︶ ̄)y
P.P.S.加密算法不用太高级,只要有一定安全性即可,或者各位启发一下我,给个思路呗(涉及到C语言的位操作就算了,我当初把这部分跳过了)
#include<iostream> using namespace std; void menu() { cout << " 1、凯撒加密\n"; cout << " 2、凯撒解密\n"; cout << " 3、换字式加密\n"; cout << " 4、换字式解密\n"; cout << " 5、多表替代加密\n"; cout << " 6、多表替代解密\n"; cout << "\n 请选择: "; } void kaisajia() { cin.get(); char mi[100]; int n; cout << "请输入明文:"; gets_s(mi); cout << "需要移动的位数:"; cin >> n; for (int i = 0; i < strlen(mi); i++) for (int j = 0; j < n; j++) { if ((mi[i] >= 'a'&&mi[i] <= 'z') || (mi[i] >= 'A'&&mi[i] <= 'Z')) { if (mi[i] == 'z' || mi[i] == 'Z') mi[i] -= 26; mi[i]++; } } cout << "得到的密文为:" << mi << endl; cin.get(); cin.get(); system("cls"); } void kaisajie() { cin.get(); char mi[100]; cout << "请输入密文:"; gets_s(mi); for (int j = 0; j < 26; j++) { for (int i = 0; i < strlen(mi); i++) { if ((mi[i] >= 'a'&&mi[i] <= 'z') || (mi[i] >= 'A'&&mi[i] <= 'Z')) { if (mi[i] == 'z' || mi[i] == 'Z') mi[i] -= 26; mi[i]++; } } cout << "明文组合" << j + 1 << ":"<<mi<<endl; } cin.get(); system("cls"); } void huanzijia() { char a[28]{ 'd','c','f', 'e', 'h', 'a', 'b', 'o', 'r', 'g', 't', 'w', 's', 'i','x','z', 'j','l', 'n', 'm', 'u', 'y', 'k','q','v','p' }; char b[28]{ 'P','X','Q', 'K', 'Y', 'U', 'M', 'N', 'L', 'J', 'Z', 'X', 'I', 'S','W','T', 'G','R', 'O', 'B', 'Q', 'H', 'E','F','C','D' }; cin.get(); char mi[100]; cout << "请输入明文:"; gets_s(mi); for (int i = 0; i < strlen(mi); i++) { if (mi[i] >= 'a'&&mi[i] <= 'z') mi[i] = a[(int)mi[i]-97]; if (mi[i] >= 'A'&&mi[i] <= 'Z') mi[i] = a[(int)mi[i] - 65]; } cout << "密文为:"<<mi << endl; cin.get(); system("cls"); } void huanzijie() { char a[28]{ 'd','c','f', 'e', 'h', 'a', 'b', 'o', 'r', 'g', 't', 'w', 's', 'i','x','z', 'j','l', 'n', 'm', 'u', 'y', 'k','q','v','p' }; char b[28]{ 'P','X','Q', 'K', 'Y', 'U', 'M', 'N', 'L', 'J', 'Z', 'X', 'I', 'S','W','T', 'G','R', 'O', 'B', 'Q', 'H', 'E','F','C','D' }; cin.get(); char mi[100]; cout << "请输入密文:"; gets_s(mi); for (int i = 0; i < strlen(mi); i++) { if (mi[i] >= 'a'&&mi[i] <= 'z') { int j = 0; while (mi[i] != a[j]) j++; mi[i] = (char)(j + 97); } if (mi[i] >= 'A'&&mi[i] <= 'Z') { int j = 0; while (mi[i] != a[j]) j++; mi[i] = (char)(j + 65); } } cout << "明文为:" << mi << endl; cin.get(); system("cls"); } void duobiaojia() { cin.get(); char mi[100]; int n,a,flag=0,ow=0; cout << "请输入明文:"; gets_s(mi); cout << "请问需要多少字符一组:"; cin >> n; if (strlen(mi) % n) flag++; for (int i = 0; i <strlen(mi)/n+flag; i++) { cout << "第" << i+1 << "组移动字符数:"; cin >> a; for (int j = 0; j < n; j++) { if ((mi[j+i*n] >= 'a'&&mi[j + i * n] <= 'z') || (mi[j + i * n] >= 'A'&&mi[j + i * n] <= 'Z')) { for (int k = 0; k < a; k++) { if (mi[j + i * n] == 'z' || mi[j + i * n] == 'Z') mi[j + i * n] -= 26; mi[j + i * n]++; } } } } cout << "密文为:" << mi << endl; cin.get(); cin.get(); system("cls"); } void duobiaojie() { cin.get(); char mi[100],ow[100]; cout << "请输入密文:"; gets_s(mi); strcpy_s(ow, mi); int flag = 0; for (int n = 1; n < 10; n++) //假设的一组的个数 { if (strlen(mi) > n) { if (strlen(mi) % n) flag++; for (int k = 1; k <26; k++)//假设的步长 { for (int j = 0; j < n; j++) //一组的个数 { for (int i = 0; i < strlen(mi) / n + flag; i++) //分组数 if ((mi[j + i * n] >= 'a'&&mi[j + i * n] <= 'z') || (mi[j + i * n] >= 'A'&&mi[j + i * n] <= 'Z')) { if (mi[j + i * n] == 'z' || mi[j + i * n] == 'Z') mi[j + i * n] -= 26; mi[j + i * n]++; cout <<"分组-" << n<<"步长"<<26-k << " 明文:" << mi << endl; } } } } strcpy_s(mi, ow); } cin.get(); system("cls"); } void main() { while (true) { menu(); int n; cin >> n; system("cls"); switch (n) { case 1: kaisajia(); break; case 2: kaisajie(); break; case 3: huanzijia(); break; case 4: huanzijie(); break; case 5: duobiaojia(); break; case 6: duobiaojie(); break; default: break; } } system("pause"); }