Quick actions

cmd+k|ctrl+k

Navigation

Languages

シーザー復号

Snippet info

Language

Python

Visibility

public

Author

a9n1105

Created

2023-09-07T02:31:44.088882Z

Updated

2023-09-07T02:31:44.088882Z

import string

def decryption(encryption, key: int):
    uppercase = string.ascii_uppercase
    lowercase = string.ascii_lowercase
    decrypt = ""
    for c in encryption:
        if c in uppercase:
            index = (uppercase.index(c) - key) % 26
            decrypt += uppercase[index]
        if c in lowercase:
            index = (lowercase.index(c) - key) % 26
            decrypt += lowercase[index]
        if (c not in uppercase) and (c not in lowercase):
            decrypt += c
    return decrypt
    

a_str = "pb qdph lv Jdlxv Lxolxv Fdhvdu."
print(decryption(a_str, 3))
INFO