From 4da8a0067f296ab384d9586e20516aa6fc18422a Mon Sep 17 00:00:00 2001 From: Maxime Vorwerk Date: Mon, 8 Jul 2024 16:53:25 +0200 Subject: [PATCH] miniRSA --- minirsa/ciphertext | 4 ++++ minirsa/sol.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 minirsa/ciphertext create mode 100755 minirsa/sol.py diff --git a/minirsa/ciphertext b/minirsa/ciphertext new file mode 100755 index 0000000..6a8cebe --- /dev/null +++ b/minirsa/ciphertext @@ -0,0 +1,4 @@ +N: 29331922499794985782735976045591164936683059380558950386560160105740343201513369939006307531165922708949619162698623675349030430859547825708994708321803705309459438099340427770580064400911431856656901982789948285309956111848686906152664473350940486507451771223435835260168971210087470894448460745593956840586530527915802541450092946574694809584880896601317519794442862977471129319781313161842056501715040555964011899589002863730868679527184420789010551475067862907739054966183120621407246398518098981106431219207697870293412176440482900183550467375190239898455201170831410460483829448603477361305838743852756938687673 +e: 3 + +ciphertext (c): 2205316413931134031074603746928247799030155221252519872650073010782049179856976080512716237308882294226369300412719995904064931819531456392957957122459640736424089744772221933500860936331459280832211445548332429338572369823704784625368933 diff --git a/minirsa/sol.py b/minirsa/sol.py new file mode 100755 index 0000000..b4c8296 --- /dev/null +++ b/minirsa/sol.py @@ -0,0 +1,31 @@ +#!/home/maxime/.pyvenv/bin/python3 +from math import sqrt + +def iroot(k, n): + u, s = n, n+1 + while u < s: + s = u + t = (k-1) * s + n // pow(s, k-1) + u = t // k + return s + +with open("ciphertext", 'r') as f: + file = f.read().splitlines() + N = int(file[0][2:].strip()) + e = int(file[1][2:].strip()) + c = int(file[3][16:].strip()) + + #sol = 3533 + #''' + for i in range(10000): + c_nomod = c+i*N + p = iroot(e, c_nomod) + if p**3 == c_nomod: + print(i) + break + #''' + #p = iroot(e, c+sol*N) + + result = p.to_bytes((p.bit_length()+7)//8, byteorder='big') + print(result) +