Взлом Vigenere cipher — различия между версиями
Материал из InformationSecurity WIKI
Drakylar (обсуждение | вклад) м (→python) |
Drakylar (обсуждение | вклад) м (→python) |
||
Строка 7: | Строка 7: | ||
==python== | ==python== | ||
− | < | + | <syntaxhighlight lang="python" line> |
def encryption(plaintext, keyword): | def encryption(plaintext, keyword): | ||
txt_len = len(plaintext) | txt_len = len(plaintext) | ||
Строка 18: | Строка 18: | ||
encoded += chr(newchar + 97) # 97 = ord('a') | encoded += chr(newchar + 97) # 97 = ord('a') | ||
return encoded | return encoded | ||
− | </ | + | </syntaxhighlight> |
==perl== | ==perl== |
Версия 11:58, 1 июня 2016
Содержание
Где часто используется
Скрипты
python
1 def encryption(plaintext, keyword):
2 txt_len = len(plaintext)
3 keyword *= txt_len // len(keyword) + 1
4 keyword = keyword[:txt_len]
5 encoded = ""
6 for c in range(txt_len):
7 newchar = ord(plaintext[c]) + ord(keyword[c]) - 194
8 newchar %= 25
9 encoded += chr(newchar + 97) # 97 = ord('a')
10 return encoded