好的,基本上我无法让RSA加密程序的一部分正常工作。我正在用MIPS编写程序,并试图将一个数字的模数提升到另一个数字。使用维基百科的例子我提高65 ^ 17,这给了6.599E30左右。我现在需要将这个数字模数减少3233(再次来自维基百科的例子)。
到目前为止,我一直无法正常工作。我已经尝试将其除以3233,但无法弄清楚如何正确获取剩余部分,就像我截断时,我丢失了大量的数字
div.d $f0, $f0, $f6 #f6 is currently 3233
trunc.w.d $f8, $f0 #this is what is going wrong
cvt.d.w $f8, $f8 #when we do this truncation we end up with something other
#than the number without the remainder
li $v0, 3
add.d $f12, $f8, $f4 #using this to test print what is in $f8. $f4 is 0
syscall #When printed we get 2.14...E9
sub.d $f0, $f0, $f8
mul.d $f0, $f0, $f6 #when we print $f0 we get 6.599...E30, but what we want is 2790
如果有人知道如何正确地给出2790的值,作为$ f0的最终值,任何建议将不胜感激。
谢谢!
好的,我有点能解决它。这样取幂然后对数字进行模数化,然后对某个指数重复。不确定如何准确地解决原始问题,但这具有相同的效果。
loop2:
mul.d $f0, $f0, $f2 #the exponentiation
div.d $f0, $f0, $f6 #here we divide by the public key to modulus
floor.w.d $f8, $f0 #We truncate this to get the number without the remainder
cvt.d.w $f8, $f8
sub.d $f0, $f0, $f8 #we subtract in order to get only the remainder
mul.d $f0, $f0, $f6 #multiply the remainder by the divisor to get the modulus
round.w.d $f0, $f0 #round, don't floor because we sometimes get #'s that dont get
#computed quite correctly and end up at x.999 instead of x+1
#and those get floored down to x
cvt.d.w $f0,$f0
addi $t5, $t5, 1 # this is the incrementer
blt $t5, $t3, loop2 #raises input number to power