# 已知公私钥 p = 9648423029010515676590551740010426534945737639235739800643989352039852507298491399561035009163427050370107570733633350911691280297777160200625281665378483 q = 11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407 e = 65537 c = 6376842280869728581726746401583705899941768214138742259689334840735633553053887641847651173776251820293087212885670180367406807406765923638973161375817392737747832762751690104423869019034
# c = input('请输入密文') n = p * q phi_n = (p - 1) * (q - 1) # 对n取欧拉函数,p,q均为素数 d = gmpy2.invert(e, phi_n) # 即e*d mod phi_n = 1 (求逆元) m = gmpy2.powmod(c, d, n) # 即m = c^d mod n (求大整数c的d次幂模n取余) # print(m) # 求得的明文 flag = str(hex(m))[2:] # print(flag) print(binascii.unhexlify(flag).decode()) # print(binascii.unhexlify(flag))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
import gmpy2
# 如果已知公私钥 p = 9648423029010515676590551740010426534945737639235739800643989352039852507298491399561035009163427050370107570733633350911691280297777160200625281665378483 q = 11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407 e = 65537 m = 123456
# c = input('请输入明文') n = p * q phi_n = (p - 1) * (q - 1) # 对n取欧拉函数,p,q均为素数 d = gmpy2.invert(e, phi_n) # 即e*d mod phi_n = 1 (求逆元) c = gmpy2.powmod(m, e, n) # 即c = m^e mod n (求大整数m的e次幂模n取余) print(c) # 求得的密文