凯撒密码

凯撒是没有密匙的,即使没有密匙也能将它破解出来,因为凯撒移位密码只有25种密匙,最多就是将这25种可能性挨个检测一下可以了,这就是我们所说的暴力破解法。也可在用软件破解,不过我提倡用人工的。

1.原始的凯撒密码:恺撒是一名古代将领,他率先使用这种方法.

凯撒通过把字母移动一定的位数来实现加密和解密。例如,当偏移量是3的时候,所有的字母A将被替换成D,B变成E,以此类推X将变成A,Y变成B,Z变成C。由此可见,位数就是凯撒密码加密和解密的密钥。恺撒密码非常容易被破解,而且在实际应用中也无法保证通信安全。

2.升级版的的凯撒密码即:凯撒密码II

凯撒密码II通过查询动态密码表,把凯撒单词加密成一些密文数字:加密:增加一条凯撒单词string到凯撒密文数字integer的映射规则,如果先前已经有关于这个string的规则,那么用该规则替换原规则。解密:反过来操作即可。

3.凯撒密表:就是把明文中的每一个字母用它在字母表上位置后面的第三个字母代替。这个密表就是英文字母表即:A-Z。

D代a,用E代b,……,用z代w,用A代x(注意!),用B代y,C代z。

实例:

OmniaGalliaest
divisainPartestres
加密后:
RPQLDJDOOLDHVW
GLYLVDLQSDUWHVWUHV
明文即原文 ,密文即原文经加密后得到的内容




转载于:https://www.cnblogs.com/iamjuruo/p/7470963.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
凯撒密码加解密程序(C语言) 2009年09月30日 星期三 13:21 1、程序结构化,用函数分别实现 2、对文件的加密,解密输出到文件 #include #include void menu()/*菜单,1.加密 2.解密 3.退出*/ { clrscr(); printf("\n==============================================================================="); printf("\n1.Encrypt the file"); printf("\n2.Decrypt the file"); printf("\n3.Quit\n"); printf("===============================================================================\n"); printf("Please select a item:"); return; } char encrypt(char ch,int n)/*加密函数,把字符向右循环移位n*/ { while(ch>='A'&&ch='a'&&ch<='z') { return ('a'+(ch-'a'+n)%26); } return ch; } main() { int i,n; char ch0,ch1; FILE *in,*out; char infile[10],outfile[10]; textbackground(RED); textcolor(LIGHTGREEN); clrscr(); menu(); ch0=getch(); while(ch0!='3') { 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(encrypt(fgetc(in),n),out); } printf("\nEncrypt 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); } printf("Please input the key:"); scanf("%d",&n);/*输入解密密码(可以为加密时候的密码)*/ n=26-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(encrypt(fgetc(in),n),out); } printf("\nDecrypt is over!\n"); fclose(in); fclose(out); sleep(1); } clrscr(); printf("\nGood Bye!\n"); sleep(3); getch(); } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值