题目原型:
1 from flag import FLAG 2 from Cryptodome.Util.number import * 3 import gmpy2 4 import random 5 6 e=65537 7 p = getPrime(512) 8 q = int(gmpy2.next_prime(p)) 9 n = p*q 10 m = bytes_to_long(FLAG) 11 c = pow(m,e,n) 12 print(n) 13 print(c)
可从output.txt里查看到n与c的值
既然已知n为多少,使用yafu分解,打开cmd输入yafu-x64.exe启动yafu,可以得到p和q
可以计算得出明文m,但根据题目中的“bytes_to_long”,直接得出flag
1 #from flag import FLAG 2 from Crypto.Util.number import long_to_bytes 3 import gmpy2 4 import random 5 6 e=65537 7 #p = getPrime(512) 8 #q = int(gmpy2.next_prime(p)) 9 #n = p*q 10 #m = bytes_to_long(FLAG) 11 #c = pow(m,e,n) 12 #print(n) 13 #print(c) 14 n=177606504836499246970959030226871608885969321778211051080524634084516973331441644993898029573612290095853069264036530459253652875586267946877831055147546910227100566496658148381834683037366134553848011903251252726474047661274223137727688689535823533046778793131902143444408735610821167838717488859902242863683 15 c=1457390378511382354771000540945361168984775052693073641682375071407490851289703070905749525830483035988737117653971428424612332020925926617395558868160380601912498299922825914229510166957910451841730028919883807634489834128830801407228447221775264711349928156290102782374379406719292116047581560530382210049 16 p=13326909050357447643526585836833969378078147057723054701432842192988717649385731430095055622303549577233495793715580004801634268505725255565021519817179293 17 q=13326909050357447643526585836833969378078147057723054701432842192988717649385731430095055622303549577233495793715580004801634268505725255565021519817179231 18 L=(q-1)*(p-1) 19 phi=gmpy2.invert(e,L) 20 m=gmpy2.powmod(c,phi,n) 21 print(long_to_bytes(m))
最后得到flag
flag{p_and_q_should_not_be_so_close_in_value}
标签:BUUCTF,gmpy2,bytes,crypto,long,flag,2020,print,import From: https://www.cnblogs.com/lgyj/p/16884946.html