Search code examples
cencryptioncryptographyhexxor

XOR 2 52 bytes msgs in C or other program?


I have two 52 bytes hexadecimals (they are ciphertexts but that doesn't matter). How can I XOR those two in C (or any other programming language)?

unsigned long long won't support the 52 bytes message.

c1 = 837f68797e691a10020c3e6e75100c7009651a1d6561060c6d0b6f046116450c031e1c001c09130a001b0163016569637a626f22;

c2 = 7e6f7c6f79001d0018017270148016770e720b1d656f06690e117900150c671f0e020d6917680a0b721c6e0a0b006f676b636693;

I want c1^c2 somehow. How to do it?


Solution

  • Let A = A0A1A2...AN and B = B0B1B2...BN 2 arrays of N bytes.
    Cool thing about the XOR (noted ^) is that you have the following equality:

    A ^ B = (A0 ^ B0) (A1 ^ B1) (A2 ^ B2) ... (AN ^ BN)
    

    So provided C1 and C2 are 2 arrays of 52 bytes you just have to:

    char xor[52];
    for(size_t i=0; i<52; i++)
    {
        xor[i] = c1[i] ^ c2[i];
    }