欢迎来到天天文库
浏览记录
ID:9843587
大小:32.50 KB
页数:5页
时间:2018-05-12
《凯撒加密算法c语言实现》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、凯撒加密算法C语言实现#include#includecharencrypt(charch,intn)/*加密函数,把字符向右循环移位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.暴力破解,密码只能是数字*/{clrscr();printf("=========================
2、======================================================");printf("1.Encryptthefile");printf("2.Decryptthefile");printf("3.Forcedecryptfile");printf("4.Quit");printf("===============================================================================");printf("Pleaseselectaitem:");ret
3、urn;}voidlogo()/*显示版权信息*/{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);/*输入解密密码(可以为加密时候的密码)*/ n=26-n; printf("Pleaseinputtheoutfile:"); scanf("%s",outfile);/*输入解密后文件的
此文档下载收益归作者所有