0
안녕하세요,이 스크립트에 문제가 있습니다. 이 스크립트는 기본적으로 입력을 요구하고 사용자가 입력 한 내용을 암호화 한 다음 사용자는 다시 돌아가 암호화 된 메시지를 입력하여 메시지의 암호를 해독 할 수 있습니다. 스크립트의 암호화 부분은 잘 작동하지만, 문제를 일으키는 해독 부분 일뿐입니다. 여기에 사전에 코드 감사 당연히입니다 : D파이썬에서 암호화 알고리즘을 반대로 교환
def encrypt(key, msg):
encryped = []
for i, c in enumerate(msg):
key_c = ord(key[i % len(key)])
msg_c = ord(c)
encryped.append(chr((msg_c + key_c) % 127))
return ''.join(encryped)
def decrypt(key, encryped):
msg2 = []
for i, c in enumerate(encryped):
key_c = ord(key[i % len(key)])
enc_c = ord(c)
msg.append(chr((enc_c - key_c) % 127))
return ''.join(msg)
welcome = str(input("Press 1 to encrypt or anything else to decrypt: "))
if welcome in ['1', '1']:
var = input("Please type in what you want to encrypt: ")
if __name__ == '__main__':
key = 'This is the key'
msg = var
encrypted = encrypt(key, msg)
decrypted = decrypt(key, encrypted)
print ('Please take down the key and encryption message to decrypt this message at a later stage')
print ('This is what you want to encrypt:' , repr(msg))
print ('This is the encryption/decryption key:', repr(key))
print ('This is the encrypted message:', repr(encrypted))
else:
var2 = input("Please enter your encrypted message that you would like to decrypt: ")
if __name__ == '__main__':
key = 'This is the key'
msg = var2
decrypted = decrypt(key, var2)
print ('This is the decrypted message:', repr(decrypted))
암호화 된 메시지의 예를 들려 줄 수 있습니까? – RageCage
암호화 된 경우 'Hello World'가 다음과 같이 표시됩니다. "\ x1dNV'O \ nkO'fD" – AbdulNaji