import libnum from Crypto.Util.number import long_to_bytes
c = 747831491353896780365654517748216624798517769637260742155527 n = 882564595536224140639625987659416029426239230804614613279163 # n = int("",16) e = 65537 # e = int("",16) q = 1029224947942998075080348647219 p = 857504083339712752489993810777
d = libnum.invmod(e, (p - 1) * (q - 1)) m = pow(c, d, n) # m 的十进制形式 string = long_to_bytes(m) # m明文 print(string) # 结果为 b‘ m ’ 的形式 #b'hgame{w0w~yOU_kNoW+R5@!}'
–HappyNewYear!!
这题也考的是 RSA,根据描述可知,有消息相同,然后打开文件发现 e=3,e太小了。
在 Google 上逛了半天,了解了不少 RSA 破解算法,锁定了一个叫低加密指数广播攻击的方法,该方法适用于加密指数e比较低,并且使用了相同的加密指数e给若干个接收者发送相同的信息的情况,适用于本题。
#python2.7 import gmpy import gmpy2 from Crypto.Util.number import long_to_bytes
defboradcast_fuzz(question, e): #广播攻击 N = 1 for i inrange(len(question)): N *= question[i]['n'] N_list = [] for i inrange(len(question)): N_list.append(N / question[i]['n']) t_list = [] for i inrange(len(question)): t_list.append(int(gmpy2.invert(N_list[i], question[i]['n']))) sum = 0 for i inrange(len(question)): sum = (sum + question[i]['c'] * t_list[i] * N_list[i]) % N sum = gmpy.root(sum, e)[0] # return libnum.n2s(sum) return long_to_bytes(sum)
defgetArraySubSet(originArray): #获得子集 result = [[]] for i inrange(len(originArray)): for j inrange(len(result)): result.append(result[j] + [originArray[i]]) return result
for arr in subset: ifnot arr: continue res = boradcast_fuzz(arr, 3) print res print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
运行得到输出
提取一下有用信息:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ I am afraid the dishes in the second grade are too fragrant, you will not reply my text messages, so I won’t give you New Year greetings this year, I hope you don’t know how to praise, good night.
I am afraid that there are too many blessings on the 30th night, you will not see my greetings, I am afraid that the firecrackers in the first grade are too noisy, you will not hear my blessings,