Exemplo n.º 1
0
def keygen(n, h):

    f, g = get_nbit_ham_strings(n, h, 2)

    pk = max(f // g, g // f)
    sk = g

    return pk, sk
Exemplo n.º 2
0
def enc(m, pk, p, nn=n, hh=h):
    (R, T) = pk
    pp = 2**nn - 1
    A, B1, B2 = get_nbit_ham_strings(hh, nn, 3)

    C1 = ((A * R) % pp + B1) % pp
    C2 = ((A * T) % pp + B2) % pp ^ E(m, rho)
    return (C1, C2)
Exemplo n.º 3
0
def keygen(n, h):
    p = 2**n - 1
    f, g = get_nbit_ham_strings(n, h, 2)

    r = randrange(p // 2, p)

    t = ((f * r) % p + g) % p

    pk = (r, t)
    sk = f

    return pk, sk, g
Exemplo n.º 4
0
def enc(m, pk, p, n, h):

    a, b = get_nbit_ham_strings(n, h, 2)

    com = 1
    signed = False
    if m:
        com = -1
        signed = True

    c = com * ((a * pk + b) % p)

    return c, signed
Exemplo n.º 5
0
from util import int2string, string2int
from gen import get_nbit_ham_strings, get_n_bit_int
from random import randrange
from ham import ham2
from AJPS_basic import keygen

n = 100
h = 10

pk, sk = keygen(n, h)

guess = get_nbit_ham_strings(n, h, 1).pop()


while ham2(guess//pk) != h or guess//pk != sk:
    guess = get_nbit_ham_strings(n, h, 1).pop()

print(sk == guess//pk)

print(sk, guess)
print(ham2(sk), ham2(guess))