跪求高手帮我做一个这个C++加密程序的 解密程序
#include<iostream>usingnamespacestd;intmain(){charch[100];inti;cout<<"请输入一句英文:"<<endl...
#include <iostream>
using namespace std;
int main()
{
char ch[100];
int i;
cout<<"请输入一句英文:"<<endl;
cin>>ch;
for(i=0;(ch[i]!='\0')&&(i<100);i++)
{
if(((ch[i]>='a')&&(ch[i]<='w'))||
((ch[i]>='A')&&(ch[i]<='W')))
{
ch[i]+=3;
}
else
{
switch(ch[i])
{
case 'x':ch[i]='a';break;
case 'X':ch[i]='A';break;
case 'y':ch[i]='b';break;
case 'Y':ch[i]='B';break;
case 'z':ch[i]='c';break;
case 'Z':ch[i]='C';break;
default:break;
}
}
}
cout<<"加密后:"<<endl;
for(i=0;(ch[i]!='\0')&&(i<100);i++)
{
cout<<ch[i];
}
cout<<endl;
return 0;
} 展开
using namespace std;
int main()
{
char ch[100];
int i;
cout<<"请输入一句英文:"<<endl;
cin>>ch;
for(i=0;(ch[i]!='\0')&&(i<100);i++)
{
if(((ch[i]>='a')&&(ch[i]<='w'))||
((ch[i]>='A')&&(ch[i]<='W')))
{
ch[i]+=3;
}
else
{
switch(ch[i])
{
case 'x':ch[i]='a';break;
case 'X':ch[i]='A';break;
case 'y':ch[i]='b';break;
case 'Y':ch[i]='B';break;
case 'z':ch[i]='c';break;
case 'Z':ch[i]='C';break;
default:break;
}
}
}
cout<<"加密后:"<<endl;
for(i=0;(ch[i]!='\0')&&(i<100);i++)
{
cout<<ch[i];
}
cout<<endl;
return 0;
} 展开
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const int MAX_N=200;
int main(int argc, char *argv[])
{
int i,j,p;
char text[MAX_N];
char alphabet[30];
char op[10];
while(1)
{
printf("1---输入密码表 2---退出\n");
gets(op);
if(strcmp(op,"1")==0)
{
printf("密码表:");
gets(alphabet);
while(1)
{
printf("1---加密 2---解密 3---返回\n");
gets(op);
if(strcmp(op,"1")==0 ||strcmp(op,"2")==0 )
{
printf("输入文本:");
gets(text);
for(i=0;text[i]!='\0';i++)
{
if((text[i]>='a'&&text[i]<='z') || (text[i]>='A'&&text[i]<='Z') )
{
if(strcmp(op,"1")==0)
{
p=text[i]>='a'? (text[i]-'a'):(text[i]-'A');
text[i]=text[i]+ alphabet[p]-(p+'A');
}
else
{
for(j=0;;j++)
if(alphabet[j]==text[i]||alphabet[j]==(text[i]-('a'-'A')))
break;
text[i]= text[i]>='a' ? (j+'a') :(j+'A');
}
}
}//for(i)
if(strcmp(op,"1")==0)
printf("加密后的文本为:" );
else
printf("解密后的文本为:");
printf("%s\n\n",text);
}
else if(strcmp(op,"3")==0)
{
printf("\n");
break;
}
else
{
printf("选择有误!请重新选择!\n");
}
}//while(1)
}
else if(strcmp(op,"2")==0)
{
exit(1);
}
else
{
printf("选择有误!请重新选择!\n");
}
}
return 0;
}
/*
输入样例
QWERTYUIOPASDFGHJKLZXCVBNM
Welcome to ZZSY2009!
输出样例
Vtsegdt zg MMLN2009!
*/
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-05-24
展开全部
#include <iostream>
using namespace std;
int main()
{
char ch[100];
int i;
cout<<"请输入密文:"<<endl;
cin>>ch;
for(i=0;(ch[i]!='\0')&&(i<100);i++)
{
if(((ch[i]>='d')&&(ch[i]<='z'))||
((ch[i]>='D')&&(ch[i]<='Z')))
{
ch[i]-=3;
}
else
{
switch(ch[i])
{
case 'a':ch[i]='x';break;
case 'A':ch[i]='X';break;
case 'b':ch[i]='y';break;
case 'B':ch[i]='Y';break;
case 'c':ch[i]='z';break;
case 'C':ch[i]='Z';break;
default:break;
}
}
}
cout<<"解密后:"<<endl;
for(i=0;(ch[i]!='\0')&&(i<100);i++)
{
cout<<ch[i];
}
cout<<endl;
return 0;
}
using namespace std;
int main()
{
char ch[100];
int i;
cout<<"请输入密文:"<<endl;
cin>>ch;
for(i=0;(ch[i]!='\0')&&(i<100);i++)
{
if(((ch[i]>='d')&&(ch[i]<='z'))||
((ch[i]>='D')&&(ch[i]<='Z')))
{
ch[i]-=3;
}
else
{
switch(ch[i])
{
case 'a':ch[i]='x';break;
case 'A':ch[i]='X';break;
case 'b':ch[i]='y';break;
case 'B':ch[i]='Y';break;
case 'c':ch[i]='z';break;
case 'C':ch[i]='Z';break;
default:break;
}
}
}
cout<<"解密后:"<<endl;
for(i=0;(ch[i]!='\0')&&(i<100);i++)
{
cout<<ch[i];
}
cout<<endl;
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询