凯撒算法是一种根据字母与字母之间的替换来破解凯撒密码的算法。
基本介绍
- 中文名:凯撒算法
- 分类:算法
- 原理:字母与字母之间的替换
- 作用:确保信息传递的安全
使用方法
凯撒密码是一种非常古老的加密方法,相传当年凯撒大帝行军打仗时为了保证自己的命令不被敌军知道,就使用这种特殊的方法进行通信,以确保信息传递的安全。
原理
它的原理是字母与字母之间的替换。例如26个字母都向后移动K位。若K等于2,则A用C代替,B用D代替,以此类推
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z A B
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
特性
算法比较简单,很容易实现,但是作为加密算法,特别容易被破解
实现
C语言算法如下
# include<stdio.h>
main()
int key;
char mingma,mima;
printf("\n Please input the character:");
getch();
scanf("%c",&mingma);
printf("\n Please input the key:");
getch();
scanf("%d",&key);
if((mingma>='A')&&(mingma<='Z'))
mima='A'+(mingma-'A'+key)%26;
if((mingma>='a')&&(mingma<='z'))
mima='a'+(mingma-'a'+key)%26;
printf("\n The output is:%c",mima);
getch();