Code Monkey home page Code Monkey logo

garena-authenticator's Introduction

Garena-Authenticator

This program implements same OTP algorithm with Garena.

Algorithm

Actually it's RFC-6238. Algorith descripted below:

Input key is 16chars base-32 encoded string.

# 1. decode the key
raw_key = base32.decode(key)
# 2. compute time interval (`time` is integer)
time = epoch_seconds() / 180
# 3. encode time interval as 8bytes big-endian
time_bytes = int64_to_bigendian(time)
# 4. compute HMAC-SHA1 hash value, raw_out is bytes
raw_out = hmac_sha1(time_bytes, sign_key=raw_key)
# 5. take last byte
last_byte = raw_out[19]
# 6. compute index
index = last_byte % 16
# 7. take 4bytes sub-sequance from raw_out,
sequance = subbytes(raw_out, index, 4) # take 4bytes from raw_out
# 8. decode as big-endian integer and remove highest bit
number = bigendian_to_int32(sequance) & 0x7fffffff
# 9. compute OTP code
otp_code = padding_zero(number % 1000000, 6)

Python alternative

import time
import pyotp # pip install pyotp

h = pyotp.HOTP('KKKKKKKKKKKKKKKK')
otp = h.at(int(time.time() / 180))
print(otp)

TODO

  • Extract code from Android App
  • Python version

garena-authenticator's People

Contributors

inndy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

garena-authenticator's Issues

How to

How to use it ? What should i fill in the form ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.