Example #1
0
def test_smoothness_and_smoothness_p():
    assert smoothness(1) == (1, 1)
    assert smoothness(2 ** 4 * 3 ** 2) == (3, 16)

    assert smoothness_p(10431, m=1) == (1, [(3, (2, 2, 4)), (19, (1, 5, 5)), (61, (1, 31, 31))])
    assert smoothness_p(10431) == (-1, [(3, (2, 2, 2)), (19, (1, 3, 9)), (61, (1, 5, 5))])
    assert smoothness_p(10431, power=1) == (-1, [(3, (2, 2, 2)), (61, (1, 5, 5)), (19, (1, 3, 9))])
    assert (
        smoothness_p(21477639576571, visual=1)
        == "p**i=4410317**1 has p-1 B=1787, B-pow=1787\n" + "p**i=4869863**1 has p-1 B=2434931, B-pow=2434931"
    )
Example #2
0
def test_smoothness_and_smoothness_p():
    assert smoothness(1) == (1, 1)
    assert smoothness(2**4*3**2) == (3, 16)

    assert smoothness_p(10431, m=1) == \
        (1, [(3, (2, 2, 4)), (19, (1, 5, 5)), (61, (1, 31, 31))])
    assert smoothness_p(10431) == \
        (-1, [(3, (2, 2, 2)), (19, (1, 3, 9)), (61, (1, 5, 5))])
    assert smoothness_p(10431, power=1) == \
        (-1, [(3, (2, 2, 2)), (61, (1, 5, 5)), (19, (1, 3, 9))])
    assert smoothness_p(21477639576571, visual=1) == \
        'p**i=4410317**1 has p-1 B=1787, B-pow=1787\n' + \
        'p**i=4869863**1 has p-1 B=2434931, B-pow=2434931'
Example #3
0
 def generate_key(self):
     """
     Генерация ключа для схемы Шнорра
     :return: открытый и закрытый ключ
     """
     p = get_random_prime()
     q = smoothness(p - 1)[0]  # максимальный простой делитель
     x = randint(1, min(MAX_POWER, q))
     g = find_root(p, q)
     y = find_open_key(p, pow(g, x))
     public_key = (y, p, q, g)
     private_key = x
     self.steps = locals()
     return public_key, private_key
Example #4
0
 def generate_key(self):
     """
     Генерация ключа для ГОСТ 30.10-94
     :return: открытый и закрытый ключ
     """
     p = get_random_prime()
     q = smoothness(p - 1)[0]            # максимальный простой делитель
     a = find_root(p, q)
     x = randint(1, q-1)                 # закрытый ключ
     y = pow(a, x, p)                    # открытый ключ
     public_key = (p, q, a, y)
     private_key = x
     self.steps = locals()
     return public_key, private_key
Example #5
0
def largest_prime_factor(n):
    p, g = smoothness(n)
    return p
Example #6
0
from itertools import permutations
from sympy.ntheory.factor_ import smoothness
from math import sqrt

smooth = 0;
for i in range(1,10**10 + 1,1):
    if(i%10**6 == 0):
        print(i//10**6)
    if(smoothness(i)[0] < sqrt(i)):
        smooth+=1

print(smooth + 1)