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.

4
  • please, add your code and error traceback. Don't use images Commented Nov 21, 2022 at 17:49
  • Why should I not upload images of code/data/errors when asking a question? Commented Nov 21, 2022 at 18:52
  • @cards Done!!!.Kindly help me with this plzzz Commented Nov 22, 2022 at 10:49
  • It looks like you are using a python library for elliptic curve cryptography, but you did not say which one. This is probably relevant information because there seem to be multiple such libraries. (py-ecc, ECPy, ecc-pycrypto, PyCryptodome, maybe others...) Commented Nov 22, 2022 at 10:53

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.