Advertisement
bmtd

A fine OTP server

Apr 9th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. def gen_otps():
  2.     template_phrase = 'Welcome, dear customer, the secret passphrase for today is: '
  3.    
  4.     OTP_1 = template_phrase + gen_passphrase(18)
  5.     OTP_2 = template_phrase + gen_passphrase(18)
  6.  
  7.     otp_1 = bytes_to_long(OTP_1)
  8.     otp_2 = bytes_to_long(OTP_2)
  9.  
  10.     nbit, e = 2048, 3
  11.     privkey = RSA.generate(nbit, e = e)
  12.     pubkey  = privkey.publickey().exportKey()
  13.     n = getattr(privkey.key, 'n')
  14.    
  15.     r = otp_2 - otp_1
  16.     if r < 0:
  17.         r = -r
  18.     IMP = n - r**(e**2)
  19.     if IMP > 0:
  20.         c_1 = pow(otp_1, e, n)
  21.         c_2 = pow(otp_2, e, n)
  22.     return pubkey, OTP_1[-18:], OTP_2[-18:], c_1, c_2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement