In October 1999, a group led by the then 16-year-old Norwegian Jon Lech Johansen released the DeCSS program to circumvent the Content Scramble System (CSS) DVD playback protection. CSS used 40-bit encryption, the keys to which were distributed to licensed manufacturers, to restrict DVD playback. Because the distribution of the code fell under the US DMCA and was legally prohibited, activists sought ways to disguise the code as a mathematical entity.
Phil Carmody then constructed a prime number which, when interpreted in binary after gzip decompression, contains the complete source code of DeCSS. The core of the DeCSS algorithm can be implemented in TypeScript as follows, where the bit operations directly map the sector decryption logic.:
function CSSdescramble(sec: Uint8Array, key: Uint8Array): void {
let t1: number, t2: number, t3: number, t4: number, t5: number, t6: number;
const end = 0x800;
t1 = (key[0] ^ sec[0x54]) | 0x100;
t2 = key[1] ^ sec[0x55];
const keyView = new DataView(key.buffer, key.byteOffset);
const secView = new DataView(sec.buffer, sec.byteOffset);
t3 = (keyView.getUint32(2, true) ^ secView.getUint32(0x56, true)) >>> 0;
t4 = t3 & 7;
t3 = (t3 * 2 + 8 - t4) >>> 0;
let offset = 0x80;
t5 = 0;
while (offset < end) {
t4 = CSStab2[t2] ^ CSStab3[t1];
t2 = t1 >>> 1;
t1 = ((t1 & 1) << 8) ^ t4;
t4 = CSStab5[t4];
t6 = (((((((t3 >>> 3) ^ t3) >>> 1) ^ t3) >>> 8) ^ t3) >>> 5) & 0xff;
t3 = (((t3 << 8) >>> 0) | t6) >>> 0;
t6 = CSStab4[t6];
t5 += t6 + t4;
sec[offset] = CSStab1[sec[offset]] ^ (t5 & 0xff);
t5 >>>= 8;
offset++;
}
}
The principle behind the prime number is to interpret the entire source code as a single, solid integer. Since no given file is ever a prime number, the number is artificially augmented with additional bytes (padding). This padding is incremented in a loop until a primality test, such as the Miller-Rabin test, confirms the number is prime. The following generator uses the DeCSS code described above and searches for a corresponding prime number representation.:
import { isPrime } from 'crypto-utils-lib'; // Hypothetical library for primality testing
async function generateIllegalPrime(code: string): Promise<bigint | null> {
const encoder = new TextEncoder();
const bytes = encoder.encode(code);
let hexBase = Array.from(bytes)
.map(b => b.toString(16).padStart(2, '0'))
.join('');
// Start bei 1, da 0x00 immer gerade und damit keine Primzahl ist
for (let i = 1; i < 256; i++) {
const candidateHex = hexBase + i.toString(16).padStart(2, '0');
const candidateInt = BigInt('0x' + candidateHex);
if (await isPrime(candidateInt)) {
return candidateInt;
}
}
return null;
}
const source = `void CSSdescramble(unsigned char *sec, unsigned char *key) { ... }`;
generateIllegalPrime(source).then(p => console.log(p));
The prime number trick was never the subject of a separate court case, nor did it need to be. Although Carmody's original prime number had 1401 digits, it was too small for the top lists of the largest prime numbers at the time. He later created a 1905-digit version, artificially inflated with null bytes, to achieve tenth place in the ECPP ranking . This success demonstrated the impossibility of censoring pure mathematics, as the number earned its place on the list solely on the basis of its mathematical properties.