예제 #1
0
def encrypt(text, key):
    random.seed(key)
    table = list(alphabet)
    random.shuffle(table)
    ciphertext = ''
    for c in text:
        i = alphabet.index(c)
        ciphertext += table[i]
    return ciphertext
예제 #2
0
def encrypt(text, key):
    ciphertext = ''
    for c in text:
        i = alphabet.index(c)
        ciphertext += alphabet[(i + key) % len(alphabet)]
    return ciphertext
예제 #3
0
def decrypt(text, key):
    plaintext = ''
    for c in text:
        i = alphabet.index(c)
        plaintext += alphabet[i - key]
    return plaintext