# 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_}")