Help create a single key permutation cipher in Python
I'm just starting to learn python, I really need the help of tc. there is not much information on this topic on the Internet, I would be very grateful
(Key - Pelican)
(Encrypt-TERMINATOR ARRIVES ON THE SEVENTH AT MIDNIGHT)
(Result-GNWEP LTOOA DRNEV TEIO RPOTM BCHMOR SOYI)
0
1 answers
def getCipher(origin_key, origin_text):
clear_text = ''.join(origin_text.split(' ')).lower()
k = len(clear_text) // len(origin_key)
cipher = {}
for index, ch in enumerate(origin_key.lower()):
if ch in cipher:
cipher[ch] += clear_text[index * k : index * k + k]
else:
cipher[ch] = clear_text[index * k : index * k + k]
cipher_text = ''.join([''.join([cipher[key][index] for key in sorted(cipher.keys())]) for index in range(k)])
return ' '.join([cipher_text[index : index + k] for index in range(0, len(cipher_text), k)]).upper()
print(getCipher('ПЕЛИКАН', 'ТЕРМИНАТОР ПРИБЫВАЕТ СЕДЬМОГО В ПОЛНОЧЬ'))
# ГНВЕП ЛТОАА ДРНЕВ ТЕЬИО РПОТМ БЧМОР СОЫЬИ
2
Author: slippyk, 2019-09-10 10:52:58