Skip to content

Instantly share code, notes, and snippets.

@mothdotmonster
Created June 7, 2023 04:30
Show Gist options
  • Save mothdotmonster/6ac9d8d022ac1a6d6aabc9c1c7abbb75 to your computer and use it in GitHub Desktop.
Save mothdotmonster/6ac9d8d022ac1a6d6aabc9c1c7abbb75 to your computer and use it in GitHub Desktop.
turn a zip file into a prime number
import sympy as sp
fileName = "file.zip"
with open(fileName, 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)
@mothdotmonster
Copy link
Author

this is very slow, don't use it on anything more than a couple bytes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment