DeCSS 2
Time limit1sMemory limit1024 MB
Given a partially known CSS keystream, find one 42-bit key that reproduces every known byte.
- Level
Medium6 of 10
- Topics
- Brute force, Matrix, Bit manipulation
- Solved
- No attempts yet
Problem
Content Scramble System (CSS) is a method that encrypts content on DVD media so that only licensed devices can access it. In the variant of this system covered here, the key is a bit string 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 a sequence of bytes. Each content byte is then combined with the corresponding keystream byte by bitwise XOR.
If the encrypted text and some content bytes are known, the corresponding keystream bytes can be determined. Your task is to find one possible key based on a 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 a set of feedback positions is defined. In one cycle, an LFSR produces one output bit and updates its state as follows:
- Compute the output bit by XORing the bits at the feedback positions. If the result is even, is 0. Otherwise, is 1.
- Shift all state bits left. Bit is discarded, and is placed in the last position. The new state is .
One step of an LFSR consists of 8 cycles, and its result is one byte. If the output bits of the cycles are in order, the result is the integer between 0 and 255 whose binary form is .
CSS uses two such circuits:
- LFSR17 has 17 bits, with feedback positions 1 and 15. Its initial state is filled in order with key bits through .
- LFSR25 has 25 bits, with feedback positions 1, 4, 5, and 13. Its initial state is filled in order with key bits through .

Figure 1: Keystream generation
The keystream is generated as follows:
- Set LFSR17 and LFSR25 to the initial states determined by the key .
- Set the variable to 0.
- Repeat times:
- Perform one step of LFSR17, and let be its result.
- Perform one step of LFSR25, and let be its result.
- Compute .
- If , subtract 256 from and set to 1. Otherwise, set to 0.
- The next keystream byte is .
A partially known keystream is given, where some bytes are known and some are unknown. Find one possible key that produces a keystream matching the given one when generated in the way described above.
Input
The first line contains a natural number , the length of the given keystream. The second line contains integers , which are the keystream bytes in order. 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 may not be unique.
Hint
The table below shows how the first four keystream bytes of the first example are generated. The first row is the initial state. Every other row is the state right after the given cycle or step ends. In each LFSR, the shaded positions are the feedback positions, and the underlined last bit is the output bit of that cycle.