資源描述:
《凱撒加密算法c語言實(shí)現(xiàn)》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、凱撒加密算法C語言實(shí)現(xiàn)#include#includecharencrypt(charch,intn)/*加密函數(shù),把字符向右循環(huán)移位n*/{while(ch>='A'&&ch<='Z'){??return('A'+(ch-'A'+n)%26);}while(ch>='a'&&ch<='z'){??return('a'+(ch-'a'+n)%26);}returnch;}voidmenu()/*菜單,1.加密,2.解密,3.暴力破解,密碼只能是數(shù)字*/{clrscr();printf("=========================
2、======================================================");printf("1.Encryptthefile");printf("2.Decryptthefile");printf("3.Forcedecryptfile");printf("4.Quit");printf("===============================================================================");printf("Pleaseselectaitem:");ret
3、urn;}voidlogo()/*顯示版權(quán)信息*/{printf("ZhensoftEncryption[Version:1.0.0]");printf("Copyright(C)2004ZhensoftCorp.");printf("http://www.zhensoft.com");return;}main(){inti,n;charch0,ch1;FILE*in,*out;charinfile[20],outfile[20];textbackground(BLACK);textcolor(LIGHTGREEN);clrscr();logo();sle
4、ep(3);/*等待3秒*/menu();ch0=getch();while(ch0!='4'){??if(ch0=='1')??{??clrscr();??printf("Pleaseinputtheinfile:");??scanf("%s",infile);/*輸入需要加密的文件名*/??if((in=fopen(infile,"r"))==NULL)??{????printf("Cannotopentheinfile!");????printf("Pressanykeytoexit!");????getch();????exit(0);??}??print
5、f("Pleaseinputthekey:");??scanf("%d",&n);/*輸入加密密碼*/??printf("Pleaseinputtheoutfile:");??scanf("%s",outfile);/*輸入加密后文件的文件名*/??if((out=fopen(outfile,"w"))==NULL)??{????printf("Cannotopentheoutfile!");????printf("Pressanykeytoexit!");????fclose(in);????getch();????exit(0);??}??while(!feof(
6、in))/*加密*/??{????fputc(encrypt(fgetc(in),n),out);??}??printf("Encryptisover!");??fclose(in);??fclose(out);??sleep(1);??}??if(ch0=='2')??{??clrscr();????????????????????printf("Pleaseinputtheinfile:");??scanf("%s",infile);/*輸入需要解密的文件名*/????????????????????????if((in=fopen(infile,"r"))=
7、=NULL)??{????printf("Cannotopentheinfile!");????printf("Pressanykeytoexit!");????getch();????exit(0);??}??printf("Pleaseinputthekey:");??scanf("%d",&n);/*輸入解密密碼(可以為加密時(shí)候的密碼)*/??n=26-n;??printf("Pleaseinputtheoutfile:");??scanf("%s",outfile);/*輸入解密后文件的