Exemple #1
0
def generate_p_and_q():
    p = methods.getPrime(BITLENGTH_PRIME)
    q = methods.getPrime(BITLENGTH_PRIME)

    while methods.log2(p*q) % 2 == 0: #if n is even, generate new p and q
        if RSA.log: print("bitLength of N ({}) was not odd".format(methods.log2(p*q)))
        p = methods.getPrime(BITLENGTH_PRIME)
        q = methods.getPrime(BITLENGTH_PRIME)

    return p, q
Exemple #2
0
    bitlength = input("What bit size do P and Q need to be? (fill in the bitsize (>= 16 bits), or blank for the standard {})"
                               .format(BITLENGTH_PRIME))

    if not bitlength == "":             #check if input is not empty (then we use default bitlength
        if(int (bitlength) >= 16):      #check if bitlength is over 16 bits
            BITLENGTH_PRIME = bitlength

    start = startBase = time.clock()    #start the timing

    p, q = generate_p_and_q()           #generate P and Q (these we not given earlier)

    print("This took {} seconds".format(time.clock() - start))
    print("P = {}".format(p))
    print("q = {}".format(q))
    print("bit-size modulo N : {}".format(methods.log2(p*q)))
    print("------------------------")

start = time.clock()

message = 88357295638463824038562958736483910039478

messageInput = input("Which message do you want to encrypt and decrypt? (leave blank for the bonus excersise text ({}))"
                     .format(message))

if not messageInput == "":
    message = int (messageInput)

print("Message to encrypt and decrypt = {}".format(message))
print("------------------------")
print("Now we are going to setup the RSA instance")