르그랑 코드북을 참조해서 파일 암호화하기
현재는 전혀 쓰이지 않는 르그랑 코드북을 참조한 암호알고리즘이다.
def makeCodebook(): #르그랑 코드북 참조
decbook ={'5':'a', '2':'b', '#':'d', '8':'e', '1':'f', '3':'g', '4':'h', '6':'i', '0':'l', '9':'m',\
'*':'n', '%':'o', '=':'p', '(':'r', ')':'s', ';':'t', '?':'u','@':'v',':':'y', '7':' '} #복호화 할때 쓰일 코드북
encbook = {} #암호화 할때 쓰일 코드북
for k in decbook: #debcook의 key와 value 값을 바꾸어서 encbook을 만듦
tmp = decbook[k]
encbook[tmp] = k
return encbook, decbook #반환값 순서대로 encbook, decbook
def encrypt(msg, encbook): #암호화 로직
for c in msg:
if c in encbook:
msg = msg.replace(c, encbook[c])
return msg
def decrypt(msg, decbook): #복화화 로직
for c in msg:
if c in decbook:
msg = msg.replace(c, decbook[c])
return msg
def main():
h = open('plain.txt', 'rt') #plain.txt라는 파일을 텍스트 읽기모드로 염
content = h.read()
h.close()
encbook, decbook = makeCodebook()
content = encrypt(content, encbook)
h = open('encryption.txt', 'wt+') #암호화 한것을 encryption.txt 파일에 텍스트 쓰기모드로 염
h.write(content)
h.close()
if __name__ == '__main__':
main()
암호화 전의 평문 텍스트 파일 plain.txt
For seven days and seven nights
Man will watch this awesome sight.
The tides will rise beyond their ken
To bite away the shores and then
A fiery dragon will cross the sky
Six times before this earth shall die
Mankind will tremble and frightened be
for the sixth heralds in this prophecy.
The great star will burn for seven days,
The cloud will cause two suns to appear
The big mastiff will howl all night
When the great pontiff will change country.
암호화 된 텍스트 파일 encryption.txt
F%(7)8@8*7#5:)75*#7)8@8*7*634;)
M5*7w6007w5;c47;46)75w8)%987)634;.
T487;6#8)7w6007(6)8728:%*#7;486(7k8*
T%726;875w5:7;487)4%(8)75*#7;48*
A7168(:7#(53%*7w6007c(%))7;487)k:
S6x7;698)7281%(87;46)785(;47)45007#68
M5*k6*#7w6007;(8920875*#71(634;8*8#728
1%(7;487)6x;4748(50#)76*7;46)7=(%=48c:.
T4873(85;7);5(7w60072?(*71%(7)8@8*7#5:),
T487c0%?#7w6007c5?)87;w%7)?*)7;%75==85(
T487263795);6117w60074%w075007*634;
W48*7;4873(85;7=%*;6117w6007c45*387c%?*;(:.
언어 파이썬(python)3.x
에디터 vscode
출처: 화이트 해커를 위한 암호화 해킹
'암호학' 카테고리의 다른 글
AES 단문메시지 암호화/복호화 코드 with python (0) | 2022.02.16 |
---|---|
3DES로 단문 메시지 암호화하기 with python (0) | 2022.01.31 |
주상 전치 암호 도구 만들기 with python (0) | 2022.01.29 |
카이사르 암호 도구 만들기 with python (0) | 2022.01.27 |
자바로 구현한 S-DES 암호화 알고리즘 (0) | 2022.01.26 |