Взлом Vigenere cipher
Материал из InformationSecurity WIKI
Содержание
Где часто используется
Скрипты
python
encrypt
def encryption(plaintext, keyword):
txt_len = len(plaintext)
keyword *= txt_len // len(keyword) + 1
keyword = keyword[:txt_len]
encoded = ""
for c in range(txt_len):
newchar = ord(plaintext[c]) + ord(keyword[c]) - 194
newchar %= 25
encoded += chr(newchar + 97)
return encoded
decrypt
def decrypt(key, ciphertext):
from itertools import cycle
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
pairs = zip(ciphertext, cycle(key))
result = ''
for pair in pairs:
total = reduce(lambda x, y: ALPHA.index(x) - ALPHA.index(y), pair)
result += ALPHA[total % 26]
return result