Tamamo
Tamamo

Reputation: 93

XOR between Integer and String

I'm trying to build an encryption scheme using Feistel network. My function F output an integer while my original plaintext is, well, String. I'm trying to find a medium (either binary or hex) so that I can convert those values into the same operand type before attempting to xor them together.

So far, I've tried converting my String to binary using something like this:

binary1 = ''.join(format(ord(i), '08b') for i in plaintext)

And converting the integer value into binary with this:

binary2 = bin(integer_value)

I still got errors saying operand types are different - when doing binary1 ^ binary2. Is this possible at all or should I try using something else?

Upvotes: 0

Views: 113

Answers (1)

zeeshan12396
zeeshan12396

Reputation: 412

plaintext = 'hii'
binary1 = ''.join(format(ord(i), '08b') for i in plaintext)
int_val = 34
bin2 = int(bin(int_val)[2:])
binary1 = int(binary1)
print(binary1 ^ bin2)

output:

11010000110100101198691

Upvotes: 1

Related Questions