ssoL2 TISTORY

[암호와 해킹] first_encrptor.py 본문

sec/crypto

[암호와 해킹] first_encrptor.py

ssoL2 2020. 12. 27. 17:39

CodeBook 에 대해 변환, CodeBook에 존재하지 않는 단어는 그대로 노출

{'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':' '}

 

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 = dict()

 

for x,y in decBook.items() :

encBook[y] = x

 

return encBook, decBook

 

def encoding(msg, encBook) :

for i in msg :

if i in encBook :

msg = msg.replace(i, encBook[i])

return msg

 

def decoding(msg, decBook) :

for i in msg :

if i in decBook :

msg = msg.replace(i, decBook[i])

return msg



#main

 

if __name__ == '__main__' :

plainText = input()

 

encBook, decBook = makeCodebook()

 

cipherText = encoding(plainText, encBook)

print(cipherText)

 

decipherText = decoding(cipherText, decBook)

print(decipherText)

 

I love you with my heart 문구에 대한 암호화 및 복호화

Comments