Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sage.all import *
- from Crypto.Util.number import *
- import random
- import time
- random.seed(time.time())
- p = random_prime(2**8 - 1, False, 2**7)
- a, b = random.randint(2, p), random.randint(2, p)
- print(f"p = {p}\na = {a}\nb = {b}")
- F = GF(p)
- elements = []
- for i in range(p):
- Y = F((((b ** 2) * (a ** 2 - i ** 2)) % p * pow(a ** 2, -1, p)) % p)
- if Y.is_square():
- elements.append((i, Mod(Y, p).sqrt()))
- def point_addition(px, py, qx, qy):
- rx = F((pow(a, -1, p) * (px * qx - py * qy * (a ** 2) * (pow(b ** 2, - 1, p)))) % p )
- ry = F((pow(a, -1, p) * (px * qy + py * qx)) % p)
- return (rx, ry)
- def scalar_multiplication(px, py, k):
- rx = a
- ry = 0
- while k:
- if k % 2:
- rx, ry = point_addition(rx, ry, px, py)
- px, py = point_addition(px, py, px, py)
- k >>= 1
- return rx, ry
- print(2 * len(elements) - 2)
- for element in elements:
- print(element, end = " ")
- for i in range(1, 2 * len(elements)):
- if scalar_multiplication(element[0], element[1], i) == (a, 0):
- print(i)
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement