Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. computeLog: g base: h modulo: p
  2. "DiscreteLogarithm problem1"
  3. "compute the discrete logarithm of g to the base b"
  4.     | lookup lhs rhs B result ginv |
  5.  
  6.     B := 2 raisedTo: 20.
  7.     ginv := g raisedTo: (p - 2) modulo: p.
  8.     lookup := Dictionary new.
  9.     "1. First build a dictionary of all the possible values of the left hand size of the equation h/g^x_1"
  10.     0 to: B do: [:x1 |
  11.         lhs := (h * (ginv raisedTo: x1 modulo: p)) \\ p.
  12.         lookup at: lhs put: x1].
  13.  
  14.     "2. Then, for each value x_0 = 0, 1, 2, ..., 2^20 check if the right hand side (g^B)^x_0 is in the hash table"
  15.     result := 0 to: B do: [:x0 |
  16.         rhs := (g raisedTo: B modulo: p) raisedTo: x0 modulo: p.
  17.         lookup at: rhs ifPresent: [:x1 | ^x0 * B + x1]].
  18.  
  19.     ^result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement