XOR Python Text Encryption / Decryption
Wiem, że istnieje wbudowany operator xor, który można importować w Pythonie. Próbuję wykonać szyfrowanie / deszyfrowanie xor. Do tej pory mam:
def xor_attmpt():
message = raw_input("Enter message to be ciphered: ")
cipher = []
for i in message:
cipher.append(bin(ord(i))[2::])#add the conversion of the letters/characters
#in your message from ascii to binary withoout the 0b in the front to your ciphered message list
cipher = "".join(cipher)
privvyKey = raw_input("Enter the private key: ")
keydecrypt = []
for j in privvyKey:
keydecrypt.append(bin(ord(j))[2::]) #same
keydecrypt = "".join(keydecrypt )#same
print "key is '{0}'" .format(keydecrypt) #substitute values in string
print "encrypted text is '{0}'" .format(cipher)
from operator import xor
for letter in message:
print xor(bool(cipher), bool(keydecrypt))
To:
> for letter in message:
print xor(bool(cipher), bool(keydecrypt))
to gdzie mój python zaczyna się mylić.
Wyjście wygląda tak
Enter message to be ciphered: hello
Enter the private key: \@154>
key is '10111001000000110001110101110100111110'
encrypted text is '11010001100101110110011011001101111'
False
False
False
False
False
To, nad czym się bawię, to próba porównania tych dwóch plików binarnych (kluczowych i zaszyfrowanych) i podania wartości true (1) lub false (wynoszącej 0). Następnie xor powinien dać mi wynikową listę binarną 1 i 0 z porównania tych dwóch. Jakieś dane wejściowe?