tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

d2.py (729B)


      1 # Future imports for Python 2.7, mandatory in 3.0
      2 from __future__ import division
      3 from __future__ import print_function
      4 from __future__ import unicode_literals
      5 
      6 q = 2**255 - 19
      7 
      8 def expmod(b,e,m):
      9  if e == 0: return 1
     10  t = expmod(b,e/2,m)**2 % m
     11  if e & 1: t = (t*b) % m
     12  return t
     13 
     14 def inv(x):
     15  return expmod(x,q-2,q)
     16 
     17 def radix255(x):
     18  x = x % q
     19  if x + x > q: x -= q
     20  x = [x,0,0,0,0,0,0,0,0,0]
     21  bits = [26,25,26,25,26,25,26,25,26,25]
     22  for i in range(9):
     23    carry = (x[i] + 2**(bits[i]-1)) / 2**bits[i]
     24    x[i] -= carry * 2**bits[i]
     25    x[i + 1] += carry
     26  result = ""
     27  for i in range(9):
     28    result = result+str(x[i])+","
     29  result = result+str(x[9])
     30  return result
     31 
     32 d = -121665 * inv(121666)
     33 print(radix255(d*2))