加密程序如下
#include<bits/stdc++.h>
using namespace std;
const char MAP[4] = {'@','#','$','*'};
int x;
bool hh_flag;
string s;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
srand(time(0));
cout << "输入加密内容:" << endl;
getline(cin,s);
cout << "加密频率(100以内):" << endl;
cin >> x;
cout << "开换行?(实验性内容):" << endl;
cin >> hh_flag;
freopen("qwerty.txt","w",stdout);
for (int j = 0;j < s.length();j++){
int k = s[j];
int yj = 0;
for (int i = 6;i >= 0;i -= 2){
int bit1 = (k>>i)&1;
int bit2 = (k>>(i+1))&1;
cout << MAP[(bit2<<1)+bit1];
if (rand()%20000 < x*x) cout << "%";
if (rand()%20000 < x*x) cout << "~";
if (rand()%40000 < x*x && hh_flag) cout << endl;
}
cout << "^";
}
exit(163699);
}解密程序如下
#include<bits/stdc++.h>
using namespace std;
int gnsw(char c) {
if (c == '@') return 0;
if (c == '#') return 1;
if (c == '$') return 2;
if (c == '*') return 3;
return -1;
}
int x,bt;
string s;
void fycstart(){
cout << "遇到不可解密的错误,为保障数据及您的电脑,已自动终止程序" << endl;
#ifdef _WIN32
system("pause");
#endif
exit(163699);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
//cout << "输入解密内容:" << endl;
//在这里输入解密文件
freopen("qwerty.txt","r",stdin);
cin >> s;
for (int i = 0;i < s.length();i++){
if (s[i] == '~' || s[i] == '%' || s[i] == '!') continue;
if (s[i] == '^'){
if (bt) cout << char(x);
x = 0;
bt = 0;
}else{
int nsw = gnsw(s[i]);
if (nsw == -1){
fycstart();
}
if (bt > 8) {
fycstart();
}
if (nsw&2) x += (1<<(7-bt));
bt++;
if (nsw&1) x += (1<<(7-bt));
bt++;
}
}
if (bt > 0) cout << (char)x;
cout << endl;
#ifdef _WIN32
system("pause");
#endif
exit(163699);
}