自制C语言密码加密代码-创新互联
这是通过把阿拉伯数字进行乱序的原理,将其中的所有英文字母替换成为字母表中的后一个字母,其他字母原样输出,符号不改变
公司专注于为企业提供成都做网站、成都网站建设、成都外贸网站建设、微信公众号开发、商城开发,小程序开发,软件定制网站等一站式互联网企业服务。凭借多年丰富的经验,我们会仔细了解各客户的需求而做出多方面的分析、设计、整合,为客户设计出具风格及创意性的商业解决方案,成都创新互联公司更提供一系列网站制作和网站推广的服务。#include
#include
#include
#include
#define MAXN 1000
using namespace std;
void simple(int n);
void middle(int n);
void hard(int n);
void encrypt1();
void encrypt2();
void unencrypt();
void Create();
static char array3[100];
static int num1, count2;
int main() {
srand(time(NULL));
int b;
cout<< "1:输入加密 enter to encrypt\n2:输入解密 enter to unencrypt\n3:生成秘钥 Create a password"<< endl;
cin >>b;
if (b >0 && b< 4) {
switch (b) {
case 1:
encrypt1();
break;
case 2:
unencrypt();
break;
case 3:
Create();
break;
}
} else cout<< "输入错误\nInput error"<< endl;
}
void simple(int n) {
int a[n], y, count = 0;
for (int i = 0; count<= n; i++) {
y = rand() % 123;
if (y >= 48 && y<= 57) {
a[count] = y;
count++;
}
}
cout<< "生成的密码是 ";
for (int i = 0; i<= (n - 1); i++) {
cout.put(a[i]);
count2++;
array3[count2] = a[i];
}
cout<< "\n";
}
void middle(int n) {
int a[n], y, count = 0;
for (int i = 0; count<= n; i++) {
y = rand() % 123;
if ((y >= 48 && y<= 57) || (y >= 65 && y<= 90) || (y >= 97 && y<= 122)) {
a[count] = y;
count++;
}
}
cout<< "生成的密码是 ";
for (int i = 0; i<= (n - 1); i++) {
cout.put(a[i]);
count2++;
array3[count2] = a[i];
}
cout<< "\n";
}
void hard(int n) {
int a[n], y, count = 0;
for (int i = 0; count<= n; i++) {
y = rand() % 123;
if (y >33 && y< 126 && y != 32) {
a[count] = y;
count++;
}
}
cout<< "生成的密码是 ";
for (int i = 0; i<= (n - 1); i++) {
cout.put(a[i]);
count2++;
array3[count2] = a[i];
}
cout<< "\n";
}
void encrypt1() {
char array1[MAXN];
char c;
scanf("%c", &c);
cout<< "请输入需要加密的密码 please enter you passcode"<< endl;
int count = 0;
for (int i = 0; i<= MAXN; i++) {
array1[i] = getchar();
if (array1[i] == '\n') {
break;
}
count++;
}
for (int i = 0; i<= count; i++) {
if (array1[i] == '0') {
array1[i] = '6';
} else if (array1[i] == '1') {
array1[i] = '4';
} else if (array1[i] == '2') {
array1[i] = '5';
} else if (array1[i] == '3') {
array1[i] = '7';
} else if (array1[i] == '4') {
array1[i] = '3';
} else if (array1[i] == '5') {
array1[i] = '0';
} else if (array1[i] == '6') {
array1[i] = '1';
} else if (array1[i] == '7') {
array1[i] = '2';
} else if (array1[i] == '8') {
array1[i] = '9';
} else if (array1[i] == '9') {
array1[i] = '8';
} else if (array1[i] >= 'a' && array1[i]<= 'y') {
array1[i] = array1[i] + 1;
} else if (array1[i] == 'z') {
array1[i] = 'a';
} else if (array1[i] >= 'A' && array1[i]<= 'Y') {
array1[i] = array1[i] + 1;
} else if (array1[i] == 'Z') {
array1[i] = 'A';
} else {
array1[i] = array1[i];
}
}
for (int i = 0; i<= count; i++) {
cout.put(array1[i]);
}
}
void encrypt2() {
for (int i = 0; i<= count2; i++) {
if (array3[i] == '0') {
array3[i] = '6';
} else if (array3[i] == '1') {
array3[i] = '4';
} else if (array3[i] == '2') {
array3[i] = '5';
} else if (array3[i] == '3') {
array3[i] = '7';
} else if (array3[i] == '4') {
array3[i] = '3';
} else if (array3[i] == '5') {
array3[i] = '0';
} else if (array3[i] == '6') {
array3[i] = '1';
} else if (array3[i] == '7') {
array3[i] = '2';
} else if (array3[i] == '8') {
array3[i] = '9';
} else if (array3[i] == '9') {
array3[i] = '8';
} else if (array3[i] >= 'a' && array3[i]<= 'y') {
array3[i] = array3[i] + 1;
} else if (array3[i] == 'z') {
array3[i] = 'A';
} else if (array3[i] >= 'A' && array3[i]<= 'Y') {
array3[i] = array3[i] + 1;
} else if (array3[i] == 'Z') {
array3[i] = 'A';
} else {
array3[i] = array3[i];
}
}
cout<< "加密后的的密码是 ";
for (int i = 0; i<= count2; i++) {
cout.put(array3[i]);
}
}
void unencrypt() {
char array2[MAXN];
char c;
scanf("%c", &c);
cout<< "请输入需要解密的密码 please enter you passcode"<< endl;
int count = 0;
for (int i = 0; i<= MAXN; i++) {
array2[i] = getchar();
if (array2[i] == '\n') {
break;
}
count++;
}
for (int i = 0; i<= count; i++) {
if (array2[i] == '6') {
array2[i] = '0';
} else if (array2[i] == '4') {
array2[i] = '1';
} else if (array2[i] == '5') {
array2[i] = '2';
} else if (array2[i] == '7') {
array2[i] = '3';
} else if (array2[i] == '3') {
array2[i] = '4';
} else if (array2[i] == '0') {
array2[i] = '5';
} else if (array2[i] == '1') {
array2[i] = '6';
} else if (array2[i] == '2') {
array2[i] = '7';
} else if (array2[i] == '9') {
array2[i] = '8';
} else if (array2[i] == '8') {
array2[i] = '9';
} else if (array2[i] >= 'b' && array2[i]<= 'z') {
array2[i] = array2[i] - 1;
} else if (array2[i] == 'a') {
array2[i] = 'z';
} else if (array2[i] >= 'B' && array2[i]<= 'Z') {
array2[i] = array2[i] - 1;
} else if (array2[i] == 'A') {
array2[i] = 'Z';
} else {
array2[i] = array2[i];
}
}
cout<< "解密后的的密码是 ";
for (int i = 0; i<= count; i++) {
cout.put(array2[i]);
}
}
void Create() {
cout<< "请输入需要多少位数的密码\nHow many digits do you want a passcode?"<< endl;
cin >>num1;
if (num1 >0 && num1< MAXN) {
cout<< "1:安全性弱的密码\n1:Weaker passwords\n2:安全性较弱的密码\n2:Strong passwords\n3:安全性强的密码\n3:Passwords with strong security\n其他:退出\nother:ESC"<< endl;
int a;
cin >>a;
if (a >0 && a< 4) {
switch (a) {
case 1:
simple(num1);
break;
case 2:
middle(num1);
break;
case 3:
hard(num1);
break;
default:
break;
}
int y;
cout<< "1:输入加密\nenter to encrypt\n2:把生成的秘钥加密\nEncrypt the generated key"<< endl;
cin >>y;
switch (y) {
case 1:
encrypt1();
break;
case 2:
encrypt2();
break;
default:
break;
}
} else cout<< "输入错误\nInput error"<< endl;
} else cout<< "输入错误\nInput error"<< endl;
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
网站题目:自制C语言密码加密代码-创新互联
文章转载:http://myzitong.com/article/djjpce.html