埃特巴什码(Atbash)
程序员文章站
2022-07-08 20:24:08
...
埃特巴什码
-
加密对象:字母
-
原理
-
最后一个字母代表第一个字母,倒数第二个字母代表第二个字母。
-
对应表:
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 z y x w v u t s r q p o n m l k j i h g f e d c b a
-
-
代码
# write by 2021/7/4 DIC_LOWER = "abcdefghijklmnopqrstuvwxyz" DIC_UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" DIC_LOWER_RE = DIC_LOWER[::-1] DIC_UPPER_RE = DIC_UPPER[::-1] def encrypt_atbash(string): ciphertext = "" for i in string: if i in DIC_LOWER: ciphertext += DIC_LOWER_RE[DIC_LOWER.index(i)] elif i in DIC_UPPER: ciphertext += DIC_UPPER_RE[DIC_UPPER.index(i)] else: ciphertext += i return ciphertext def decrypt_atbash(string): plaintext = "" for i in string: if i in DIC_LOWER_RE: plaintext += DIC_LOWER[DIC_LOWER_RE.index(i)] elif i in DIC_UPPER: plaintext += DIC_UPPER[DIC_UPPER_RE.index(i)] else: plaintext += i return plaintext if __name__ == '__main__': ciphertext_ = encrypt_atbash("HaHa") plaintext_ = decrypt_atbash(ciphertext_) print(f"{plaintext_}: {ciphertext_}")
上一篇: 第十四章 泛型
下一篇: Java文件完整性校验sha256