Пример #1
0
    def test_paper_check(self):
        t12_11_3 = ClassGroup(12, 11, 3)
        t93_109_32 = ClassGroup(93, 109, 32)

        self.assertEqual(t12_11_3.discriminant(), -23)
        self.assertEqual(t93_109_32.discriminant(), -23)

        t = t12_11_3 * t93_109_32
        self.assertEqual(t, ClassGroup(1, -15, 62))
        self.assertEqual(t.discriminant(), -23)

        t1 = t93_109_32 * t12_11_3
        self.assertEqual(t, t1)

        # the normalize and reduce example from the paper
        f = ClassGroup(195751, 1212121, 1876411)
        self.assertEqual(f.normalized(), (195751, 37615, 1807))
        self.assertEqual(f.reduced(), (1, 1, 1))
Пример #2
0
def compute_order(g: ClassGroup) -> int:
    d = g.discriminant()
    quadRoot = int((-d)**0.25)
    size = quadRoot
    order = 0
    while order == 0:
        babylist = list(
            accumulate(repeat(g, quadRoot - 1), ClassGroup.multiply))
        babyset = set(babylist)
        gSqrt = (g**quadRoot).normalized()
        bigStep = gSqrt
        result = next(
            filter(
                lambda giant: giant[1] in babyset,
                accumulate(repeat((1, bigStep), size), lambda old, new:
                           (old[0] + new[0], old[1] * new[1]))), None)
        if result is not None:
            order = (result[0] * quadRoot - babylist.index(result[1]) - 1)
            return order
        size *= 2
Пример #3
0
def judge_entry(mystr):
    assert len(mystr) < 100000
    lines = mystr.strip().split(b'\n')
    assert len(lines) == 3
    ds = set()
    for line in lines:
        # File format:
        # challenge(in hex) length a b c order
        vals = [x.strip() for x in line.strip().split(b' ')]
        assert len(vals) == 6
        length = int(vals[1])
        assert length < 5000
        assert all(len(x) < length for x in vals[2:])
        assert len(vals[0]) <= 32
        d = create_discriminant(a2b_hex(vals[0]), length)
        g = ClassGroup(int(vals[2]), int(vals[3]), int(vals[4]))
        assert g.discriminant() == d
        assert g != g.identity()
        order = int(vals[5])
        assert order > 1
        assert g**order == g.identity()
        assert d not in ds
        ds.add(d)
    return -max(ds)
Пример #4
0
 def test_bad_multiply(self):
     n1 = ClassGroup(2243390248, -565721959, 35664920)
     n2 = ClassGroup(2, 1, 370)
     n = n1 * n2
     self.assertEqual(n.discriminant(), n1.discriminant())
     self.assertEqual(n.discriminant(), n2.discriminant())