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

标签 wolfram-mathematica

我在 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/

相关文章:

function - 球体不显示|数学

wolfram-mathematica - 面向对象数学编程

wolfram-mathematica - 使用 BarChart[ ] 工具提示说明数据的来源

wolfram-mathematica - 使用 With 绘图与使用 Block 绘图 (Mathematica)

wolfram-mathematica - 如何在Mathematica中有效地初始化此稀疏数组?

list - 如何在Mathematica中找到局部最小值和列表?

wolfram-mathematica - 数学: flatten a nested list with repetitions

select - "Select"比较 Mathematica 中的相邻元素

wolfram-mathematica - Mathematica——将列表转换为元素位置的分区

wolfram-mathematica - 条件问题 (/;)