I am looking for a way that I can do bitwise operations (for crypto so mostly xor) on hex strings which could possibly be longer than I would want to fit in a Long. As an example I could have a lengthy hex literal I want to xor with other data. Below is an example of what I want to do and how I am doing it now but I believe at some limit the computer will hit it's limit in what it can put in Long so how can I do this more robustly?
#assuming lengths of messages are correct and key length as well
old_hex = "top secret ascii message".encode('hex')
encoded = "09e1c5f70a65ac56e55ac519458e7e53f36" #a literal hex encoded string
key_hex = int(old_hex,16) ^ int(encoded,16) #this currently works because this fits in Long
new_hex = "my new message to send 2".encode('hex')
ans_hex = key_hex ^ int(new_hex,16)
print 'old message in hex: 0x'+old_hex
print 'found a key in hex: '+str(hex(key_hex))
print 'new message in hex: 0x'+new_hex
print 'new message encode: '+str(hex(ans_hex))
So I will want to do XORs on longer strings that this and I am afraid they will not fit in a Long variable so how can I get around this? Do I have to break the string up into smaller chunks and do each part through the operation?
2 ** 4096fits into an int