메이플 웹 사이트를 사용하는, 그리고 당신이 찾아야합니다입니다 해당하는 d
을 디코딩 할 수 있습니다. 디코딩 할 때 왜 e
을 사용하려고했는지 이해가 안됩니다.
절차에 msg[i]
대신 message[i]
을 사용하는 적어도 하나의 유형이 포함되어 있습니다. 아래 코드의 주석을 참조하십시오.
d
을 찾은 후 인코딩 된 정수 11393739244는 ASCII 문자 "W"(제안 된대로 "Wha"또는 "Wha"가 아님)에 해당하는 정수 87로 디코딩됩니다.
블록 크기에 대한 의도를 이해하지 못하고 이므로을 추측해야했습니다. 아래에서는 A) 한 번에 한 글자 또는 한 번에 세 글자를 사용하는 B) 인코딩/디코딩을 보여줍니다. 한 번에 한 문자 씩 인코딩하는 것은 좋은 생각이 아니라는 것을 알고 있습니다. 또한 다른 포럼의 중복 게시물에서 공격에 대한 보안에 신경 쓰지 않는다고 썼습니다. (숙제가 아니라는 점을 썼습니다 만, 여기서는 IMO와 같이 보입니다.)
rsa
절차를 작성하고 사용하는 데 어려움이있는 경우 다양한 분열/협착/패딩 작업이 어려울 수 있습니다 또한.
당신은 절차 rsa
에서 초기 시도를 사용할 때 "아무것도 돌려주지 않습니다"라는 코멘트에 썼습니다. 평가되지 않은 호출로 반환 된 경우 proc 만들기 및 할당 시도는 실제로 작동하지 않습니다. 문서에서 Maple의 기본 2D 입력 모드를 사용하는 데 문제가 있으면 워크 시트에서 기본 설정을 1D Maple Notation 입력으로 전환하십시오. 그것들은 Maple의 표준 Java GUI에 대한 두 가지 기본 설정입니다.
NB. 나는 Maple의 numtheory[lambda]
명령을 사용하여 "모든 g coprime을 n으로, g^i는 1 modulo n과 일치하는 최소 정수 i"를 찾습니다. 최근 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"
...? 문제가 있습니까? –
그래도 실행되지만 공개 키와 ASCII로 된 암호 텍스트로 평가하려고하면 아무 것도 반환하지 않습니다 – Gibberish
공개 키로 작게는 3 문자의 ASCII 메시지 만 허용됩니다. –