Beispiel #1
0
def zad_5():
    ran = range(0, 1024)
    result0 = Modular.ModuloEquatation(8, 8, 1024, ran)

    print("NWD")
    print(Modular.nwd(result0))

    print('Sum of x')
    print(np.sum(result0))

    max_value = 0
    max_power = 0
    for i in range(len(result0)):
        value = result0[i]
        power = Modular.phi(value)
        if max_power < power:
            max_power = power
            max_value = value
        elif power < max_power:
            a = pow(max_value, max_power)
            b = pow(value, power)
            if a < b:
                max_power = power
                max_value = value

    print("max")
    print(pow(max_value, max_power))

    print('k')
    print(len(result0))
Beispiel #2
0
 def test_multiply_large_numbers(self):
     first = pow(81723, 4)
     second = pow(56789, 7)
     mod = 123456789
     result = Modular.mul_modulo(first, second, mod)
     expected = 28459179
     self.assertEqual(expected, result)
Beispiel #3
0
 def test_multiply_by_modulo_multiple(self):
     first = 10
     second = 7
     mod = 5
     result = Modular.mul_modulo(first, second, mod)
     expected = 0
     self.assertEqual(expected, result)
Beispiel #4
0
 def test_simple_multiply(self):
     first = 2
     second = 3
     mod = 5
     result = Modular.mul_modulo(first, second, mod)
     expected = 1
     self.assertEqual(expected, result)
Beispiel #5
0
 def test_simple_power(self):
     first = 5
     second = 4
     mod = 9
     result = Modular.pow_modulo(first, second, mod)
     expected = 4
     self.assertEqual(expected, result)
Beispiel #6
0
 def test_power_large_numbers(self):
     first = 2018
     second = 2018
     mod = pow(2, 32) - 1
     result = Modular.pow_modulo(first, second, mod)
     expected = 2110863454
     self.assertEqual(expected, result)
Beispiel #7
0
def zad_2():
    base = 2018
    power = 2018
    mod = pow(2, 32) - 1

    a = Modular.pow_modulo(base, power, mod)

    t1 = int(pow(2, 16) - 1)
    result1 = a % t1
    print(" a mod( 2^16 -1)")
    print(result1)

    result2 = Modular.tau(a)
    print(" tau(a)")
    print(result2)

    result3 = Modular.jota(a)
    print(" jota(a)")
    print(result3)

    result4 = Modular.nwd([a, t1])
    print(" nwd(a, 2^16 -1)")
    print(result4)

    result5 = Modular.nww([a, t1])
    print(" nww(a, 2^16 -1)")
    print(result5)

    result61, result62 = Modular.pi_from_probability(a)
    print(" pi(a)")
    print(result61)
    print(result62)

    result7 = Modular.phi_by_kanon(a)
    print(" euler(a)")
    print(result7)

    result8 = Modular.is_prime(a)
    t2 = Modular.kanon(a)
    print(" zad2.1")
    print(result8)
    print(min(t2))

    result9 = Modular.nfermat(a)
    print(" zad2.2")
    print(result9)
    print(t2)
Beispiel #8
0
 def test_ModuloEquatation(self):
     expected = [1, 129, 257, 385, 513, 641, 769, 897]
     ran = range(0, 1025)
     a = 8
     b = 8
     mod = 1024
     result = Modular.ModuloEquatation(a, b, mod, ran)
     self.assertEquals(expected, result)
Beispiel #9
0
    def test_euklidesEquatation(self):
        a = math.pow(2, 16) - 1
        b = math.pow(2, 16) + 1
        nwd, x, y = Modular.euklidesEquatation(a, b)

        self.assertEquals(1, nwd)
        self.assertEquals(math.pow(2, 15), x)
        self.assertEquals(-math.pow(2, 15) + 1, y)
Beispiel #10
0
def zad_3():
    n = 5
    solutions = []
    primes = Modular.nPrime(n)
    ran = range(1, 2048)
    for i in range(1, n + 1):
        solutions.append(Modular.ModuloEquatation(1, i, primes[i - 1], ran))

    base = set(solutions[0])
    for i in range(1, n):
        B = set(solutions[i])
        base = base.intersection(B)

    x = min(base)

    print(x)
    is_prime = Modular.is_prime(x)
    print("is prime:", is_prime)

    result1 = Modular.tau(x)
    print(result1)

    result2 = Modular.phi(x)
    print(result2)

    result3 = Modular.jota(x)
    print(result3)

    result4 = Modular.kanon(x)
    print(result4)
