Skip to content

Caesar cipher · ⁨凯撒密码⁩

English

Caesar cipher

The Roman historian Suetonius wrote that Julius Caesar hid his messages by shifting each letter three places along the alphabet.

alphabet.index(ch) gives a letter's position, from 0 for a to 25 for z. Add the shift and use % 26, so that position 26 wraps back to 0. To decode a message, shift it again by 26 minus the original shift.

中文

凯撒密码

罗马历史学家苏埃托尼乌斯记载,尤利乌斯·凯撒把每个字母在字母表中后移三位来隐藏信息。

alphabet.index(ch) 给出字母的位置:a 是 0,z 是 25。加上移动的位数,再用 % 26,让位置 26 回到 0。要解密,就用 26 减去原来的位数,再移动一次。

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