在SAGE中执行两个整数环(具有不同的mod)之间的算术运算

时间:2014-11-25 16:12:55

标签: python math cryptography sage dsa

我正在尝试使用DSA(DSS)在Sage中对测试邮件进行数字签名。运行我的代码后,我得到:

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'

违规行是:u_2 = mod(r*w,q)。我认为这里的问题是我将rw相乘:

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

但是,这些都是mod q。为什么我不能对它们进行乘法运算?我必须做某种演员吗?

以下是完整(仍然很小)sage表的链接:http://i.imgur.com/dX7PKHi.png

0 个答案:

没有答案
相关问题