0

CODE

start_time1 = time.time()

ec = EC(a, b, num)
g, _ = ec.at(at)
assert ec.order(g) <= ec.q
            
# ElGamal enc/dec usage
eg = ElGamal(ec, g)
# mapping value to ec point
# "masking": value k to point ec.mul(g, k)
# ("imbedding" on proper n:use a point of x as 0 <= n*v <= x < n*(v+1) < q)
mapping = [ec.mul(g, i) for i in range(eg.n)]
plain = mapping[at]    
pub = eg.gen(priv)   
cipher = eg.enc(plain, pub, r) 
decoded = eg.dec(cipher, priv)
assert decoded == plain
assert cipher != pub

average_time1 = time.time() - start_time1

ERROR TRACEBACK

Exception                                 Traceback (most recent call last)
<ipython-input-2-77934393a2f8> in <module>
    256 
    257 ec = EC(a, b, num)
--> 258 g, _ = ec.at(at)
    259 assert ec.order(g) <= ec.q
    260 

1 frames
<ipython-input-2-77934393a2f8> in sqrt(n, q)
     85             return (i, q - i)
     86         pass
---> 87     raise Exception("not found")
     88 
     89 

Exception: not found

Donot know what to do with this error.This is basically an ECC Cryptography Code in Python.

I found this on the stack overflow -

use \Exception as Exception;

But Error.

1 Answers1

0

The exception appear to originate in this code for calculating (or really, just brute-forcing by trying all integer possibilities) the square root of a number n, modulo q.

def sqrt(n, q):
    """sqrt on PN modulo: returns two numbers or exception if not exist
    >>> assert (sqrt(n, q)[0] ** 2) % q == n
    >>> assert (sqrt(n, q)[1] ** 2) % q == n
    """
    assert n < q
    for i in range(1, q):
        if i * i % q == n:
            return (i, q - i)
        pass
    raise Exception("not found")

Not all whole numbers are squares of other whole numbers, so the function will throw an exception with the message "not found" for that case.

This in turn is happening because on the line

g, _ = ec.at(at)

you are asking for a point on the elliptic curve which does not exist.

Wim Coenen
  • 66,094
  • 13
  • 157
  • 251