#include <stdio.h>
#include <string.h>
int main()
{
char passwd[100];
int i,k;
printf("请输入明文:");
gets(passwd); //输入明文
printf("请输入偏移量:");
scanf("%d",&k); //输入偏移量
for(i=0; i<strlen(passwd); i++) // 循环让明文中的每个字母加上偏移量
{
if (passwd[i]>='A'&& passwd[i]<='Z')
passwd[i]+=32;//将含有大写的字母转换成小写
passwd[i] = ((passwd[i]-'a')+k)%26+'a'; //防越界
passwd[i]-=32; //转换为大写输出
}
printf("%s",passwd);
printf("\n");
getchar();
getchar();
return 0;
}
Last modification:December 11th, 2019 at 11:15 pm
© The copyright belongs to the author