Decoding Task

Interview

Time limit2sMemory limit128 MB

Summary
Given an encrypted message and the same message with a space prepended, recover the shared XOR key bytes.
Level

Medium4 of 10

Topics
Bit manipulation, Implementation
Solved
No attempts yet

Problem

In the near future, all research and publication about cryptography is outlawed worldwide on national-security grounds: if cryptographic literature were public, anyone (including criminals) could hide their plans from the authorities. As a result, public cryptographic systems no longer exist, and everyone who needs strong protection for their secrets must invent a proprietary algorithm.

The ACM Corporation has many competitors eager to learn its trade secrets. Protecting those secrets is hard because ACM must use intercontinental communication lines that are easy to eavesdrop on, unlike its well-guarded internal lines. To defend itself, ACM invented the Intercontinental Cryptographic Protection Code (ICPC), which it considers unbreakable — until now.

A group of hackers, hired by an unnamed rival, set out to break ICPC. They first bribed one of ICPC's programmers and learned how it works. ICPC uses a very long key: a sequence of bytes produced by a sophisticated random physical process. The key is changed every week and encrypts every message sent over the intercontinental lines during that week. ICPC is extremely fast because it simply computes a bitwise exclusive OR (XOR) between the message bytes and the key. That is, the ii-th byte of the encrypted message is Ei=Ki⊕CiE_i = K_i \oplus C_i, where KiK_i is the ii-th byte of the key and CiC_i is the ii-th byte of the original clear-text message.

The hackers now need a reliable way to obtain the weekly key. They found a clerk who sends weekly newsletters to employees just after each key change; a newsletter is long enough that studying it together with its encrypted form would reveal a large part of the key. But no employee would leak a newsletter, because a Non-Disclosure Agreement makes the penalty for disclosure death.

Instead, they convinced the clerk (for a small reward) to do something seemingly innocent: when copying the newsletter to the corporation, he inserts one extra space character at the beginning of some copies while sending other copies unchanged.

Now recovering the key is straightforward — and that is your job. You are given two ICPC-encrypted messages. The first message is NN bytes long. The second message is N+1N + 1 bytes long and is the encryption of the same clear text as the first, but with one extra space character (the byte with decimal value 3232) inserted at the beginning. Find the first N+1N + 1 bytes of the key that was used to encrypt the messages.

Input

The input consists of two lines.

  • The first line contains 2N2N characters and represents the first encrypted message, which is NN bytes long.
  • The second line contains 2N+22N + 2 characters and represents the second encrypted message, which is N+1N + 1 bytes long.

Here 1≤N≤100001 \le N \le 10000. Each message is written on a single line in hexadecimal, byte by byte and without spaces. Each byte is written as two characters from 0-9 and A-F giving the hexadecimal value of that byte.

Output

Print a single line containing the recovered N+1N + 1 bytes of the key, in the same hexadecimal format as the input (two uppercase hexadecimal characters per byte, no spaces).

Examples2

  1. Example 1

    Input
    05262C5269143F314C2A69651A264B
    610728413B63072C52222169720B425E
    
    Expected output
    41434D2049435043204E454552432732
    
  2. Example 2

    Input
    51
    3061
    
    Expected output
    1020