def compute_totp(secret, offset=0):
 assert (type(secret) == six.text_type)
 assert (type(offset) in six.integer_types)
 try:
  key = base64.b32decode(secret)
 except TypeError:
  raise Exception('invalid secret')
 interval = (offset + (int(time.time()) // 30))
 msg = struct.pack('>Q', interval)
 digest = hmac.new(key, msg, hashlib.sha1).digest()
 o = (15 & (digest[19] if six.PY3 else ord(digest[19])))
 token = ((struct.unpack('>I', digest[o:(o + 4)])[0] & 2147483647) % 1000000)
 return u'{0:06d}'.format(token)

def compute_totp ( secret , offset = 0 ) : assert ( type ( secret ) == six . text_type ) assert ( type ( offset ) in six . integer_types ) try : key = base64 . b32decode ( secret ) except TypeError : raise Exception ( 'invalid secret' ) interval = ( offset + ( int ( time . time ( ) ) // 30 ) ) msg = struct . pack ( '>Q' , interval ) digest = hmac . new ( key , msg , hashlib . sha1 ) . digest ( ) o = ( 15 & ( digest [ 19 ] if six . PY3 else ord ( digest [ 19 ] ) ) ) token = ( ( struct . unpack ( '>I' , digest [ o : ( o + 4 ) ] ) [ 0 ] & 2147483647 ) % 1000000 ) return u'{0:06d}' . format ( token )
computes the current totp code .