def test_lcm_list(self):
        self.assertEqual(libnum.lcm(100, 75), 300)
        self.assertEqual(libnum.lcm(100500), 100500)
        self.assertEqual(libnum.lcm(10, 20, 30, 40, 5, 80), 240)

        self.assertRaises(ZeroDivisionError, libnum.lcm, 123, 0, 0)
        self.assertRaises(ZeroDivisionError, libnum.lcm, 0, 100, 123)
        self.assertRaises(TypeError, libnum.lcm, "qwe", 10)
        self.assertRaises(TypeError, libnum.lcm, 10, "qwe")
    def test_lcm_pair(self):
        self.assertEqual(libnum.lcm(100, 75), 300)
        self.assertEqual(libnum.lcm(1, 31), 31)
        self.assertEqual(libnum.lcm(2, 37), 74)

        self.assertRaises(ZeroDivisionError, libnum.lcm, 1, 0)
        self.assertRaises(ZeroDivisionError, libnum.lcm, 0, 1)
        self.assertRaises(TypeError, libnum.lcm, "qwe", 10)
        self.assertRaises(TypeError, libnum.lcm, 10, "qwe")
Exemple #3
0
def test_lcm_list():
    assert lcm(100, 75) == 300
    assert lcm(100500) == 100500
    assert lcm(10, 20, 30, 40, 5, 80) == 240

    assert lcm(123, 0, 0) == 0
    assert lcm(0, 100, 123) == 0

    with pytest.raises(TypeError):
        lcm("qwe", 10)
    with pytest.raises(TypeError):
        lcm(10, "qwe")
Exemple #4
0
def test_lcm_pair():
    assert lcm(100, 75) == 300
    assert lcm(1, 31) == 31
    assert lcm(2, 37) == 74

    assert lcm(1, 0) == 0
    assert lcm(0, 1) == 0

    with pytest.raises(TypeError):
        lcm("qwe", 10)
    with pytest.raises(TypeError):
        lcm(10, "qwe")
Exemple #5
0
        r = random.randint(bound, bound * 0x1000000000001)
        d = sympy.nextprime(r)
        e = libnum.invmod(d, lcm)
        if isPrime(e):
            break
    return e


# generate p and q
p = getStrongPrime(1024)
q = getStrongPrime(1024)
N = p * q

# Generate two big e where limit is a number to confirm parameters satisfy Minkowski Bounds.
# Hint: You may do not need to know about what this part is doing, just try to construct the lattice and use LLL algorithm to solve it!
lcm = libnum.lcm(p - 1, q - 1)
bound = gmpy2.iroot(N, 3)[0]
e1 = genE(lcm, bound)
e2 = genE(lcm, bound)

# encryption
phi = (p - 1) * (q - 1)
d1 = libnum.invmod(e1, phi)
d2 = libnum.invmod(e2, phi)
m1, m2 = bytes_to_long(flag[0:len(flag) // 2]), bytes_to_long(flag[len(flag) //
                                                                   2::])
c1, c2 = pow(m1, e1, N), pow(m2, e2, N)
print('N = ' + str(N))
print('e1 = ' + str(e1))
print('e2 = ' + str(e2))
print('c1 = ' + str(c1))