defcontinuedFra(x, y): #计算连分数 #:param x: 分子 #:param y: 分母 #:return: 连分数列表 cf = [] while y: cf.append(x // y) x, y = y, x % y return cf defgradualFra(cf): #计算传入列表最后的渐进分数 #:param cf: 连分数列表 #:return: 该列表最后的渐近分数 numerator = 0 denominator = 1 for x in cf[::-1]: # 这里的渐进分数分子分母要分开 numerator, denominator = denominator, x * denominator + numerator return numerator, denominator
defgetGradualFra(cf): #计算列表所有的渐近分数 #:param cf: 连分数列表 #:return: 该列表所有的渐近分数 gf = [] for i inrange(1, len(cf) + 1): gf.append(gradualFra(cf[:i])) return gf
defwienerAttack(e, n): #:param e: #:param n: #:return: 私钥d cf = continuedFra(e, n) gf = getGradualFra(cf) for d, k in gf: if k == 0: continue ifb'end'in long_to_bytes(d): print(d) print(k) break return (y*d-1)//k
n = 141425071303405369267688583480971314815032581405819618511016190023245950842423565456025578726768996255928405749476366742320062773129810617755239412667111588691998380868379955660483185372558973059599254495581547016729479937763213364591413126146102483671385285672028642742654014426993054793378204517214486744679**4 y = 217574365691698773158073738993996550494156171844278669077189161825491226238745356969468902038533922854535578070710976002278064001201980326028443347187697136216041235312192490502479015081704814370278142850634739391445817028960623318683701439854891399013393469200033510113406165952272497324443526299141544564964545937461632903355647411273477731555390580525472533399606416576667193890128726061970653201509841276177937053500663438053151477018183074107182442711656306515049473061426018576304621373895497210927151796054531814746265988174146635716820986208719319296233956243559891444122410388128465897348458862921336261068868678669349968117097659195490792407141240846445006330031546721426459458395606505793093432806236790060342049066284307119546018491926250151057087562126580602631912562103705681810139118673506298916800665912859765635644796622382867334481599049728329203920912683317422430015635091565073203588723830512169316991557606976424732212785533550238950903858852917097354055547392337744369560947616517041907362337902584102983344969307971888314998036201926257375424706901999793914432814775462333942995267009264203787170147555384279151485485660683109778282239772043598128219664150933315760352868905799949049880756509591090387073778041
solution = calculate_p_q() p = solution[0] q = solution[1] e = 65537 c = 104575090683421063990494118954150936075812576661759942057772865980855195301985579098801745928083817885393369435101522784385677092942324668770336932487623099755265641877712097977929937088259347596039326198580193524065645826424819334664869152049049342316256537440449958526473368110002271943046726966122355888321
d = libnum.invmod(e, (p-1)*(q-1)) m = pow(c, int(d), n)