Advertisement
Guest User

Untitled

a guest
Apr 5th, 2017
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | None | 0 0
  1. #! /usr/bin/env sage
  2.  
  3. # Constants
  4.  
  5. M = 93556643250795678718734474880013829509320385402690660619699653921022012489089
  6. A = 66001598144012865876674115570268990806314506711104521036747533612798434904785
  7.  
  8. P = (56027910981442853390816693056740903416379421186644480759538594137486160388926, 65533262933617146434438829354623658858649726233622196512439589744498050226926)
  9. nP = (30399321663277778915789435918669378136486628773979001534946407690195669208748, 1973041983573227486868025872751342101679089524467602053850914626437554196117)
  10.  
  11. b = 400000000000000000000000000000
  12.  
  13. # Compute B with basic modular arithmetic
  14. B = (P[1]**2 - P[0]**3 - A*P[0]) % M
  15.  
  16. # Define curve and points
  17. F = GF(M)
  18. E = EllipticCurve(F, [A,B])
  19.  
  20. base = E(P)
  21. res = E(nP)
  22.  
  23. # Step is the amount that every increment of this subgroup's
  24. # scalar will increase the overall scalar by
  25. step = 1
  26. # Start is the residue under the modulus step of the final
  27. # scalar value
  28. start = 0
  29.  
  30. for p, k in factor(E.order()):
  31.     # Pohlig-Hellman over this factor
  32.     f = p ** k
  33.     nbase = base * (E.order() // f)
  34.     nres = res * (E.order() // f)
  35.     # Find whether it is faster to compute using the given
  36.     # bound and our start point and step or from the order
  37.     # of the subgroup as the bounds
  38.     if b // (step - start) < f:
  39.         bounds = (start, start + b // (step - start))
  40.     else:
  41.         bounds = (0, f)
  42.     # Find this subgroup's discrete log using those bounds
  43.     r = bsgs(nbase, nres, bounds, operation='+')
  44.     # Change start to include start % f == r
  45.     start = crt(start, r, step, f)
  46.     # Because all factors are mutually coprime, we can just
  47.     # multiply the step to get the step for the next subgroup
  48.     step *= f
  49.  
  50. # Once we've iterated through all of the factors, step == E.order()
  51. # and so the residue (start) is the solution to the problem
  52. print(start)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement