feat: finish xiaosai

This commit is contained in:
2023-10-15 19:42:16 +08:00
parent 7fe37b52eb
commit c2de294d1c
13 changed files with 571 additions and 0 deletions

14
xiaosai/factor_n/crack.py Normal file
View File

@@ -0,0 +1,14 @@
import gmpy2
from sympy import nextprime
from Crypto.Util.number import *
n = 119089874014927074688341672884508166875005676500322264758691717600758737133958853429775347698400246542956663932584349274109281162512900740554148968627493442686180696496512753102593837838697028745592258709705875168834908314583594102947493349091661801379830005354833653565157987808629144151353148601181998243399
cipher = 117095409962662175082351896808794751507022710425611245694723238077959955609489552866653772250169627679450018400780468195080203740614508425379908667955368095074633690882446901510961333353751345467769557765781287285368700648236247094896521401160296460446518097963846290488354458277094831166588801569124630935182
e = 65537
root = gmpy2.iroot(n,2)[0]
q = nextprime(root)
print(n % q)
p = n // q
phi = (p - 1) * (q - 1)
d = inverse(e, phi)
plaintext = pow(cipher, d, n)
print(long2str(plaintext))

1
xiaosai/factor_n/flag.py Normal file
View File

@@ -0,0 +1 @@
flag = b'flag{You_can_do_this}'

16
xiaosai/factor_n/main.py Normal file
View File

@@ -0,0 +1,16 @@
from flag import flag
from Crypto.Util.number import *
from sympy import nextprime
p = getStrongPrime(512)
q = nextprime(p)
n = p * q
e = 65537
message = bytes_to_long(flag)
cipher = pow(message, e, n)
print('n = ', n)
print('cipher = ', cipher)
'''
n = 119089874014927074688341672884508166875005676500322264758691717600758737133958853429775347698400246542956663932584349274109281162512900740554148968627493442686180696496512753102593837838697028745592258709705875168834908314583594102947493349091661801379830005354833653565157987808629144151353148601181998243399
cipher = 117095409962662175082351896808794751507022710425611245694723238077959955609489552866653772250169627679450018400780468195080203740614508425379908667955368095074633690882446901510961333353751345467769557765781287285368700648236247094896521401160296460446518097963846290488354458277094831166588801569124630935182
'''