凯撒加密解密
#includevoid main() { char M[100]; char C[100]; int p; printf("请选择0:加密,1:解密\n"); scanf("%d",&p); printf("请输入明文M(注意不要输入空白串)\n"); scanf("%s",M); int i,K; printf("请输入密钥K(注意不要输入空白串)\n"); scanf("%d",&K); if(p==0) { for(i=0;M[i]!='\0';i++) if(M[i]>='a'&&M[i]<='z') C[i]=(M[i]-'a'+K)%26+'a'; else if(M[i]>='A'&&M[i]<='z') C[i]=(M[i]-'A'+K)%26+'A'; C[i]='\0'; } else if(p==1) { for(i=0;M[i]!='\0';i++) if(M[i]>='a'&&M[i]<='z') C[i]=(M[i]-'a'-K)%26+'a'; else if(M[i]>='A'&&M[i]<='z') C[i]=(M[i]-'A'-K)%26+'A'; C[i]='\0'; } printf("The Ciphrtext is:\n%s\n",C); }
分享标题:凯撒加密解密
标题链接:http://scyanting.com/article/gocgjg.html