08/10/27 00:20:22
Mathematicaでのアルゴリズム記述
(Mathematicaが無くてもアルゴリズムとUnicodeから一応計算可能ですよ^^;)
(* 定義 *)
encrypt[m_, e_, n_] = Mod[m^e, n];
decrypt[c_, d_, n_] = Mod[c^d, n];
p = Prime[60];
q = Prime[70];
n = p q;
phin = (p - 1) (q - 1);
e = 2;
While[GCD[e, phin] != 1, e++];
{g, {d, k}} = ExtendedGCD[e, phin];
d = If[d < 0, d + phin, d];
(* テスト1 *)
m1 = 1234;
c1 = encrypt[m1, e, n]
decrypt[c1, d, n]
(* テスト2 *)
m2 = ToCharacterCode["Nurupo"]
c2 = encrypt[m2, e, n]
FromCharacterCode[decrypt[c2, d, n]]
じゃーまず俺からね~!
公開鍵:{e, n} = {11, 98069}
暗号文:c = {40664, 56301, 18167, 63083, 242, 82112, 39909, 47708, 61841, 5624, \
64264, 76144, 89552, 2690, 53670, 75353}