文件移位加密与解密题目分析与总结
1个回答
2010-01-06
展开全部
#include<stdio.h>
#include<stdlib.h>
#define M 200
void change(char *mi,char *yuan,int password)
{
int i=0;
while(mi[i]!='\0')
{
if(mi[i]>='a' && mi[i]<='z')
yuan[i]=(mi[i] - 'a' + password + 26) % 26 +'a';
else
yuan[i]=(mi[i] - 'A' + password + 26) % 26 +'A';
i++;
}
yuan[i]='\0';
}
int main()
{
char mi[M],yuan[M];
int password;
int choose;
while(1)
{
printf("*****************************\n");
printf("**1:加密***2:解密***3:退出***\n");
printf("*****************************\n");
scanf("%d",&choose);
if(choose==3)
break;
printf("input text:\n");
scanf("%s",mi);
printf("input password:\n");
scanf("%d",&password);
if(choose==2)
password=-password;
change(mi,yuan,password);
printf("%s\n",yuan);
system("pause");
}
return(0);
}
#include<stdlib.h>
#define M 200
void change(char *mi,char *yuan,int password)
{
int i=0;
while(mi[i]!='\0')
{
if(mi[i]>='a' && mi[i]<='z')
yuan[i]=(mi[i] - 'a' + password + 26) % 26 +'a';
else
yuan[i]=(mi[i] - 'A' + password + 26) % 26 +'A';
i++;
}
yuan[i]='\0';
}
int main()
{
char mi[M],yuan[M];
int password;
int choose;
while(1)
{
printf("*****************************\n");
printf("**1:加密***2:解密***3:退出***\n");
printf("*****************************\n");
scanf("%d",&choose);
if(choose==3)
break;
printf("input text:\n");
scanf("%s",mi);
printf("input password:\n");
scanf("%d",&password);
if(choose==2)
password=-password;
change(mi,yuan,password);
printf("%s\n",yuan);
system("pause");
}
return(0);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询