[英]Decrypting a string using RSA
the scenario is as follows: I am asked to implement a decryption algorithm in Javascript to decrypt a string that was encoded using RSA with the following algorithm: 方案如下:我被要求在Javascript中实现解密算法,以使用以下算法解密使用RSA编码的字符串:
e[i] = RSA((u[i]-e[i-1]) mod n), e[-1] = 0
e[i] = RSA((u[i]-e[i-1]) mod n), e[-1] = 0
A textual description of step 2: We encrypt the first element, subtract the encrypted first element from the second element. 步骤2的文本描述:我们加密第一个元素,从第二个元素中减去加密的第一个元素。 Then we do (modulo n) and then encrypt the result.
然后我们做(模数n)然后加密结果。 And the process continues for the rest of the numbers.
其余的数字继续进行。
Now the problem is the decryption part. 现在问题是解密部分。 I have been stuck at this part for hours!
我被困在这个部分好几个小时!
I worked with the equation, with the goal of making u[n] the subject: 我使用了等式,目标是让你成为主题:
e[i] = RSA((u[i]-e[i-1]) mod n) -- (1)
We know: 我们知道:
RSA(x) = x^e mod n -- (2)
RSA'(x) = x^d mod n -- (3)
So, from (1) and (3) 那么,从(1)和(3)
RSA'(e[i]) = (u[i]-e[i-1]) mod n
RSA'(e[i]) + k*i + e[i-1] = u[i]
Then i am kind of stuck, because we do not know k. 然后我有点卡住,因为我们不知道k。
So, i tried again: 所以,我再试一次:
RSA'(e[i]) = (u[i]-e[i-1]) mod n
(e[i])^d mod n = (u[i]-e[i-1]) mod n
That seems to go no where too... 这似乎也没有...
The second step doesn't make much sense, shouldn't it be: 第二步没有多大意义,不应该是:
e[i] = RSA((u[i]-e[i-1]) mod n), e[-1] = 0
That is, the modulus is independent of the index. 也就是说,模量与指数无关。 It doesn't make much sense because to get
e[0]
you would have to calculate something modulo 0 (equally nonsensical as dividing by zero), and for e[1]
you have to calculate something modulo 1 and the result of that is always 0. 这没有多大意义,因为要获得
e[0]
你必须计算0模的东西(同样无意义地除以零),而对于e[1]
你必须计算模1的东西,结果是总是0。
Furthermore, if n
is the RSA modulus, for the plain text you have 0 <= u[i] < n
. 此外,如果
n
是RSA模数,则对于纯文本,您有0 <= u[i] < n
。 This means that the second step in reverse is just 这意味着反向的第二步就是
u[i] = (RSA'(e[i]) + e[i-1]) mod n
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.