Exemple #1
0
def gen_prime(n):
    if (n < 200):
        n = 200
    a = 10**n
    b = a * 10
    x = random.randrange(a, b)
    x |= 1
    while (pow(2, x - 1, x) != 1 or MillerRabin.is_Prime(x) == False):
        x += 2
    return x
Exemple #2
0
def gen_RSApq(n):
    x0 = gen_prime(n // 3)
    a = 10**(n - n // 3)
    b = a * 100
    #on genere un grand nombre premier
    #puis on en cherche un de la forme k*x+1
    #ainsi p-1 ne sera pas seulement composé de petits facteurs
    k = random.randrange(a, b)
    x = k * x0 + 1
    while (x & 1 and pow(2, x - 1, x) != 1 and not MillerRabin.is_Prime(x)):
        x += x0
    return x
Exemple #3
0
#!/usr/bin/python3

import random
import math
import sys
import MillerRabin
import algo

factors = [int(nb) for nb in range(3, 100, 2) if MillerRabin.is_Prime(nb)]


def main():
    lenNb = random.randint(200, 210)
    eps = random.randint(1, 10)

    p = gen_RSApq(lenNb)
    q = gen_RSApq(lenNb + eps)
    n = p * q
    e = gen_exp(p, q)
    d = congru_equation(e, 1, (p - 1) * (q - 1))

    m = random.randint(10**100, 10**200)
    print(m)
    c = pow(m, e, n)
    plain = pow(c, d, n)
    print(plain == m)


def gen_exp(p, q):
    e = 1
    prod = (p - 1) * (q - 1)