privatekey = rsa.PrivateKey(n,e,d,p,q) with open("encrypted.message1","rb") as f: print(rsa.decrypt(f.read(),privatekey).decode())
with open("encrypted.message2","rb") as f: print(rsa.decrypt(f.read(),privatekey).decode())
with open("encrypted.message3","rb") as f: print(rsa.decrypt(f.read(),privatekey).decode())
2017第二届广东省强网杯线上赛-SimpleMath
题目源码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
from Crypto.Util.number import * from hashlib import md5
flag = "xxx" assert len(flag) == 15 pad = bytes_to_long(md5(flag).digest())
hack = 0
for char in flag: hack *= ord(char) hack += pad print hack # hack = 280098481791453837177137197730537158171743673148935867304957882116 # flag = "flag{" + flag + "}"
defresult1(arr):#获得每一个组合结果中数字的相乘结果 source = 1 for i in arr: source *= i return source
deff2(a,b,s,n): if a//b-1in range(32, 127): s = s+chr(a//b-1) if len(s)==14: checkMD5(s[::-1],n) for c in range(32,127): if (a//b-1)%c==0: f2(a//b-1,c,s+chr(c),n)
defcheckMD5(s,n): for c in range(32,127): t= chr(c)+s if int.from_bytes(md5(t.encode('utf-8')).digest(),byteorder='big')==n: print(t)
for i in range(1,12): for j in list(itertools.combinations(dic,i)):#将这些数字进行组合 tmp = result1(j) if tmp.bit_length() in range(120,129): f2(hack,tmp,'',tmp)