from Crypto.Util.number import long_to_bytes

c = 364812620179131273680130240148084836403846027393384913159162092631491386521136431985815726041640268869899250546875572473450702105133851945618590296616284218872409897353796638895758963083075264218372930102765065661636950920355098372841435042642748593167374414989630427181232399218196685772309403529745406119979371226428026631723070867224675860939203796555567951762311063010081727524747799375832842589314306700599116049075415601108806973017635507910763925927172362 n = 1068394811940475700113916170772008310607904879176073274337669322446687936907143981238893756179197975634434673229920275765973807209412891205884402965483756254507691419368528133959132303476165747992107800736918701005971552264644185146124560027884795936191839406241406301141310602020436434278421529178345240902508007101551941438277539664839258109542374751444222500079818129540895166090788487787028178055561786822480872065405947357363186718845196587434430898650662917 e = 65537 p = 12253096079262730693787845304459770181159272160708761390419517461435886798119494973936186382645490774511179747402693066192362104144553287739427091488849987 q = 9656184899794050073098614505490788837141112476549205418072011388278372195682566976277132351856116300104728124405389485440262266612903835574949734938773879 r = (n // p) // q

求n的欧拉函数

def euler_phi(n): result = n p = 2 while p * p <= n: if n % p == 0: result -= result // p while n % p == 0: n //= p p += 1 if n > 1: result -= result // n return result

count = euler_phi(n)

拓展欧几里得求e的逆元

def extended_gcd(a, b): if b == 0: return a, 1, 0 gcd, x1, y1 = extended_gcd(b, a % b) x = y1 y = x1 - y1 * (a // b) return gcd, x, y

gcdne, x0, d = extended_gcd(count, e)

解密m

m = pow(c, d, n) flag = long_to_bytes(m) secret = flag.decode('utf-8')

print(count) print(gcdne) print(flag) print(secret)

RSA解密算法示例:利用欧拉函数和扩展欧几里得算法

原文地址: http://www.cveoy.top/t/topic/bJ3g 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录