Advertisement
fooker

generator

Dec 13th, 2023
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. from sage.all import *
  2. from Crypto.Util.number import *
  3. import random
  4. import time
  5. random.seed(time.time())
  6.  
  7. p = random_prime(2**8 - 1, False, 2**7)
  8. a, b = random.randint(2, p), random.randint(2, p)
  9.  
  10. print(f"p = {p}\na = {a}\nb = {b}")
  11.  
  12. F = GF(p)
  13. elements = []
  14. for i in range(p):
  15.     Y = F((((b ** 2) * (a ** 2 - i ** 2)) % p * pow(a ** 2, -1, p)) % p)
  16.     if Y.is_square():
  17.         elements.append((i, Mod(Y, p).sqrt()))
  18.    
  19. def point_addition(px, py, qx, qy):
  20.     rx = F((pow(a, -1, p) * (px * qx - py * qy * (a ** 2) * (pow(b ** 2, - 1, p)))) % p )
  21.     ry = F((pow(a, -1, p) * (px * qy + py * qx)) % p)
  22.     return (rx, ry)
  23.  
  24. def scalar_multiplication(px, py, k):
  25.     rx = a
  26.     ry = 0
  27.     while k:
  28.         if k % 2:
  29.             rx, ry = point_addition(rx, ry, px, py)
  30.         px, py = point_addition(px, py, px, py)
  31.         k >>= 1
  32.     return rx, ry
  33.  
  34. print(2 * len(elements) - 2)
  35.  
  36. for element in elements:
  37.     print(element, end = " ")
  38.     for i in range(1, 2 * len(elements)):
  39.         if scalar_multiplication(element[0], element[1], i) == (a, 0):
  40.             print(i)
  41.             break
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement