fork download
  1. import httplib
  2. import hmac
  3. import hashlib
  4. import time
  5. import sys
  6. import struct
  7. import json
  8.  
  9. root = "http://h...content-available-to-author-only...t.com/challenge/003/endpoint"
  10. content_type = "application/json"
  11. userid = "rishabhaggarwal005@gmail.com"
  12. secret_suffix = "HDECHALLENGE003"
  13. shared_secret = userid+secret_suffix
  14.  
  15. timestep = 30
  16. T0 = 0
  17.  
  18. def HOTP(K, C, digits=10):
  19. K_bytes = str.encode(K)
  20. C_bytes = struct.pack(">Q", C)
  21. hmac_sha512 = hmac.new(key = K_bytes, msg=C_bytes, digestmod=hashlib.sha512).hexdigest()
  22. return Truncate(hmac_sha512)[-digits:]
  23.  
  24. def Truncate(hmac_sha512):
  25. offset = int(hmac_sha512[-1], 16)
  26. binary = int(hmac_sha512[(offset *2):((offset*2)+8)], 16) & 0x7FFFFFFF
  27. return str(binary)
  28.  
  29. def TOTP(K, digits=10, timeref = 0, timestep = 30):
  30. C = int ( time.time() - timeref ) // timestep
  31. return HOTP(K, C, digits = digits)
  32.  
  33. passwd = TOTP(shared_secret, 10, T0, timestep)
  34. passwd = TOTP(shared_secret, 10, T0, timestep).zfill(10)
  35.  
  36. print(passwd)
Success #stdin #stdout 0.08s 69008KB
stdin
Standard input is empty
stdout
1728710766