import base64 import binascii import hashlib import hmac import requests import scrypt import binascii def hex2bin(hex): return binascii.unhexlify(hex) logN = 15 r = 8 p = 1 name = 'name' password = 'password' salt_response = requests.get('https://keybase.io/_/api/1.0/getsalt.json', params={'email_or_username': name}).json() salt = salt_response['salt'] csrf_token = salt_response['csrf_token'] login_session = salt_response['login_session'] start = 192 end = start + 32 pwh = scrypt.hash(password, hex2bin(salt), 1 << logN, r, p, end)[start:end] hmac_pwh = hmac.new(pwh, base64.b64decode(login_session), hashlib.sha512).hexdigest() login_response = requests.post('https://keybase.io/_/api/1.0/login.json', params={'email_or_username': name, 'csrf_token': csrf_token, 'hmac_pwh': hmac_pwh, 'login_session': login_session})