凯撒加密算法c语言实现

凯撒加密算法c语言实现

ID:9843587

大小:32.50 KB

页数:5页

时间:2018-05-12

凯撒加密算法c语言实现_第1页
凯撒加密算法c语言实现_第2页
凯撒加密算法c语言实现_第3页
凯撒加密算法c语言实现_第4页
凯撒加密算法c语言实现_第5页
资源描述:

《凯撒加密算法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);/*输入解密后文件的

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。