凯撒密码 程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------wk.baidu.com-----------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
return ('0'+(ch-'0'+n)%10); } return ch; } char JFjiemi(char ch,int n) { static int k; while(ch>='A'&&ch<='Z') { k=n%26; n=26-k;
return ('A'+(ch-'A'+n)%26); } while(ch>='a'&&ch<='z') { k=n%26;
2.CFljiami the file");
printf("\n
3.JFjiemi the file");
printf("\n
4.CFjiemi the file");
printf("\n
5.Quit\n");
printf("=========================================================\n");
printf("Please input a number rang from 1 to 5 and select a item:");
return;
}
void main() { int i,n; char ch0,ch1; FILE *in,*out; char infile[20],outfile[20]; sleep(3); menu(); ch0=getch(); while(ch0!='5') {
n=26-k; return ('a'+(ch-'a'+n)%26); } while(ch>='0'&&ch<='9') { k=n%10; n=10-k;
return ('0'+(ch-'0'+n)%10); } return ch; } char CFjiami(char ch,int n) { if(n%2==0) n=n%10+1;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
h=((ch-'a')+i*26)/n; if(h>=0&&h<=26)
return ('a'+h); } } while(ch>='0'&&ch<='9') { for(i=0;i<n;i++) { k=((ch-'0')+i*10)%n; if(k==0) h=((ch-'0')+i*10)/n; if(h>=0&&h<=9)
return ('0'+h); } } return ch; } void menu() {
printf("\n=========================================================");
printf("\n
1.JFjiami the file");
printf("\n
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if(ch0=='1') {
clrscr(); printf("\nPlease input the infile:"); scanf("%s",infile); if((in=fopen(infile,"r"))==NULL) {
printf("Can not open the infile!\n"); printf("Press any key to exit!\n"); getch(); exit(0); } printf("Please input the key:"); scanf("%d",&n); printf("Please input the outfile:"); scanf("%s",outfile); if((out=fopen(outfile,"w"))==NULL) { printf("Can not open the outfile!\n"); printf("Press any key to exit!\n"); fclose(in); getch(); exit(0); } while(!feof(in)) { fputc(JFjiami(fgetc(in),n),out); } printf("\nJFjiami is over!\n"); fclose(in); fclose(out); sleep(1); } if(ch0=='2') { clrscr(); printf("\nPlease input the infile:"); scanf("%s",infile); if((in=fopen(infile,"r"))==NULL) { printf("Can not open the infile!\n"); printf("Press any key to exit!\n"); getch(); exit(0);
#include<stdio.h> #include<conio.h> char JFjiami(char ch,int n) { while(ch>='A'&&ch<='Z') {
n=n%26; return ('A'+(ch-'A'+n)%26); } while(ch>='a'&&ch<='z') { n=n%26; return ('a'+(ch-'a'+n)%26); } while(ch>='0'&&ch<='9') { n=n%10;
else n=n%10; if(n%5==0) n=n+2; else n=n; while(ch>='A'&&ch<='Z') {
return ('A'+((ch-'A')*n)%26); } while(ch>='a'&&ch<='z') {
return ('a'+((ch-'a')*n)%26); } while(ch>='0'&&ch<='9') {
return ('0'+((ch-'0')*n)%10); } return ch; } char CFjiemi(char ch,int n) { int i; int k,h; if(n%2==0) n=n%10+1; else n=n%10; if(n%5==0) n=n+2; else n=n; while(ch>='A'&&ch<='Z') {
for(i=0;i<100;i++) {
k=((ch-'A')+i*26)%n; if(k==0) h=((ch-'A')+i*26)/n; if(h>=0&&h<=26)
return ('A'+h); } } while(ch>='a'&&ch<='z') {
for(i=0;i<n;i++) {
k=((ch-'a')+i*26)%n; if(k==0)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
相关文档
最新文档