【问题标题】:RSA procedure cryptologyRSA过程密码学
【发布时间】:2017-02-22 16:17:26
【问题描述】:

您好,我想知道是否有人可以使用 maple 帮助我完成以下程序

rsa 解密/加密方法的协议如下,我尝试在此之后尝试尝试的问题,我将不胜感激。谢谢

我目前的尝试如下

rsa := proc (key::rsakey, msg::(list(rsascii))) 
local ct, pe, pm, i; 
 pm := 26271227347; 
pe := key[2]; 
ct := [];
for i to nops(msg) do ct := [op(ct), `mod`(message[i]^pe, pm)] 
end do; 
RETURN(ct) 
end proc;

这是来自使用枫叶网站

【问题讨论】:

  • 和...?有问题吗?
  • 是的,它可以运行,但是当我尝试使用公钥和一些 ASCII 密文进行评估时,它不会返回任何内容
  • 这么小的公钥只允许 3 个字符的 ASCII 消息。
  • 是的,密文的第一位是 11393739244,在纯文本中我认为是 wha 或 Wha

标签: encryption rsa maple prime-factoring greatest-common-divisor


【解决方案1】:

您已获得ne,您需要在解码之前找到对应的d。我不明白您为什么要尝试使用e 进行解码。

您的过程至少包含一种类型,使用message[i] 而不是msg[i]。另请参阅下面代码中的 cmets。

找到d 后,我得到编码整数 11393739244 解码为整数 8​​7,它对应于 ASCII 字符“W”(不是您建议的“wha”或“Wha”)。

我不明白你打算对块大小做什么,所以我不得不猜测。下面我展示了 A) 一次一个字符或 B) 一次使用三个字符完成的编码/解码。我相信您意识到一次编码一个字符并不是一个好主意。此外,在另一个论坛的重复帖子中,您写道您不关心针对攻击的安全性。 (您还在那里写道,这不是家庭作业,但在这里看起来更像是,IMO。)

如果您在编写和使用 rsa 过程时遇到问题,那么您可能会发现各种拆分/集中/填充操作也很困难。

您在评论中写道,当您尝试在程序rsa 中使用您的初始尝试时,“它不会返回任何东西”。如果它作为未评估的调用返回,那么您创建 proc 并分配它的尝试可能实际上并没有奏效。如果您在文档中使用 Maple 的默认 2D 输入模式时遇到问题,请考虑将您的首选项切换到工作表中的 1D Maple Notation 输入。这是 Maple 标准 Java GUI 的两个首选项。

注意。我使用 Maple 的numtheory[lambda] 命令来查找“最小整数 i,使得所有 g 与 n 互质,g^i 与 1 模数一致”。在最近的 Maple 版本中,这也可以作为命令 NumberThoery:-CarmichaelLambda 使用。另见here

restart;

# The procedure `rsa` below can be used to both encode or
# decode an integer.
#
# Conversion from/to ASCII is done separately, before/after.

rsa := proc(key::list(posint), msg::list(posint)) 
  local ct, pe, pm, i; 
  pm := key[1]; 
  pe := key[2];

  ## The original used `message` instead of `msg`, which was
  ## a careless typo. But iterated list concatenation like this
  ## is inefficient. Better to just use `seq`, as below.
  ## Also, use inert `&^` instead of `^` in the call to `mod`
  ## since the latter inefficiently computes the power
  ## explicitly (before taking the modulus).

  #ct := [];
  #  for i to nops(msg) do ct := [op(ct), `mod`(msg[i] &^ pe, pm)] 
  #end do;

  ct := map(u->`mod`(u &^ pe, pm), msg);

  return ct; 
end proc:

# You supplied (n,e) and you'll need to find d in order to decode.

n:=26271227347;
                          n := 26271227347

L := numtheory[lambda](n);
                          L := 13135445468

e:=11546465;
                            e := 11546465

evalb( e < L ); # a requirement
                                true

evalb( gcd(e, L) = 1); # a requirement
                                true

d := 1/e mod L;
                           d := 7567915453

# Now decode the number you supplied.

res := rsa([n,d],[11393739244]);
                             res := [87]

with(StringTools):
# So what ASCII character is that?

convert(res,bytes);

                                 "W"

s := "Wha":
sb := map(convert,convert(s,bytes),string);
                      sb := ["87", "104", "97"]

sbn := map(parse,sb);
                        sbn := [87, 104, 97]

encoded := rsa([n,e],sbn);
          encoded := [11393739244, 9911682959, 21087186892]

decoded := rsa([n,d],encoded);
                      decoded := [87, 104, 97]

pad := proc(str::string)
  local r;
  r := irem(length(str),3);
  cat(seq("0",i=1..`if`(r=0,0,3-r)), str);
end proc:

map(pad, map(convert,decoded,string));
                        ["087", "104", "097"]

cat(op(map(u->convert(map(parse,[LengthSplit(convert(u,string),3)]),
                      bytes), %)));
                                "Wha"

newsb := [cat(op(map(SubstituteAll,map(PadLeft,sb,3)," ","0")))];
                           newsb := ["087104097"]

newsbn := map(parse,newsb);
                        newsbn := [87104097]

encoded := rsa([n,e],newsbn);
                      encoded := [15987098394]

decoded := rsa([n,d],%);
                        decoded := [87104097]

map(pad, map(convert,decoded,string));
                            ["087104097"]

cat(op(map(u->convert(map(parse,[LengthSplit(convert(u,string),3)]),
                      bytes), %)));
                                "Wha"

【讨论】:

  • 如果您使用的是 2D 数学(排版)输入模式,请确保 rsa 和左括号 ( 之间没有多余的空格,当您将其称为 rsa(...) 时。如果有额外的空格,它将被解析为乘法。
  • 嗨,我完全忘记了需要计算 d,谢谢你,以及一次解密一个字符的消息,这会花费太多时间,所以我使用了以下代替 block1:=rsa ([n,d],[第一个要解密的数字,第二个,第三个,依此类推]);你能向我解释一下 ct := map(proc (u) options operator, arrow; mod(&amp;^(u, pe), pm) end proc, msg) 正在做的安静吓人哈哈
  • 尝试找出候选人d是否正确。您尚未提供大部分编码消息,因此您必须让我们知道它的进展情况......
  • rsa 方法有效,消息正确我只是想知道该行在程序中做了什么,因为我不太明白,但是
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-18
  • 2020-01-24
  • 2023-01-19
  • 2013-05-08
  • 2020-11-08
相关资源
最近更新 更多