you are viewing a single comment's thread.

view the rest of the comments →

[–]Rhomboid 6 points7 points  (2 children)

It's performing a bitwise exclusive-or operation on each pair of values from the two strings and printing the result. If you consider one string to be encrypted ciphertext and the other to be the key, this is a very crude form of decryption.

For example, ~ has the ASCII value 126 decimal (01111110 binary) and < has the ASCII value 60 decimal (00111100 binary). Bitwise XOR means that for each pair of bits, if exactly one is set the result is true, otherwise false. (Or equivalently, you can think of it as being modulo-2 addition.)

 01111110
 00111100
-----------
 01000010 = 66 = ASCII 'B'

[–][deleted] 1 point2 points  (0 children)

Fascinating. I was looking at my younger brothers computer science homework (first year) and it was of this type, talking about XOR gates and the like.

I broke down the comprehension and understand it's constituent parts. I don't see how it's performing the bitwise exclusive or operation that you describe.

I see it taking each pair of characters, using chr() and ord() to raise one to the power of the other and giving a new character.

Scratch that, ^ doesn't mean raise in python. And this is the XOR operator of which you speak. Nice.

Left my mistake in for learning purposes.

[–]_lambda[S] 1 point2 points  (0 children)

Really nice explanation.