Знам, че има вграден оператор xor, който може да бъде импортиран в Python. Опитвам се да изпълня xor криптиране/декриптиране. Досега имам:
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))
Това:
> for letter in message:
print xor(bool(cipher), bool(keydecrypt))
е мястото, където моят питон започва да се обърква.
The ouput looks like this
Enter message to be ciphered: hello
Enter the private key: \@154>
key is '10111001000000110001110101110100111110'
encrypted text is '11010001100101110110011011001101111'
False
False
False
False
False
Това, което бъркам, е да се опитам да накарам тези две двоични (ключови и криптирани) да бъдат сравнени и да дадат true(1) или false (което е 0). След това xor трябва да ми даде получен двоичен списък с 1 и 0 от сравняването на двете. Някакви данни?