编程介的小学生 2017-02-23 12:59 采纳率: 20.5%
浏览 759
已采纳

Leaky Cryptography

The ACM ICPC judges are very careful about not leaking their problems, and all communi- cations are encrypted. However, one does sometimes make mistakes, like using too weak an encryption scheme. Here is an example of that.

The encryption chosen was very simple: encrypt each chunk of the input by flipping some bits according to a shared key. To provide reasonable security, the size of both chunk and key is 32 bits.

That is, suppose the input was a sequence of m 32-bit integers.

N1 N2 N3 ... Nm

After encoding with the key K it becomes the following sequence of m 32-bit integers.

(N1 ^ K) (N2 ^ K) (N3 ^ K) ... (Nm ^ K)

where (a ^ b) is the bitwise exclusive or of a and b.

Exclusive or is the logical operator which is 1 when only one of its operands is 1, and 0 otherwise. Here is its definition for 1-bit integers.

As you can see, it is identical to addition modulo 2. For two 32-bit integers a and b, their bitwise exclusive or a ^ b is defined as follows, using their binary representations, composed of 0's and 1's.

a ^ b = a31 ... a1a0 ^ b31 ... b1b0 = c31 ... c1c0

where

For instance, using binary notation, 11010110 ^ 01010101 = 10100011, or using hexadecimal, d6 ^ 55 = a3.

Since this kind of encryption is notoriously weak to statistical attacks, the message has to be compressed in advance, so that it has no statistical regularity. We suppose that N1 N2 ... Nm is already in compressed form.

However, the trouble is that the compression algorithm itself introduces some form of regularity: after every 8 integers of compressed data, it inserts a checksum, the sum of these integers. That is, in the above input, N9 = N1 + N2 + ... + N8, where additions are modulo 2^32.

Luckily, you could intercept a communication between the judges. Maybe it contains a problem for the finals!

As you are very clever, you have certainly seen that you can easily find the lowest bit of the key, denoted by K0. On the one hand, if K0 = 1, then after encoding, the lowest bit of N1^K + N2^K + ... + N8^K is unchanged, as K0 is added an even number of times, but the lowest bit of N9^K is changed, so they shall differ. On the other hand, if K0 = 0, then after encoding, the lowest bit of N1^K + N2^K + ... + N8^K shall still be identical to the lowest bit of N9^K, as they do not change. For instance, if the lowest bits after encoding are 1 1 1 1 1 1 1 1 1 then K0 must be 1, but if they are 1 1 1 1 1 1 1 0 1 then K0 must be 0.

So far, so good. Can you do better?

You should find the key used for encoding.

Input

The input starts with a line containing only a positive integer S, indicating the number of datasets in the input. S is no more than 1000.

It is followed by S datasets. Each dataset is composed of nine 32-bit integers corresponding to the first nine chunks of a communication. They are written in hexadecimal notation, using digits 0' to9' and lowercase letters a' tof', and with no leading zeros. They are separated by a space or a newline. Each dataset is ended by a newline.

Output

For each dataset you should output the key used for encoding. Each key shall appear alone on its line, and be written in hexadecimal notation, using digits 0' to9' and lowercase letters a' tof', and with no leading zeros.

Sample Input

8
1 1 1 1 1 1 1 1 8
3 2 3 2 3 2 3 2 6
3 4 4 7 7 b a 2 2e
e1 13 ce 28 ca 6 ab 46 a6d
b08 49e2 6128 f27 8cf2 bc50 7380 7fe1 723b
4eba eb4 a352 fd14 6ac1 eed1 dd06 bb83 392bc
ef593c08 847e522f 74c02b9c 26f3a4e1 e2720a01 6fe66007
7a4e96ad 6ee5cef6 3853cd88
60202fb8 757d6d66 9c3a9525 fbcd7983 82b9571c ddc54bab 853e52da
22047c88 e5524401
8
Sample Output

0
2
6
1c6
4924afc7
ffff95c5
546991d
901c4a16

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-03-02 23:58
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?