Пример #1
0
def chineese(a, b, c, m1, m2, m3):
    inv1 = modinv(m2 * m3, a)
    inv2 = modinv(m1 * m3, b)
    inv3 = modinv(m1 * m2, c)
    x1 = a * m2 * m3 * inv1
    x2 = b * m1 * m3 * inv2
    x3 = c * m1 * m2 * inv3
    print(x1, x2, x3)
    print(inv1, inv2, inv3)
    return (x1 + x2 + x3) % (m1 * m2 * m3)
Пример #2
0
def get_alpha(x1, y1, x2, y2, mod):
    print(f"alpha =((y2-y1)*modinv(x2-x1,mod)) % mod")
    print(f"alpha =(({y2}-{y1})*modinv({x2}-{x1},mod)) % {mod}")
    print(f"alpha =(({y2 - y1})*modinv({x2 - x1},mod)) % {mod}")
    print(
        f"alpha =(({y2 - y1})*{modinv(x2 - x1, mod)}) % {mod} = {((y2 - y1) * modinv(x2 - x1, mod)) % mod}"
    )
    return ((y2 - y1) * modinv(x2 - x1, mod)) % mod
Пример #3
0
def decrypt(a, b, l):
    return chr(((modinv(a, 26) * (l - b) % 26) + ord('A')))
Пример #4
0
def get_a_inv(g,n,sq):
    sq_mod = (g ** sq )% n
    inv = modinv(sq_mod, (n))
    return inv
Пример #5
0
def get_alpha(x, y, a, mod):
    print(f"alpha = (3*{x}**2+{a})*modinv(2*{y},{mod})) % {mod}")
    print(
        f"alpha = ({3*x**2}+{a})*{modinv(2*y,mod)}) % {mod} = {((3*x**2+a)*modinv(2*y,mod)) % mod}"
    )
    return ((3 * x**2 + a) * modinv(2 * y, mod)) % mod