凯撒密码
在密码学中,恺撒密码(英语:Caesar cipher),或称恺撒加密、恺撒变换、变换加密,是一种最简单且最广为人知的加密技术。它是一种替换加密的技术,明文中的所有字母都在字母表上向后(或向前)按照一个固定数目进行偏移后被替换成密文。例如,当偏移量是3的时候,所有的字母A将被替换成D,B变成E,以此类推。这个加密方法是以罗马共和时期恺撒的名字命名的,当年恺撒曾用此方法与其将军们进行联系。
加密公式:En(x) = (x + n) mod 26
解密公式:Dn(x) = (x - n) mod 26
栅栏密码
所谓栅栏密码,就是把要加密的明文分成N个一组,然后把每组的第1个字连起来,形成一段无规律的话。 不过栅栏密码本身有一个潜规则,就是组成栅栏的字母一般不会太多。(一般不超过30个,也就是一、两句话)
一般比较常见的是2栏的栅栏密码。
- ①:比如明文:THERE IS A CIPHER
- ②:去掉空格后变为:THEREISACIPHER
- ③:两个一组,得到:TH ER EI SA CI PH ER
- ④:先取出第一个字母:TEESCPE
- ⑤:再取出第二个字母:HRIAIHR
- ⑥:连在一起就是:TEESCPEHRIAIHR
复合加密
结合凯撒加密和栅栏加密等多种加密方式,实现复合加密,得到更加安全的加密方式。