making an illegal prime number


have you ever heard about illegal numbers?

you see, some computer data is illegal. the obvious example is copyright infringement; any data which was obtained by infringing copyright is illegal to have. this makes sense in theory… but because all computer data is just numbers, it means that illegal computer data is a number that happens to be illegal to know.

a related concept is an illegal prime number. if you somehow encode illegal data into a prime number, that prime number becomes illegal. but that has to be hard, right?

well, not really.

many file formats contain headers that have all the important information about the file. and some file formats have a header that says how big the file is. any extra data added to the end will simply be ignored, since it's not truly supposed to be a part of the file. the ZIP format happens to do this, which is convenient, since it's supported on just about every platform and can contain any files you like.

because of this, you can encode any data you'd like as a prime number. simply ZIP it up, and then shove bytes on the end until it turns into a prime number!1

the reason i went on this adventure was because of the controversy surrounding Dolphin's use of the Wii's common key2 in their code. i though it would be fun to encode it as a prime number. here's what that number is, by the way:

print(int.from_bytes(rvl-common-key-prime.zip))

1468621646726059024187572720978892916737801949913272997302104621188465310821785748663071150027361486639634905192523715455180771194891515370892921776637847415588342651523888430241363866439606515422933888716415142910947210664305503950514949753986226086085037902674555174754898923021290674960499257087617106576125340443581801333548786608204952261740531604604479827259318441349036112185830043308536945178503746072483803905112347611909989804284957206770765744420773494818393950874399579481723213716276089645865224335418677237442074774321068628988919831
					

pretty neat, huh? you can download it as a zip file here if you'd like to check for yourself. and if you're curious how i generated it, here's the Python code I wrote:

generate-prime.py
import sympy as sp

with open("file.zip", mode="rb") as file:
	fileContents = bytearray(file.read())
	fileContents.append(255)
	while not sp.isprime(int.from_bytes(fileContents)):
		if (int.from_bytes(fileContents[-1:]) != 0):
			print("bruteforcing " + str(int.from_bytes(fileContents[-1:])))
			fileContents[-1:] = [int.from_bytes(fileContents[-1:]) - 1]
		else:
			print("appending")
			fileContents.append(255)
	print("prime detected")
	print(int.from_bytes(fileContents))
	with open("file-prime.zip", "wb") as outFile:
		outFile.write(fileContents)

1. there are probably better ways to do this, but i am not good at math, and brute-forcing works well enough for small files.

2. all Wii games are encrypted using a common key, which is shared by all consoles. one could reasonably just decrypt the games while ripping them to avoid this problem entirely, but for some reason Dolphin never did this.