diff --git a/crypto/mind_your_ps_and_qs/solve.py b/crypto/mind_your_ps_and_qs/solve.py new file mode 100755 index 0000000..3828b9a --- /dev/null +++ b/crypto/mind_your_ps_and_qs/solve.py @@ -0,0 +1,30 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i sage -p sage + +from sage.all import * +import time +import sys + +c = 8533139361076999596208540806559574687666062896040360148742851107661304651861689 +n = 769457290801263793712740792519696786147248001937382943813345728685422050738403253 +e = 65537 + +if len(sys.argv) >= 2 and sys.argv[1] == 'CACHE': + print('Using precalculated p & q') + p = 1617549722683965197900599011412144490161 + q = 475693130177488446807040098678772442581573 +else: + print('Factorizing N') + # Takes about 7-8 minutes on my own pc + start = time.time() + factorization = ZZ(n).factor(algorithm='qsieve') + stop = time.time() + print(f"Took: {stop - start}") + + p, q = [x[0] for x in list(factorization)] + +phi = (p - 1) * (q - 1) +d = inverse_mod(e, phi) +m = power_mod(c, d, n) + +print(m.to_bytes((m.bit_length() + 7) // 8, 'big').decode()) diff --git a/crypto/mind_your_ps_and_qs/values b/crypto/mind_your_ps_and_qs/values new file mode 100644 index 0000000..d6caed9 --- /dev/null +++ b/crypto/mind_your_ps_and_qs/values @@ -0,0 +1,4 @@ +Decrypt my super sick RSA: +c: 8533139361076999596208540806559574687666062896040360148742851107661304651861689 +n: 769457290801263793712740792519696786147248001937382943813345728685422050738403253 +e: 65537