단일 치환 암호는 알파벳을 일대일 대응하여 암호를 만드는 알고리즘이다.
단점은 암호문과 평문에서 문자의 빈도가 동일하다는 것이다.
예를들어 A->C , B->D 로 치환된 AABBABA의 암호문은 CCDDCDC이다.
빈도분석으로 추측 해독이 가능하다. 그래서 암호화만 만들었다.
##mono_sub_cipher
from random import shuffle
def Encryption(plain_text):
substitution = list(range(65,91))
shuffle (substitution)
plain_text = plain_text.upper()
cipher_text = []
for i in plain_text:
cipher_text.append(chr(substitution[ord(i)-65]))
print(''.join(cipher_text))
while 1:
Encryption(plain_text = input("Text : "))
stop = input("Again? y/n : ")
if stop == 'y': continue
elif stop == 'n':
print("Exit")
break
else :
print("Error")
break
'Programming > Python' 카테고리의 다른 글
[Python] web scraping (0) | 2020.09.25 |
---|---|
[Python] 단일 치환 암호 (0) | 2020.04.25 |
[Python] Ceasar cipher (0) | 2020.04.25 |