Ejemplo n.º 1
0
def keygen():

    print("Generating keys, this could take a while...")
    clef = randrange(0, 2**tailleClef)

    while not rabinMiller.isPrime(clef):
        clef = randrange(2, 2**tailleClef)

    #write the first part of the public key into a file
    file = open(nomClef[0], 'w')
    file.write(str(clef))
    file.close()

    #write the second part of the public key into another file
    generator = calcGene(clef)
    file = open(nomClef[1], 'w')
    file.write(str(generator))
    file.close()

    #randomly generate the secret key, it must be <clefQ
    secret = randrange(1, clef)
    file = open(nomClef[2], 'w')
    file.write(str(secret))
    file.close()

    #calculate the third part of the public key and write it into a fourth file
    file = open(nomClef[3], 'w')
    file.write(str((generator**secret) % clef))
    file.close()
Ejemplo n.º 2
0
def prime_factorization(number):
    table = []
    i = 2
    while i != 1 and number >= i:
        if rabinMiller.isPrime(i) and number % i == 0:
            table.append(i)
            number = number / i
        else:
            i += 1
    return table
Ejemplo n.º 3
0
def attacker(cipherText, publicKey):
    # First, init clock

    # extract c from cipherText

    for factor in range(2, publicKey[0] // 2):  # try to systematically factor n
        if publicKey[0] % factor == 0 and rabinMiller.isPrime(factor):
        # if n is divisible by the factor
        # check if the factor is prime
        # find all possible RSA-key/sets using this factorization
            phi = (factor - 1) * ((publicKey[0] // factor) - 1)

            possible = publicKey[1]
            otherKey = rsahelp.findModInverse(possible, phi)
            return otherKey

    return None
Ejemplo n.º 4
0
#!/usr/local/bin/python3.4

import rabinMiller

num = 2000000
prime_sum = 0

for i in range(1, num + 1):
    if rabinMiller.isPrime(i):
        prime_sum += i

print(prime_sum)
Ejemplo n.º 5
0
#!/usr/local/bin/python3.4

import rabinMiller

num = 10001

primes = []
i = 1

while True:
    if rabinMiller.isPrime(i) == True:
        primes.append(i)
        if len(primes) == num:
            break

    i += 1

print(primes[num - 1])
Ejemplo n.º 6
0
def prime_decomposition(num):
    for n in range(2, int(math.sqrt(num))):
        if num % n == 0 and rabinMiller.isPrime(n) ==True:
            print (n)