encryptionxorbitwise-xor

How to Xor cipher_text and and hex value?


How do I use python to Xor cipher-text1 XOR cipher-text2 = "3c0d094c1f523808000d09" and "746865" to get this "48656c"? Thanks

It is based on this https://crypto.stackexchange.com/questions/59/taking-advantage-of-one-time-pad-key-reuse

enter image description here


Solution

  • You can use the ^ bitwise exclusive or operator on each byte:

    >>> a = bytes.fromhex('3c0d094c1f523808000d09')
    >>> b = bytes.fromhex('746865')
    >>> bytes(x ^ y for x, y in zip(a, b)).hex()
    '48656c'