Ask Your Question
0

Can't multiply two variables together due to type (I think)

asked 2014-11-25 17:22:21 +0100

I'm trying to digitally sign a test message in Sage using DSA (DSS). After running my code, I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_28.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("IyBDaGVjayB0aGUgc2lnbmF0dXJlCmNoZWNrX3NpZyhtLHAscSxnLHIscyx5KQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>

  File "/tmp/tmpUuKk65/___code___.py", line 3, in <module>
    exec compile(u'check_sig(m,p,q,g,r,s,y)
  File "", line 1, in <module>

  File "/tmp/tmppjN9Gi/___code___.py", line 7, in check_sig
    u_2 = mod(r*w,q)
  File "element.pyx", line 1701, in sage.structure.element.RingElement.__mul__ (sage/structure/element.c:14531)
  File "coerce.pyx", line 856, in sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure/coerce.c:8169)
TypeError: unsupported operand parent(s) for '*': 'Ring of integers modulo 98007532214006523718033513010741500921668410005086660781341579786663143142637' and 'Ring of integers modulo 44449'

The offending line is: u_2 = mod(r*w,q). I think the issue here is I'm multiplying r and w where:

r = mod(mod(g^k,p),q)
w = mod(1/s,q)

However, these are both mod q. Why can't I perform a multiplication on them? Is there some kind of casting I have to do?

edit retag flag offensive close merge delete

Comments

kcrisman gravatar imagekcrisman ( 2014-12-02 16:33:47 +0100 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2014-11-25 21:17:31 +0100

FrédéricC gravatar image

Maybe you can try to use the Zmod rings instead of the mod function?

sage: ring_q = Zmod(691)   # defining the ring of integers modulo 691
sage: ring_q(345543423)    # converting an integer to this ring
581
edit flag offensive delete link more

Comments

2

mod(a,p) does return an element of Integers(p) so I don't think this is the problem. Mathematically, what id mod(mod(g^k,p),q) supposed to mean? You are trying to map in element of Z/pZ to Z/qZ but there is no such map (at least, no ring homomorphism). Of course you can lift from Z.pZ up to Z first and then down to Z/qZ but this is not a nice map since it depends on which lift you take. This is what happens when you do something like mod(mod(a,p),q).

John Cremona gravatar imageJohn Cremona ( 2014-11-27 13:31:49 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2014-11-25 17:22:21 +0100

Seen: 333 times

Last updated: Nov 25 '14