def client_session(user, password, salt, A, B, a):
    """
    Client session secret
        Both:  u = H(A, B)

        User:  x = H(s, p)                 (user enters password)
        User:  S = (B - kg^x) ^ (a + ux)   (computes session key)
        User:  K = H(S)
    """
    N, g, k = get_prime()
    u = get_scramble(A, B)
    x = getUserHash(salt, user, password)   # x
    gx = pow(g, x, N)                       # g^x
    kgx = (k * gx) % N                      # kg^x
    diff = (B - kgx) % N                    # B - kg^x
    ux = (u * x) % N
    aux = (a + ux) % N
    session_secret = pow(diff, aux, N)      # (B - kg^x) ^ (a + ux)
    K = hash_digest(hashlib.sha1, session_secret)
    if DEBUG_PRINT:
        print('B=', binascii.b2a_hex(long2bytes(B)), end='\n')
        print('u=', binascii.b2a_hex(long2bytes(u)), end='\n')
        print('x=', binascii.b2a_hex(long2bytes(x)), end='\n')
        print('gx=', binascii.b2a_hex(long2bytes(gx)), end='\n')
        print('kgx=', binascii.b2a_hex(long2bytes(kgx)), end='\n')
        print('diff=', binascii.b2a_hex(long2bytes(diff)), end='\n')
        print('ux=', binascii.b2a_hex(long2bytes(ux)), end='\n')
        print('aux=', binascii.b2a_hex(long2bytes(aux)), end='\n')
        print('session_secret=', binascii.b2a_hex(long2bytes(session_secret)), end='\n')
        print('session_key:K=', binascii.b2a_hex(K))

    return K
def client_session ( user , password , salt , A , B , a ) : N , g , k = get_prime ( ) u = get_scramble ( A , B ) x = getUserHash ( salt , user , password ) gx = pow ( g , x , N ) kgx = ( k * gx ) % N diff = ( B - kgx ) % N ux = ( u * x ) % N aux = ( a + ux ) % N session_secret = pow ( diff , aux , N ) K = hash_digest ( hashlib . sha1 , session_secret ) if DEBUG_PRINT : print ( 'B=' , binascii . b2a_hex ( long2bytes ( B ) ) , end = '\n' ) print ( 'u=' , binascii . b2a_hex ( long2bytes ( u ) ) , end = '\n' ) print ( 'x=' , binascii . b2a_hex ( long2bytes ( x ) ) , end = '\n' ) print ( 'gx=' , binascii . b2a_hex ( long2bytes ( gx ) ) , end = '\n' ) print ( 'kgx=' , binascii . b2a_hex ( long2bytes ( kgx ) ) , end = '\n' ) print ( 'diff=' , binascii . b2a_hex ( long2bytes ( diff ) ) , end = '\n' ) print ( 'ux=' , binascii . b2a_hex ( long2bytes ( ux ) ) , end = '\n' ) print ( 'aux=' , binascii . b2a_hex ( long2bytes ( aux ) ) , end = '\n' ) print ( 'session_secret=' , binascii . b2a_hex ( long2bytes ( session_secret ) ) , end = '\n' ) print ( 'session_key:K=' , binascii . b2a_hex ( K ) ) return K
Client session secret
        Both:  u = H(A, B)

        User:  x = H(s, p)                 (user enters password)
        User:  S = (B - kg^x) ^ (a + ux)   (computes session key)
        User:  K = H(S)