#P6962. [NEERC 2017] Knapsack Cryptosystem

[NEERC 2017] Knapsack Cryptosystem

题目描述

The Merkle-Hellman Knapsack Cryptosystem was one of the earliest public key cryptosystems invented by Ralph Merkle and Martin Hellman in 19781978 . Here is its description

Alice chooses nn positive integers a1,...,an{a_{1}, . . . , a_{n}} such that each ai>∑j=1i−1aj,a_{i} > \sum^{i−1}_{j=1}a_{j}, a positive integer qq which is greater than the sum of all ai,a_{i}, and a positive integer rr which is coprime with qq . These n+2n + 2 integers are Alice's private key.

Then Alice calculates bi=(ai⋅r)b_i = (a_{i} · r) mod qq . These nn integers are Alice's public key.

Knowing her public key, Bob can transmit a message of nn bits to Alice. To do that he calculates ss , the sum of bib_{i} with indices ii such that his message has bit 11 in i-th position. This value ss is the encrypted message.

Note that an eavesdropper Eve, who knows the encrypted message and the public key, has to solve a (presumably hard) instance of the knapsack problem to find the original message. Meanwhile, after receiving ss , Alice can calculate the original message in linear time; we leave it to you as an exercise.

In this problem you deal with the implementation of the Merkle-Hellman Knapsack Cryptosystem in which Alice chose q=264,q = 2^{64}, for obvious performance reasons, and published this information. Since everyone knows her qq , she asks Bob to send her the calculated value ss taken modulo 2642^{64} for simplicity of communication.

You are to break this implementation. Given the public key and an encrypted message, restore the original message.

输入格式

The first line contains one integer n(1≤n≤64)n (1 \le n \le 64) .

Each of the next nn lines contains one integer bi(1≤bi<264).b_{i} (1 \le b_{i} < 2^{64}).

The last line contains one integer ss mod qq -- the encrypted message ss taken modulo q(0≤sq (0 \le s mod q<264).q < 2^{64}).

The given sequence bib_{i} is a valid public key in the described implementation, and the given value ss mod qq is a valid encrypted message.

输出格式

Output exactly nn bits (00 or 11 digits) -- the original message.

5
10
20
50
140
420
440

01001

提示

Time limit: 3 s, Memory limit: 512 MB.