Exemple #1
0
def send_message(e, N):
    print("Alish wishes to send message x to Bob")
    print("She looks up his public key (N, e) and sends him message"
          " y = x^e mod N")
    x = readinput("message x")
    y = modular_exp(x, e, N)
    return y
Exemple #2
0
def main():
    print("=============== RSA DEMO =================")
    print("Bob chooses his public and secret keys")
    print("He starts by picking 2 n-bit prime numbers 'p' & 'q'")
    p = get_primenum()
    q = get_primenum()
    print("p: %d" % p)
    print("q: %d" % q)
    N = p * q
    x = (p - 1) * (q - 1)
    e = relative_prime(x)
    print("His public key is (N, e) where N = pq and e is relative prime"
          " to (p-1)(q-1)")
    print("(p-1)*(q-1): ", x)
    print("N: ", N)
    print("e: ", e)
    print("His secret key is 'd', inverse of e modulo (p-1)(q-1)")
    d = inverse_modulo(e, x)
    print("Secret key d: ", d)

    y = send_message(e, N)
    print("Encoded mesage Y: ", y)
    print("Finally Bob decodes the message by computing y^d mod N")
    msg = modular_exp(y, d, N)
    print("Decoded message M: ", msg)
Exemple #3
0
def main():
    print ("=============== RSA DEMO =================")
    print ("Bob chooses his public and secret keys")
    print ("He starts by picking 2 n-bit prime numbers 'p' & 'q'")
    p = get_primenum()
    q = get_primenum()
    print ("p: %d" % p)
    print ("q: %d" % q)
    N = p * q
    x = (p-1) * (q-1)
    e = relative_prime(x)
    print("His public key is (N, e) where N = pq and e is relative prime"
          " to (p-1)(q-1)")
    print ("(p-1)*(q-1): ", x)
    print ("N: ", N)
    print ("e: ", e)
    print ("His secret key is 'd', inverse of e modulo (p-1)(q-1)")
    d = inverse_modulo(e, x)
    print ("Secret key d: ", d)

    y = send_message(e, N)
    print ("Encoded mesage Y: ", y)
    print ("Finally Bob decodes the message by computing y^d mod N")
    msg = modular_exp(y, d, N)
    print ("Decoded message M: ", msg)
Exemple #4
0
def send_message(e, N):
    print ("Alish wishes to send message x to Bob")
    print ("She looks up his public key (N, e) and sends him message"
           " y = x^e mod N")
    x = readinput("message x")
    y = modular_exp(x, e, N)
    return y
Exemple #5
0
def isprime(p):
    if p == 1:
        return False
    if p == 2:
        return True
    n = min(p, 100)
    for i in range(n):
        a = random.randint(2, p - 1)
        lhs = modular_exp(a, p - 1, p)
        if lhs != 1:
            return False
    return True
Exemple #6
0
def isprime(p):
    if p == 1:
        return False
    if p == 2:
        return True
    n = min(p, 100)
    for i in range(n):
        a = random.randint(2, p-1)
        lhs = modular_exp(a, p-1, p)
        if lhs != 1:
            return False
    return True
Exemple #7
0
def isprime(p):
    a = random.randint(1, p - 1)
    lhs = modular_exp(a, p - 1, p)
    if lhs == 1:
        return True
    return False
Exemple #8
0
def isprime(p):
    a = random.randint(1, p-1)
    lhs = modular_exp(a, p-1, p)
    if lhs == 1:
        return True
    return False