Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/RSA-code/Mathematica/rsa-code.math
Normal file
20
Task/RSA-code/Mathematica/rsa-code.math
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
toNumPlTxt[s_] := FromDigits[ToCharacterCode[s], 256];
|
||||
fromNumPlTxt[plTxt_] := FromCharacterCode[IntegerDigits[plTxt, 256]];
|
||||
enc::longmess = "Message '``' is too long for n = ``.";
|
||||
enc[n_, _, mess_] /;
|
||||
toNumPlTxt[mess] >= n := (Message[enc::longmess, mess, n]; $Failed);
|
||||
enc[n_, e_, mess_] := PowerMod[toNumPlTxt[mess], e, n];
|
||||
dec[n_, d_, en_] := fromNumPlTxt[PowerMod[en, d, n]];
|
||||
text = "The cake is a lie!";
|
||||
n = 9516311845790656153499716760847001433441357;
|
||||
e = 65537;
|
||||
d = 5617843187844953170308463622230283376298685;
|
||||
en = enc[n, e, text];
|
||||
de = dec[n, d, en];
|
||||
Print["Text: '" <> text <> "'"];
|
||||
Print["n = " <> IntegerString[n]];
|
||||
Print["e = " <> IntegerString[e]];
|
||||
Print["d = " <> IntegerString[d]];
|
||||
Print["Numeric plaintext: " <> IntegerString[toNumPlTxt[text]]];
|
||||
Print["Encoded: " <> IntegerString[en]];
|
||||
Print["Decoded: '" <> de <> "'"];
|
||||
Loading…
Add table
Add a link
Reference in a new issue