반응형
import string
def caesor():
a= 'PXEVHFX MH MAX ATVDBGZ PHKEW'
letters = string.ascii_lowercase
for i in range(1, len(letters)+1):
result = ''
for j in a:
#print(i)
tmp = chr(i+ord(j))
if tmp > 'Z':
tmp = chr(ord(tmp) - len(letters))
result += tmp
print(result)
def mono_alphabatic():
enc = 'AKVP RPTSI CKIT UPVT'
key = 'SECRETWORLD'
dic = dict()
count = 97
last = 0
for i in key:
if dic.get(i):
continue
dic[i] = chr(count)
count += 1
last = ord(i)
while len(dic) < 26:
last += 1
if chr(last) > 'Z':
last = last - len(string.ascii_lowercase)
if dic.get(chr(last)):
continue
dic[chr(last)] = chr(count)
count += 1
print(dic)
result = ''
for i in enc:
if i == ' ':
result += ' '
continue
result += dic[i]
print(result)
def vigenere():
enc = 'OMUYXHJWGVEYYZTGXQWGCJ'
key = 'secretisbeautiful'
result = ''
idx = 0
for i in enc:
if idx >= len(key):
idx = 0
tmp = chr(ord(i) - (ord(key[idx]) - ord('a')))
if tmp < 'A':
tmp = chr(ord(tmp) + 26)
idx += 1
result += tmp
print(result)
#caesor()
#mono_alphabatic()
vigenere()
반응형
'Programming$ > Crypto' 카테고리의 다른 글
python3 AES 암복호화 (0) | 2019.10.27 |
---|---|
AES-128 암호화 복호화 C로 짜기 (미완본) (0) | 2018.01.01 |
python으로 vigenere solver 짜기 (0) | 2017.10.16 |