DeCSS 7
Time limit1sMemory limit1024 MB
Given a partly known CSS keystream built from two LFSRs with a carry bit, find any 42-bit key that reproduces the known bytes.
- Level
Hard8 of 10
- Topics
- Bit manipulation, Math, Brute force, Simulation
- Solved
- No attempts yet
Problem
Content Scramble System (CSS) is a method that encrypts the content on DVD media so that only licensed devices can access it. In the variant studied here, the key is a sequence of exactly 42 bits , and the content is a sequence of bytes. The content is encrypted by first generating a keystream from the key. The keystream is also bytes long. Then the bitwise exclusive OR is applied to each content byte and the corresponding keystream byte.
If the ciphertext and some bytes of the content are known, the corresponding keystream bytes can be determined. Your task is to find one possible key based on the partially known keystream .
The keystream function is based on a Linear-feedback shift register (LFSR) circuit. The state of an LFSR consists of bits , and its behavior is defined by a set of feedback positions. In one cycle, the LFSR outputs one bit and updates its state as follows.
- Compute the output bit by summing the bits at the feedback positions. If the sum is even, is 0. Otherwise is 1. In other words, is the XOR of the bits at the feedback positions.
- Shift all state bits one position to the left and discard . Place in the last position. The new state is .
One step of the LFSR consists of 8 cycles. The result is one byte made of the output bits of the cycles, read from right to left. If the output bits of the cycles are in order, the result is the integer from 0 to 255 whose binary representation is .
CSS uses two such circuits.
- LFSR17 has 17 bits. Its feedback positions are 1 and 15. Its initial state is the key bits , in that order.
- LFSR25 has 25 bits. Its feedback positions are 1, 4, 5, and 13. Its initial state is the key bits , in that order.

Figure 1: Keystream generation
The keystream is generated as follows.
- Set LFSR17 and LFSR25 to their initial states using the key , as described above.
- Set to 0.
- Repeat the following times.
- Perform one step of LFSR17 and let be the result.
- Perform one step of LFSR25 and let be the result.
- Compute .
- If , subtract 256 from and set to 1. Otherwise set to 0.
- The next keystream byte is .
You are given a keystream where some bytes are known and others are unknown. Find one key that produces a keystream matching the given bytes in the way described above.
Input
The first line contains the natural number , the length of the keystream. The second line contains integers , the keystream bytes. If the -th byte is unknown, then . If it is known, then .
Output
Print the bits of the key on one line, without spaces.
A solution always exists, but it is not necessarily unique.
Explanation of the first example
The following table shows the details of generating the first four bytes of the keystream. The first row is the initial state. Every other row is the state right after the given cycle or step.