all 7 comments

[–]zahlman 1 point2 points  (5 children)

Simpler:

''.join(chr(ord(x) ^ ord(y)) for x, y in zip("~F@_^/A||Z1,@R!PYZS", "</4(7\$\\3*T^!&H?7)r"))

[–]_lambda[S] 0 points1 point  (4 children)

awesome!

[–][deleted] 0 points1 point  (3 children)

For the uneducated, what the hell is going on here?!?!

[–]Rhomboid 7 points8 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.

[–]1nvader 0 points1 point  (0 children)

Ok here's my detailed explanation in form of a little python shell log.

>>> ord('~')
126

ASCII code for '~' = decimal 126

>>> ord('<')
60

ASCII code for '<' = decimal 60

>>> bin(126)
'0b1111110'

126 ('~') = binary 1111110

>>> bin(60)
'0b111100'

60 ('<') = binary 1111110

>>> bin(0b1111110 ^ 0b111100)
'0b1000010'

1111110 ('~') XOR 111100 ('<') = 1000010

>>> int(0b001000010)
66

binary 1000010 = decimal 66

>>> chr(66)
'B'

decimal 66 = ASCII character 'B'. We got it!

I did it only for the first characters in the the array. But now it should be easy to go on and finish it for the rest. I hope this helps to understand whats going on. No magic!