gpt4 book ai didi

wolfram-mathematica - Mathematica 溢出 [] 错误 : Why and how-to bypass?

转载 作者:行者123 更新时间:2023-12-04 05:41:53 45 4
gpt4 key购买 nike

我在 Mathematica 中从未出现过溢出错误,发生了以下情况。

我演示了 RSA 加密的原理如下:

 n = 11*13
m = EulerPhi[n]
e = 7
GCD[e, m]
d = PowerMod[e, -1, m]
cipher2[m_String] := Map[Mod[#^e, n] &, ToCharacterCode[m]]
decipher2[x_Integer] := FromCharacterCode[Map[Mod[#^d, n] &, x]]

In[207]:= cipher2["StackOverflow"]
decipher2[cipher2["StackOverflow"]]
Out[207]= {8,129,59,44,68,40,79,62,49,119,4,45,37}
Out[208]= StackOverflow

目前没问题。

然后我将质数更改为更现实但仍然非常适中的大小。
 n = 252097800611*252097800629

In[236]:= cipher2["StackOverflow"]
decipher2[cipher2["StackOverflow"]]

Out[236]= {27136050989627, 282621973446656, 80798284478113, \
93206534790699, 160578147647843, 19203908986159, 318547390056832, \
107213535210701, 250226879128704, 114868566764928, 171382426877952, \
207616015289871, 337931541778439}

During evaluation of In[236]:= General::ovfl: Overflow occurred in computation. >>

During evaluation of In[236]:= General::ovfl: Overflow occurred in computation. >>

Out[237]= FromCharacterCode[{Overflow[], Overflow[], Overflow[],
Overflow[], Overflow[], Overflow[], Overflow[], Overflow[],
Overflow[], Overflow[], Overflow[], Overflow[], Overflow[]}]

问题 : 我是否已经突破了 Mathematica 的极限?我是否使用了不正确的方法?什么是旁路,如果有的话?

最佳答案

尝试使用 PowerMod在解密操作中:

n = 252097800611*252097800629;
m = EulerPhi[n];
e = 7;
Print[GCD[e, m]];
d = PowerMod[e, -1, m];
Print[{"n" -> n, "m" -> m, "e" -> e, "d" -> d}];
Grid[
Join[{
{"Input", "Encrypted", "Decrypt with Mod", "Decrypt with PowerMod"}},
Table[{i, (j = Mod[i^e, n]), Mod[j^d, n], PowerMod[j, d, n]}, {i, 40}]],
Frame -> All]

关于wolfram-mathematica - Mathematica 溢出 [] 错误 : Why and how-to bypass?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8095416/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com