这几天在准备一个培训,身心俱疲,略有懈怠。。。
每天一题,只能多不能少
RSA-ECC
题目分析
- ECC椭圆曲线方程
- sage求因式
- gcd(p,n) != 1
1.题目
ecn.py
from fastecdsa.point import Point
from Crypto.Util.number import bytes_to_long, isPrime
from os import urandom
from random import getrandbits
from secret import flag, myCurve
def gen_rsa_primes(G):
urand = bytes_to_long(urandom(521//8))
while True:
s = getrandbits(521) ^ urand
Q = s*G
if isPrime(Q.x) and isPrime(Q.y):
print("ECC Private key:", hex(s))
print("RSA primes:", hex(Q.x), hex(Q.y))
print("Modulo:", hex(Q.x * Q.y))
return (Q.x, Q.y)
ecc_p = myCurve.p
a = myCurve.a
b = myCurve.b
Gx = myCurve.gx
Gy = myCurve.gy
G = Point(Gx, Gy, curve=myCurve)
e = 65537
p, q = gen_rsa_primes(G)
n = p * q
m = bytes_to_long(flag)
c = pow(m, e, n)
print 'ECC Curve Prime = %s' % str(ecc_p)
print 'Curve a = %s' % str(a)
print 'Curve b = %s' % str(b)
print 'Gx = %s' % str(Gx)
print 'Gy = %s' % str(Gy)
print 'n = %s' % str(n)
print 'c = %s' % str(c)
# ECC Curve Prime = 6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151
# Curve a = 7
# Curve b = 3337486724173056198539806914083613591148552939440918108176506133639914043582629357942467392691514112323307681909882108412484322514730595838550808273964305469
# Gx = 3439826180868101672186760668868680735915910517718501487265676703411036750054361952397760187383847238746825251488584803812606994058571565033330221427376027071
# Gy = 2288776024351564828297492412066489392882447049893573067242139452176063822294333628193334883272224755588185200613434343466993019050466497692751899685169812177
# n = 130836925797189464646251571878614307843783026920872521446830547061336579168687329377545601761197382071596503015940802370892208678895927660773409759934008499011908437644773874436659983869706278841801493292171611572887778767966515592691660935298340372354876736339396858122737792476111032435537504301742670815931
# c = 854728898282050849139489562985196062627381948504036497804149702242745957233504003606923820531390470224996438518826687593416911196766750309