Beispiel #1
0
def giant_step(alpha, p, fname):
    m = grpsize(p)
    fid = open(fname, 'w')
    for giant in range(m):
        exponentation = primes_template.square_multiply(alpha, m * giant, p)
        fid.write(str(exponentation) + ',' + str(giant) + '\n')
    fid.close()
Beispiel #2
0
def baby_step(alpha, beta, p, fname):
    m = grpsize(p)
    fid = open(fname, 'w')
    for baby in range(m):
        exponentation = (primes_template.square_multiply(alpha, baby, p) *
                         beta) % p
        fid.write(str(exponentation) + ',' + str(baby) + '\n')
    fid.close()
def giant_step(alpha,p,fname='giant_step.txt'):
    g = p - 1
    m = math.floor(math.sqrt(g))
    giant_step_result = {}
    for xg in range(m):
        result = primes_template.square_multiply(alpha, xg * m, p)
        # result = pow(alpha, xg * m, p)# alpha ** (xg * m)
        giant_step_result[xg] = result
    return giant_step_result
def baby_step(alpha, beta, p, fname):
    m = ceil(sqrt(p - 1))
    with open(fname, 'w') as fptr:
        for i in range(m):
            res = (primes_template.square_multiply(alpha, i, p) * beta) % p
            if i == m - 1:
                fptr.write(str(res))
            else:
                fptr.write(str(res))
                fptr.write('\n')
def giant_step(alpha, p, fname):
    m = ceil(sqrt(p - 1))
    with open(fname, 'w') as fptr:
        for i in range(m):
            res = primes_template.square_multiply(alpha, m * i, p)
            if i == m - 1:
                fptr.write(str(res))
            else:
                fptr.write(str(res))
                fptr.write('\n')
def giant_step(alpha,p,fname='giant_step.txt'):
    g = p - 1
    m = math.floor(math.sqrt(g))
    giant_step_result = {}
    with open(fname, 'w') as fout:
        for xg in range(m):
            result = primes_template.square_multiply(alpha, xg * m, p)
            # result = pow(alpha, xg * m, p)# alpha ** (xg * m)
            fout.write(str(result) + '\n')
            giant_step_result[xg] = result
    return giant_step_result
Beispiel #7
0
def get_shared_key(keypub, keypriv, p):
    return primes_template.square_multiply(keypub, keypriv,
                                           p)  # (keypub ** keypriv) % p
Beispiel #8
0
def get_pub_key(alpha, a, p):
    return primes_template.square_multiply(alpha, a, p)  # (alpha ** a ) % p
Beispiel #9
0
    for right in rdict.keys():
        if right in ldict.keys():
            output = (ldict[right] * m - rdict[right]) % p
            return output


"""
# of bits the key needs to avoid attack = 30 bits
"""

if __name__ == "__main__":
    """
    test 1
    My private key is:  264
    Test other private key is:  7265
    
    """
    p = 17851
    alpha = 17511
    A = 2945
    B = 11844
    sharedkey = 1671
    a = baby_giant(alpha, A, p)
    b = baby_giant(alpha, B, p)
    guesskey1 = primes_template.square_multiply(A, b, p)
    guesskey2 = primes_template.square_multiply(B, a, p)
    print('Guess key 1:', guesskey1)
    print('Guess key 2:', guesskey2)
    print('Actual shared key :', sharedkey)
# Glenn Chia 1003118
# Year 2019

import math
import primes_template


def baby_step(alpha,beta,p,fname='baby_step.txt'):
    # Find the group order G
    g = p - 1 # since All elements of the eld except 0 form a multiplicative group with the group operation ×
    # Calculate m
    m = math.floor(math.sqrt(g))
    baby_step_result = {}
    with open(fname, 'w') as fout:
        for xb in range(m):
            result = (primes_template.square_multiply(alpha, xb, p) * beta)%p
            # result = (pow(alpha, xb, p) * beta)%p
            fout.write(str(result) + '\n')
            baby_step_result[xb] = result
    return baby_step_result


def giant_step(alpha,p,fname='giant_step.txt'):
    g = p - 1
    m = math.floor(math.sqrt(g))
    giant_step_result = {}
    with open(fname, 'w') as fout:
        for xg in range(m):
            result = primes_template.square_multiply(alpha, xg * m, p)
            # result = pow(alpha, xg * m, p)# alpha ** (xg * m)
            fout.write(str(result) + '\n')
    return a

def get_pub_key(alpha, a, p):
    return primes_template.square_multiply(alpha, a, p) # (alpha ** a ) % p

def get_shared_key(keypub,keypriv,p):
    return primes_template.square_multiply(keypub, keypriv, p) # (keypub ** keypriv) % p

def baby_step(alpha,beta,p,fname='baby_step.txt'):
    # Find the group order G
    g = p - 1 # since All elements of the eld except 0 form a multiplicative group with the group operation ×
    # Calculate m
    m = math.floor(math.sqrt(g))
    baby_step_result = {}
    for xb in range(m):
        result = (primes_template.square_multiply(alpha, xb, p) * beta)%p
        # result = (pow(alpha, xb, p) * beta)%p
        baby_step_result[xb] = result
    return baby_step_result


def giant_step(alpha,p,fname='giant_step.txt'):
    g = p - 1
    m = math.floor(math.sqrt(g))
    giant_step_result = {}
    for xg in range(m):
        result = primes_template.square_multiply(alpha, xg * m, p)
        # result = pow(alpha, xg * m, p)# alpha ** (xg * m)
        giant_step_result[xg] = result
    return giant_step_result
def get_shared_key(keypub,keypriv,p):
    shared = primes_template.square_multiply(keypub, keypriv, p)
    return shared
def get_pub_key(alpha, a, p):
    pk = primes_template.square_multiply(alpha,a,p)
    return pk