- #1
- 2,168
- 193
For fun, I have decided to implement a simple XOR encryption algorithm. The first step is to convert messages into bytes to perform XOR operation on each bit. The problem has started here. For instance, I want to encrypt this message.
Now I need to turn this text into binary. It seems that there are two different ways to do it for '24';
a) Take 2 and 4 as separate and as integers, so this means
or
[00000010, 00000100]
b) take 2 and 4 as strings, so by doing something like this
or
[00110010, 00110100]
Does this makes a difference in the perspective of XOR encryption (or in general) ? What is the correct approach ?
Code:
I hiked 24 miles.
Now I need to turn this text into binary. It seems that there are two different ways to do it for '24';
a) Take 2 and 4 as separate and as integers, so this means
Code:
>>> bin(2)
'0b10'
>>> bin(4)
'0b100'
[00000010, 00000100]
b) take 2 and 4 as strings, so by doing something like this
Code:
>>> bin(ord('2'))
'0b110010'
>>> bin(ord('4'))
'0b110100'
[00110010, 00110100]
Does this makes a difference in the perspective of XOR encryption (or in general) ? What is the correct approach ?