程序和身体一样,健壮,再健壮! 我爱C++
#include<stdio.h> #include<string.h>
//int key(int p) int key() { int p; printf("please input the key: \n") ; scanf("%d",&p); while(!(p>=1&&p<=25)) { printf("Error,please input again:"); scanf("%d",&p); } return p; }
char encrypt(int t,int k,char ch[]) { int i; for(i=0;i<t;i++){ if(ch[i]>='a'&&ch[i]<='z') ch[i]=(ch[i]-'a'+k)%26+'A'; if(ch[i]>='A'&&ch[i]<='Z') ch[i]=(ch[i]-'A'+k)%26+'A'; else ; }
} main() { int k,n,t=1000; char ch[t],s[t]; printf("please input the plaintext: \n"); //scanf("%s",ch); gets(ch); n=strlen(ch); k=key(); //i=?好象没初值 encrypt(n,k,ch); printf("The ciphertext is:\n \t\t\t"); printf("%s\n",ch); getchar(); getchar();
}