(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 6.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 16088, 589] NotebookOptionsPosition[ 12252, 444] NotebookOutlinePosition[ 13178, 479] CellTagsIndexPosition[ 13052, 473] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["\<\ RSA kriptosistem \ \>", "Title"], Cell[CellGroupData[{ Cell["Dve veliki pra\[SHacek]tevili", "Subtitle"], Cell[CellGroupData[{ Cell[TextData[{ "V ", StyleBox["Mathematici ", FontSlant->"Italic"], "za izra\[CHacek]un n-tega pra\[SHacek]tevila uporabimo ukaz Prime." }], "Text", CellDingbat->None, FontFamily->"Courier New", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}, Background->RGBColor[0.714855, 0.906264, 0.718761]], Cell[CellGroupData[{ Cell["?Prime", "Input"], Cell[BoxData[ RowBox[{ StyleBox["\<\"\!\(\*RowBox[{\\\"Prime\\\", \\\"[\\\", StyleBox[\\\"n\\\", \ \\\"TI\\\"], \\\"]\\\"}]\) gives the \!\(\*SuperscriptBox[StyleBox[\\\"n\\\", \ \\\"TI\\\"], \\\"th\\\"]\) prime number. \"\>", "MSG"], " ", ButtonBox[ StyleBox["\[RightSkeleton]", "SR"], Active->True, BaseStyle->"Link", ButtonData->"paclet:ref/Prime"]}]], "Print", "PrintUsage", CellChangeTimes->{3.438068892022805*^9}, CellTags->"Info3438072491-9386299"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Radi bi poiskati dve primerljivo veliki pra\[SHacek]tevili. Primerljivo veliki? Skoraj isto \[SHacek]tevilo binarnih/decimalnih mest.\ \>", "Text", CellDingbat->None, FontFamily->"Courier New", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}, Background->RGBColor[0.714855, 0.906264, 0.718761]], Cell[CellGroupData[{ Cell["p=Prime[10^9]", "Input"], Cell[BoxData["22801763489"], "Output", CellChangeTimes->{ 3.438068806212049*^9, 3.438068840375988*^9, {3.438068880004427*^9, 3.438068892151812*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["q=Prime[8*10^8]", "Input"], Cell[BoxData["18054236957"], "Output", CellChangeTimes->{ 3.4380688062461023`*^9, 3.438068840408206*^9, {3.438068880035471*^9, 3.438068892183765*^9}}] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Produkt pra\[SHacek]tevil p in q ozna\[CHacek]imo z n. \ \>", "Text", CellDingbat->None, FontFamily->"Courier New", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}, Background->RGBColor[0.714855, 0.906264, 0.718761]], Cell[CellGroupData[{ Cell["n=p q", "Input"], Cell[BoxData["411668441067877062973"], "Output", CellChangeTimes->{ 3.438068806262772*^9, 3.438068840441361*^9, {3.438068880068578*^9, 3.438068892216659*^9}}] }, Open ]] }, Open ]] }, Open ]], Cell["", "Text"], Cell[CellGroupData[{ Cell["Eulerjeva funkcija", "Subtitle"], Cell[CellGroupData[{ Cell["\<\ S phi oznaczimo Eulerjevo funkcijo \[SHacek]tevila n = p q. Ker poznamo pra\[SHacek]tevilski razcep \[SHacek]tevila n je naloga otro\ \[CHacek]je lahka.\ \>", "Text", CellDingbat->None, FontFamily->"Courier New", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}, Background->RGBColor[0.714855, 0.906264, 0.718761]], Cell[CellGroupData[{ Cell["phi=(p-1)(q-1)", "Input"], Cell[BoxData["411668441027021062528"], "Output", CellChangeTimes->{ 3.43806880632915*^9, 3.438068840457048*^9, {3.4380688801011963`*^9, 3.438068892283318*^9}}] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Na\[SHacek]e \[SHacek]tevilo je dovolj majhno, da zna njegovo Eulerjevo \ funkcijo izra\[CHacek]unati tudi ", StyleBox["Mathematica", FontSlant->"Italic"], ". \nTo pomeni, da na\[SHacek]i klju\[CHacek]i v tem zgledu nikakor niso \ varni!!" }], "Text", CellDingbat->None, FontFamily->"Courier New", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}, Background->RGBColor[1, 0.4, 0.4]], Cell[CellGroupData[{ Cell["EulerPhi[n]", "Input"], Cell[BoxData["411668441027021062528"], "Output", CellChangeTimes->{ 3.438068806362294*^9, 3.438068840490403*^9, {3.43806888011799*^9, 3.4380688922999*^9}}] }, Open ]] }, Open ]] }, Open ]], Cell["", "Text"], Cell[CellGroupData[{ Cell[TextData[{ "Konstrukcija javnega in privatnega klju", StyleBox["\[CHacek]", FontFamily->"Arial CE"], "a" }], "Subtitle"], Cell[CellGroupData[{ Cell["\<\ Izberimo si poljubno \[SHacek]tevilo d, manj\[SHacek]e od phi, ki je TUJE phi. Poskusimo s slu\[CHacek]ajnim \[SHacek]tevilom.\ \>", "Text", CellDingbat->None, FontFamily->"Courier New", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}, Background->RGBColor[0.714855, 0.906264, 0.718761]], Cell[CellGroupData[{ Cell["?RandomInteger", "Input", CellChangeTimes->{{3.532163904532065*^9, 3.5321639082242937`*^9}}], Cell[BoxData[ RowBox[{ StyleBox["\<\"\!\(\*RowBox[{\\\"RandomInteger\\\", \\\"[\\\", RowBox[{\\\"{\ \\\", RowBox[{SubscriptBox[StyleBox[\\\"i\\\", \\\"TI\\\"], \ StyleBox[\\\"min\\\", \\\"TI\\\"]], \\\",\\\", \ SubscriptBox[StyleBox[\\\"i\\\", \\\"TI\\\"], StyleBox[\\\"max\\\", \ \\\"TI\\\"]]}], \\\"}\\\"}], \\\"]\\\"}]\) gives a pseudorandom integer in \ the range \!\(\*RowBox[{\\\"{\\\", RowBox[{SubscriptBox[StyleBox[\\\"i\\\", \ \\\"TI\\\"], \\\"min\\\"], \\\",\\\", \\\"\[Ellipsis]\\\", \\\",\\\", \ SubscriptBox[StyleBox[\\\"i\\\", \\\"TI\\\"], \\\"max\\\"]}], \\\"}\\\"}]\). \ \\n\!\(\*RowBox[{\\\"RandomInteger\\\", \\\"[\\\", \ SubscriptBox[StyleBox[\\\"i\\\", \\\"TI\\\"], StyleBox[\\\"max\\\", \ \\\"TI\\\"]], \\\"]\\\"}]\) gives a pseudorandom integer in the range \ \!\(\*RowBox[{\\\"{\\\", RowBox[{\\\"0\\\", \\\",\\\", \\\"\[Ellipsis]\\\", \ \\\",\\\", SubscriptBox[StyleBox[\\\"i\\\", \\\"TI\\\"], \\\"max\\\"]}], \ \\\"}\\\"}]\). \\n\!\(\*RowBox[{\\\"RandomInteger\\\", \\\"[\\\", \\\"]\\\"}]\ \) pseudorandomly gives 0 or 1. \\n\!\(\*RowBox[{\\\"RandomInteger\\\", \\\"[\ \\\", RowBox[{StyleBox[\\\"range\\\", \\\"TI\\\"], \\\",\\\", \ StyleBox[\\\"n\\\", \\\"TI\\\"]}], \\\"]\\\"}]\) gives a list of \ \!\(\*StyleBox[\\\"n\\\", \\\"TI\\\"]\) pseudorandom integers. \ \\n\!\(\*RowBox[{\\\"RandomInteger\\\", \\\"[\\\", RowBox[{StyleBox[\\\"range\ \\\", \\\"TI\\\"], \\\",\\\", RowBox[{\\\"{\\\", \ RowBox[{SubscriptBox[StyleBox[\\\"n\\\", \\\"TI\\\"], StyleBox[\\\"1\\\", \ \\\"TR\\\"]], \\\",\\\", SubscriptBox[StyleBox[\\\"n\\\", \\\"TI\\\"], \ StyleBox[\\\"2\\\", \\\"TR\\\"]], \\\",\\\", StyleBox[\\\"\[Ellipsis]\\\", \\\ \"TR\\\"]}], \\\"}\\\"}]}], \\\"]\\\"}]\) gives an \ \!\(\*RowBox[{SubscriptBox[StyleBox[\\\"n\\\", \\\"TI\\\"], \\\"1\\\"], \\\"\ \[Cross]\\\", SubscriptBox[StyleBox[\\\"n\\\", \\\"TI\\\"], \\\"2\\\"], \\\"\ \[Cross]\\\", \\\"\[Ellipsis]\\\", \\\" \\\"}]\) array of pseudorandom \ integers. \"\>", "MSG"], "\[NonBreakingSpace]", ButtonBox[ StyleBox["\[RightSkeleton]", "SR"], Active->True, BaseStyle->"Link", ButtonData->"paclet:ref/RandomInteger"]}]], "Print", "PrintUsage", CellChangeTimes->{3.532358232354857*^9}, CellTags->"Info3532361831-5971902"] }, Open ]], Cell[BoxData[ RowBox[{"d", "=", RowBox[{"RandomInteger", "[", RowBox[{"phi", "-", "1"}], "]"}]}]], "Input"], Cell[BoxData["49549405303832841569"], "Output", CellChangeTimes->{ 3.43806880669481*^9, 3.438068840789805*^9, {3.438068880400432*^9, 3.438068892598754*^9}}], Cell[CellGroupData[{ Cell["GCD[d, phi]", "Input"], Cell[BoxData["1"], "Output", CellChangeTimes->{ 3.43806880674618*^9, 3.438068840841873*^9, {3.43806888045267*^9, 3.438068892666465*^9}}] }, Open ]], Cell["\<\ Par (n,d) je Borutov privatni klju\[CHacek].\ \>", "Text", CellDingbat->None, FontFamily->"Courier New", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}, Background->RGBColor[0.714855, 0.906264, 0.718761]] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Dolo\[CHacek]imo naravno \[SHacek]tevilo e, ki re\[SHacek]i diofansko ena\ \[CHacek]bo: e*d = 1 + k*phi Z drugimi besedami, e*d je po modulu phi kongruenten 1. Par (n,e) je Borutov javni klju\[CHacek].\ \>", "Text", CellDingbat->None, FontFamily->"Courier New", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}, Background->RGBColor[0.714855, 0.906264, 0.718761]], Cell[CellGroupData[{ Cell["e=PowerMod[d,-1,phi]", "Input"], Cell[BoxData["396702186635970141473"], "Output", CellChangeTimes->{ 3.438068806856423*^9, 3.438068840908722*^9, {3.438068880503543*^9, 3.4380688927330303`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Mod[e d, phi]", "Input"], Cell[BoxData["1"], "Output", CellChangeTimes->{ 3.4380688068832893`*^9, 3.438068840940503*^9, {3.4380688805347633`*^9, 3.4380688927487803`*^9}}] }, Open ]], Cell["\<\ Zelo pomembno se je znebiti \[SHacek]tevila phi. Ravno tako moramo paziti, da nih\[CHacek]e ne more do privatnega \ klju\[CHacek]a.\ \>", "Text", CellDingbat->None, FontFamily->"Courier New", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}, Background->RGBColor[1, 0.4, 0.4]] }, Open ]] }, Open ]], Cell["", "Text"], Cell[CellGroupData[{ Cell["Prenos kriptiranih podatkov", "Subtitle"], Cell[CellGroupData[{ Cell["\<\ An\[CHacek]ka bi rada Borutu poslala sporo\[CHacek]ilo. \ \>", "Text", CellDingbat->None, FontFamily->"Courier New", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}, Background->RGBColor[0.714855, 0.906264, 0.718761]], Cell[CellGroupData[{ Cell["sporocilo=12345678987654321", "Input", CellChangeTimes->{3.438068782407312*^9}], Cell[BoxData["12345678987654321"], "Output", CellChangeTimes->{{3.438068783666471*^9, 3.438068806911375*^9}, 3.438068840973703*^9, {3.438068880551256*^9, 3.438068892782542*^9}}] }, Open ]], Cell["\<\ Sporo\[CHacek]ilo, ki ga An\[CHacek]ka po\[CHacek]ilja Borutu mora biti \ kratko. Manj\[SHacek]e od n. To ne predstavlja nobenega problema. \[CapitalCHacek]e je sporo\[CHacek]ilo \ dalj\[SHacek]e, ga lahko razseka na kraj\[SHacek]e dele.\ \>", "Text", CellDingbat->None, FontFamily->"Courier New", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}, Background->RGBColor[0.714855, 0.906264, 0.718761]] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Sporo\[CHacek]ilo An\[CHacek]ka zaklene z Borutovim javnim klju\[CHacek]em. Potencira ga na potenco e in dolo\[CHacek]i ostanek pri deljenju z n.\ \>", "Text", CellDingbat->None, FontFamily->"Courier New", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}, Background->RGBColor[1, 1, 0.4]], Cell[CellGroupData[{ Cell["zaklenjenoSporocilo=PowerMod[sporocilo,e,n]", "Input"], Cell[BoxData["373251538431623327490"], "Output", CellChangeTimes->{ 3.438068806929143*^9, 3.438068841008595*^9, {3.438068880584649*^9, 3.438068892800179*^9}}] }, Open ]], Cell["\<\ Zaklenjeno sporo\[CHacek]ilo lahko po\[SHacek]lje Borutu po nezavarovanem \ kanalu. Odklene ga lahko samo Borut.\ \>", "Text", CellDingbat->None, FontFamily->"Courier New", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}, Background->RGBColor[0.714855, 0.906264, 0.718761]] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Borut sporo\[CHacek]ilo odklene s svojim privatnim klju\[CHacek]em. Potencira ga na potenco d in dolo\[CHacek]i ostanek pri deljenju z n.\ \>", "Text", CellDingbat->None, FontFamily->"Courier New", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}, Background->RGBColor[1, 1, 0.4]], Cell[CellGroupData[{ Cell["odklenjenoSporocilo=PowerMod[zaklenjenoSporocilo,d,n]", "Input"], Cell[BoxData["12345678987654321"], "Output", CellChangeTimes->{ 3.43806880696211*^9, 3.438068841041718*^9, {3.4380688806177607`*^9, 3.438068892832346*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["sporocilo==odklenjenoSporocilo", "Input"], Cell[BoxData["True"], "Output", CellChangeTimes->{ 3.438068806978602*^9, 3.4380688410738564`*^9, {3.4380688806512337`*^9, 3.438068892850047*^9}}] }, Open ]], Cell["", "Text", CellDingbat->None, FontFamily->"Courier New", FontWeight->"Plain", FontVariations->{"CompatibilityType"->0}, Background->RGBColor[0.714855, 0.906264, 0.718761]] }, Open ]] }, Open ]] }, Open ]] }, ScreenStyleEnvironment->"Working", WindowToolbars->{}, CellGrouping->Manual, WindowSize->{882, 659}, WindowMargins->{{45, Automatic}, {Automatic, 6}}, PrivateNotebookOptions->{"ColorPalette"->{RGBColor, -1}}, ShowSelection->True, ShowCellTags->False, RenderingOptions->{"ObjectDithering"->True, "RasterDithering"->False}, Magnification->1, FrontEndVersion->"8.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (November 6, \ 2010)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{ "Info3438072491-9386299"->{ Cell[1079, 49, 475, 11, 44, "Print", CellTags->"Info3438072491-9386299"]}, "Info3532361831-5971902"->{ Cell[4954, 206, 2220, 36, 100, "Print", CellTags->"Info3532361831-5971902"]} } *) (*CellTagsIndex CellTagsIndex->{ {"Info3438072491-9386299", 12837, 464}, {"Info3532361831-5971902", 12946, 467} } *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[567, 22, 42, 3, 123, "Title"], Cell[CellGroupData[{ Cell[634, 29, 49, 0, 46, "Subtitle"], Cell[CellGroupData[{ Cell[708, 33, 320, 10, 44, "Text"], Cell[CellGroupData[{ Cell[1053, 47, 23, 0, 27, "Input"], Cell[1079, 49, 475, 11, 44, "Print", CellTags->"Info3438072491-9386299"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[1603, 66, 323, 8, 61, "Text"], Cell[CellGroupData[{ Cell[1951, 78, 30, 0, 27, "Input"], Cell[1984, 80, 155, 3, 27, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[2176, 88, 32, 0, 27, "Input"], Cell[2211, 90, 157, 3, 27, "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[2417, 99, 245, 7, 44, "Text"], Cell[CellGroupData[{ Cell[2687, 110, 22, 0, 27, "Input"], Cell[2712, 112, 165, 3, 27, "Output"] }, Open ]] }, Open ]] }, Open ]], Cell[2916, 120, 16, 0, 26, "Text"], Cell[CellGroupData[{ Cell[2957, 124, 38, 0, 46, "Subtitle"], Cell[CellGroupData[{ Cell[3020, 128, 342, 9, 61, "Text"], Cell[CellGroupData[{ Cell[3387, 141, 31, 0, 27, "Input"], Cell[3421, 143, 166, 3, 27, "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[3636, 152, 422, 12, 61, "Text"], Cell[CellGroupData[{ Cell[4083, 168, 28, 0, 27, "Input"], Cell[4114, 170, 162, 3, 27, "Output"] }, Open ]] }, Open ]] }, Open ]], Cell[4315, 178, 16, 0, 26, "Text"], Cell[CellGroupData[{ Cell[4356, 182, 130, 5, 51, "Subtitle"], Cell[CellGroupData[{ Cell[4511, 191, 316, 8, 61, "Text"], Cell[CellGroupData[{ Cell[4852, 203, 99, 1, 27, "Input"], Cell[4954, 206, 2220, 36, 100, "Print", CellTags->"Info3532361831-5971902"] }, Open ]], Cell[7189, 245, 115, 3, 27, "Input"], Cell[7307, 250, 163, 3, 27, "Output"], Cell[CellGroupData[{ Cell[7495, 257, 28, 0, 27, "Input"], Cell[7526, 259, 143, 3, 27, "Output"] }, Open ]], Cell[7684, 265, 234, 7, 44, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[7955, 277, 393, 13, 129, "Text"], Cell[CellGroupData[{ Cell[8373, 294, 37, 0, 27, "Input"], Cell[8413, 296, 167, 3, 27, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[8617, 304, 30, 0, 27, "Input"], Cell[8650, 306, 151, 3, 27, "Output"] }, Open ]], Cell[8816, 312, 305, 10, 78, "Text"] }, Open ]] }, Open ]], Cell[9148, 326, 16, 0, 26, "Text"], Cell[CellGroupData[{ Cell[9189, 330, 47, 0, 46, "Subtitle"], Cell[CellGroupData[{ Cell[9261, 334, 246, 7, 44, "Text"], Cell[CellGroupData[{ Cell[9532, 345, 86, 1, 27, "Input"], Cell[9621, 348, 182, 2, 27, "Output"] }, Open ]], Cell[9818, 353, 427, 10, 61, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[10282, 368, 317, 9, 78, "Text"], Cell[CellGroupData[{ Cell[10624, 381, 60, 0, 27, "Input"], Cell[10687, 383, 165, 3, 27, "Output"] }, Open ]], Cell[10867, 389, 303, 9, 61, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[11207, 403, 309, 9, 78, "Text"], Cell[CellGroupData[{ Cell[11541, 416, 70, 0, 27, "Input"], Cell[11614, 418, 162, 3, 27, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[11813, 426, 47, 0, 27, "Input"], Cell[11863, 428, 152, 3, 27, "Output"] }, Open ]], Cell[12030, 434, 182, 5, 44, "Text"] }, Open ]] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)