Beispiel #11
0
    def test_pow_modulo(self):
        expected = 2110863454

        a = 2018
        n = 2018
        mod = pow(2, 32) - 1

        result = Modular.pow_modulo(a, n, mod)
        self.assertEquals(expected, result)
Beispiel #12
0
def zad_4():
    a = pow(2, 16) - 1
    b = pow(2, 16) + 1

    result1 = Modular.nwd([a, b])
    print("nwd", result1)

    result2 = pow(a, 32) * pow(b, 32)  # nwd is 1
    print("nww", result2)

    print("phi", Modular.phi_by_kanon_pow(a, b))

    nwd, x, y = Modular.euklidesEquatation(a, b)
    kanonx = Modular.kanon(x)
    kanony = Modular.kanon(y)

    print("x:", x)
    print("kanon x:", kanonx)

    print("y:", y)
    print("kanon y:", kanony)
Beispiel #13
0
    def test_kanon3(self):
        expected = {2: 1, 5: 1}
        a = 10

        result = Modular.kanon(a)
        self.assertEqual(expected, result)
Beispiel #14
0
 def test_pi2(self):
     expected = 1
     a = 2
     self.assertEquals(expected, Modular.pi(a))
Beispiel #15
0
 def test_pi1(self):
     expected = 0
     a = 1
     self.assertEquals(expected, Modular.pi(a))
Beispiel #16
0
 def test_nFermat_non(self):
     expected = None
     a = 4
     self.assertEquals(expected, Modular.nfermat(a))
Beispiel #17
0
 def test_nPrimeNumbers(self):
     expected = [2, 3, 5, 7, 11]
     n = 5
     self.assertEquals(expected, Modular.nPrime(n))
Beispiel #18
0
 def test_nFermat0(self):
     expected = 0
     a = 3
     self.assertEquals(expected, Modular.nfermat(a))
Beispiel #19
0
 def test_nFermat5(self):
     expected = 5
     a = 4294967297
     self.assertEquals(expected, Modular.nfermat(a))
Beispiel #20
0
 def test_Fermat7(self):
     expected = 340282366920938463463374607431768211457
     a = 7
     self.assertEquals(expected, Modular.fermat(a))
Beispiel #21
0
    def test_kanon4(self):
        expected = {97: 1}
        a = 97

        result = Modular.kanon(a)
        self.assertEqual(expected, result)
Beispiel #22
0
 def test_NWD1(self):
     expected = 1
     a = 5
     b = 12
     self.assertEquals(expected, Modular.nwd([a, b]))
Beispiel #23
0
    def test_jota(self):
        expected = 1
        a = 0

        result = Modular.jota(a)
        self.assertEquals(expected, result)
Beispiel #24
0
 def test_pi3(self):
     expected = 2
     a = 3
     self.assertEquals(expected, Modular.pi(a))
Beispiel #25
0
    def test_tau2(self):
        expected = 8
        a = 30

        result = Modular.tau(a)
        self.assertEquals(expected, result)
Beispiel #26
0
 def test_pi5(self):
     expected = 8
     a = 19
     self.assertEquals(expected, Modular.pi(a))
Beispiel #27
0
    def test_jota_negative(self):
        expected = 3
        a = -5

        result = Modular.jota(a)
        self.assertEquals(expected, result)
Beispiel #28
0
 def test_Fermat0(self):
     expected = 3
     a = 0
     self.assertEquals(expected, Modular.fermat(a))
Beispiel #29
0
 def test_NWD2(self):
     expected = 1
     a = int(math.pow(2, 16) + 1)
     b = int(math.pow(2, 16) - 1)
     self.assertEquals(expected, Modular.nwd([a, b]))
Beispiel #30
0
 def test_Fermat5(self):
     expected = 4294967297
     a = 5
     self.assertEquals(expected, Modular.fermat(a))