(* 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[ 12563, 373] NotebookOptionsPosition[ 11096, 317] NotebookOutlinePosition[ 11437, 332] CellTagsIndexPosition[ 11394, 329] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Alphabet", "=", RowBox[{"CharacterRange", "[", RowBox[{"\"\\"", ",", "\"\\""}], "]"}]}]], "Input", CellChangeTimes->{{3.409851601908718*^9, 3.4098516168502035`*^9}}], Cell[BoxData[ RowBox[{"{", RowBox[{"\<\"A\"\>", ",", "\<\"B\"\>", ",", "\<\"C\"\>", ",", "\<\"D\"\>", ",", "\<\"E\"\>", ",", "\<\"F\"\>", ",", "\<\"G\"\>", ",", "\<\"H\"\>", ",", "\<\"I\"\>", ",", "\<\"J\"\>", ",", "\<\"K\"\>", ",", "\<\"L\"\>", ",", "\<\"M\"\>", ",", "\<\"N\"\>", ",", "\<\"O\"\>", ",", "\<\"P\"\>", ",", "\<\"Q\"\>", ",", "\<\"R\"\>", ",", "\<\"S\"\>", ",", "\<\"T\"\>", ",", "\<\"U\"\>", ",", "\<\"V\"\>", ",", "\<\"W\"\>", ",", "\<\"X\"\>", ",", "\<\"Y\"\>", ",", "\<\"Z\"\>"}], "}"}]], "Output", CellChangeTimes->{3.409913959580432*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"LettersToNumbers", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"Alphabet", "[", RowBox[{"[", "i", "]"}], "]"}], "\[Rule]", RowBox[{"i", "-", "1"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", "Alphabet", "]"}]}], "}"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.4098516216871586`*^9, 3.409851662846342*^9}}], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"\<\"A\"\>", "\[Rule]", "0"}], ",", RowBox[{"\<\"B\"\>", "\[Rule]", "1"}], ",", RowBox[{"\<\"C\"\>", "\[Rule]", "2"}], ",", RowBox[{"\<\"D\"\>", "\[Rule]", "3"}], ",", RowBox[{"\<\"E\"\>", "\[Rule]", "4"}], ",", RowBox[{"\<\"F\"\>", "\[Rule]", "5"}], ",", RowBox[{"\<\"G\"\>", "\[Rule]", "6"}], ",", RowBox[{"\<\"H\"\>", "\[Rule]", "7"}], ",", RowBox[{"\<\"I\"\>", "\[Rule]", "8"}], ",", RowBox[{"\<\"J\"\>", "\[Rule]", "9"}], ",", RowBox[{"\<\"K\"\>", "\[Rule]", "10"}], ",", RowBox[{"\<\"L\"\>", "\[Rule]", "11"}], ",", RowBox[{"\<\"M\"\>", "\[Rule]", "12"}], ",", RowBox[{"\<\"N\"\>", "\[Rule]", "13"}], ",", RowBox[{"\<\"O\"\>", "\[Rule]", "14"}], ",", RowBox[{"\<\"P\"\>", "\[Rule]", "15"}], ",", RowBox[{"\<\"Q\"\>", "\[Rule]", "16"}], ",", RowBox[{"\<\"R\"\>", "\[Rule]", "17"}], ",", RowBox[{"\<\"S\"\>", "\[Rule]", "18"}], ",", RowBox[{"\<\"T\"\>", "\[Rule]", "19"}], ",", RowBox[{"\<\"U\"\>", "\[Rule]", "20"}], ",", RowBox[{"\<\"V\"\>", "\[Rule]", "21"}], ",", RowBox[{"\<\"W\"\>", "\[Rule]", "22"}], ",", RowBox[{"\<\"X\"\>", "\[Rule]", "23"}], ",", RowBox[{"\<\"Y\"\>", "\[Rule]", "24"}], ",", RowBox[{"\<\"Z\"\>", "\[Rule]", "25"}]}], "}"}]], "Output", CellChangeTimes->{3.4099139642771854`*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"NumbersToLetters", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"i", "-", "1"}], "\[Rule]", RowBox[{"Alphabet", "[", RowBox[{"[", "i", "]"}], "]"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", "Alphabet", "]"}]}], "}"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.4098516635473504`*^9, 3.409851664308445*^9}, { 3.4098517739561105`*^9, 3.4098518044399443`*^9}}], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"0", "\[Rule]", "\<\"A\"\>"}], ",", RowBox[{"1", "\[Rule]", "\<\"B\"\>"}], ",", RowBox[{"2", "\[Rule]", "\<\"C\"\>"}], ",", RowBox[{"3", "\[Rule]", "\<\"D\"\>"}], ",", RowBox[{"4", "\[Rule]", "\<\"E\"\>"}], ",", RowBox[{"5", "\[Rule]", "\<\"F\"\>"}], ",", RowBox[{"6", "\[Rule]", "\<\"G\"\>"}], ",", RowBox[{"7", "\[Rule]", "\<\"H\"\>"}], ",", RowBox[{"8", "\[Rule]", "\<\"I\"\>"}], ",", RowBox[{"9", "\[Rule]", "\<\"J\"\>"}], ",", RowBox[{"10", "\[Rule]", "\<\"K\"\>"}], ",", RowBox[{"11", "\[Rule]", "\<\"L\"\>"}], ",", RowBox[{"12", "\[Rule]", "\<\"M\"\>"}], ",", RowBox[{"13", "\[Rule]", "\<\"N\"\>"}], ",", RowBox[{"14", "\[Rule]", "\<\"O\"\>"}], ",", RowBox[{"15", "\[Rule]", "\<\"P\"\>"}], ",", RowBox[{"16", "\[Rule]", "\<\"Q\"\>"}], ",", RowBox[{"17", "\[Rule]", "\<\"R\"\>"}], ",", RowBox[{"18", "\[Rule]", "\<\"S\"\>"}], ",", RowBox[{"19", "\[Rule]", "\<\"T\"\>"}], ",", RowBox[{"20", "\[Rule]", "\<\"U\"\>"}], ",", RowBox[{"21", "\[Rule]", "\<\"V\"\>"}], ",", RowBox[{"22", "\[Rule]", "\<\"W\"\>"}], ",", RowBox[{"23", "\[Rule]", "\<\"X\"\>"}], ",", RowBox[{"24", "\[Rule]", "\<\"Y\"\>"}], ",", RowBox[{"25", "\[Rule]", "\<\"Z\"\>"}]}], "}"}]], "Output", CellChangeTimes->{3.409913969624875*^9}] }, Open ]], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"AffineCipher", "[", RowBox[{"message_", ",", "a_", ",", "b_"}], "]"}], ":=", RowBox[{"(", "\[IndentingNewLine]", RowBox[{"StringJoin", "[", RowBox[{"ReplaceAll", "[", RowBox[{ RowBox[{"Mod", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"ReplaceAll", "[", RowBox[{ RowBox[{"Characters", "[", "message", "]"}], ",", "LettersToNumbers"}], "]"}], "*", "a"}], "+", "b"}], ",", RowBox[{"Length", "[", "Alphabet", "]"}]}], "]"}], ",", "NumbersToLetters"}], "]"}], "]"}], ")"}]}], ";"}]], "Input", CellChangeTimes->{{3.409851807784754*^9, 3.409851873429146*^9}, { 3.409852053117525*^9, 3.4098520535882015`*^9}}], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"AffineDecipher", "[", RowBox[{"message_", ",", "a_", ",", "b_"}], "]"}], ":=", RowBox[{"(", "\[IndentingNewLine]", RowBox[{"StringJoin", "[", RowBox[{"ReplaceAll", "[", RowBox[{ RowBox[{"Mod", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"ReplaceAll", "[", RowBox[{ RowBox[{"Characters", "[", "message", "]"}], ",", "LettersToNumbers"}], "]"}], "-", "b"}], ")"}], "*", RowBox[{"PowerMod", "[", RowBox[{"a", ",", RowBox[{"-", "1"}], ",", RowBox[{"Length", "[", "Alphabet", "]"}]}], "]"}]}], ",", RowBox[{"Length", "[", "Alphabet", "]"}]}], "]"}], ",", "NumbersToLetters"}], "]"}], "]"}], ")"}]}], ";"}]], "Input", CellChangeTimes->{{3.409851876213149*^9, 3.409851947876195*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"FormatString", "[", "str_", "]"}], ":=", RowBox[{"StringReplace", "[", RowBox[{ RowBox[{"ToUpperCase", "[", "str", "]"}], ",", RowBox[{ RowBox[{"Except", "[", RowBox[{"CharacterRange", "[", RowBox[{"\"\\"", ",", "\"\\""}], "]"}], "]"}], "\[Rule]", "\"\<\>\""}]}], "]"}]}]], "Input"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"PowerMod", "[", RowBox[{"5", ",", RowBox[{"-", "1"}], ",", "26"}], "]"}]], "Input", CellChangeTimes->{{3.4098520698816304`*^9, 3.409852074297981*^9}}], Cell[BoxData["21"], "Output", CellChangeTimes->{3.4098520748387585`*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Mod", "[", RowBox[{ RowBox[{"5", "*", "21"}], ",", "26"}], "]"}]], "Input", CellChangeTimes->{{3.409852085113533*^9, 3.4098520894097104`*^9}}], Cell[BoxData["1"], "Output", CellChangeTimes->{3.4098520897201567`*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"LinearSolve", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"4", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"19", ",", "1"}], "}"}]}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", "5"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.409911566990056*^9, 3.409911616861768*^9}, { 3.4099117014734335`*^9, 3.4099117401190033`*^9}, {3.409912071946147*^9, 3.409912093827611*^9}, {3.409912268148272*^9, 3.409912268618949*^9}, { 3.4099123843553696`*^9, 3.409912409331283*^9}, {3.4099963114791203`*^9, 3.409996318767284*^9}}], Cell[BoxData[ RowBox[{"{", RowBox[{ FractionBox["1", "5"], ",", FractionBox["6", "5"]}], "}"}]], "Output", CellChangeTimes->{ 3.4099117550604877`*^9, {3.4099120790864143`*^9, 3.409912094418461*^9}, 3.409912270051008*^9, {3.4099123854469395`*^9, 3.4099124101124067`*^9}, 3.4099963196237993`*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"PowerMod", "[", RowBox[{"5", ",", RowBox[{"-", "1"}], ",", "26"}], "]"}]], "Input", CellChangeTimes->{{3.409912096871989*^9, 3.409912151800973*^9}, { 3.4099122185870066`*^9, 3.4099122741969695`*^9}, {3.40999632378179*^9, 3.409996324046531*^9}, {3.409996416418655*^9, 3.409996428042305*^9}}], Cell[BoxData["21"], "Output", CellChangeTimes->{3.409996428447418*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"21", "*", "1"}]], "Input", CellChangeTimes->{{3.409912147574896*^9, 3.4099121537037086`*^9}, { 3.409912239326829*^9, 3.4099122451552095`*^9}, {3.409996328360252*^9, 3.409996331428133*^9}}], Cell[BoxData["21"], "Output", CellChangeTimes->{3.409996332066626*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"6", "*", "21"}]], "Input", CellChangeTimes->{{3.4099963366762342`*^9, 3.4099963388097353`*^9}}], Cell[BoxData["126"], "Output", CellChangeTimes->{3.4099964336983166`*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Mod", "[", RowBox[{"126", ",", "26"}], "]"}]], "Input", CellChangeTimes->{ 3.409996339635104*^9, {3.4099963903043957`*^9, 3.409996394682741*^9}}], Cell[BoxData["22"], "Output", CellChangeTimes->{3.4099963953683186`*^9}] }, Open ]], Cell[BoxData[ RowBox[{"(*", RowBox[{ "If", " ", "your", " ", "denominator", " ", "comes", " ", "out", " ", "to", " ", "be", " ", "2", " ", "or", " ", "13", " ", "you", " ", "can", " ", "be", " ", "sure", " ", "that", " ", "you", " ", "have", " ", "made", " ", "a", " ", RowBox[{"mistake", "!"}], "\[IndentingNewLine]", "Your", " ", "PowerMod", " ", "output", " ", "is", " ", "the", " ", "value", " ", "of", " ", "\"\\"", " ", "in", " ", "the", " ", "Affine", " ", RowBox[{"Cipher", ".", " ", "To"}], " ", "get", " ", "the", " ", "value", " ", "of", " ", "\"\\"", " ", "multiply", " ", "the", " ", "numerator", " ", "of", " ", "the", " ", "second", " ", "fraction", " ", "output", " ", "by", " ", "\"\\"", " ", "and", " ", "evalate", " ", "this", " ", "product", " ", "Mod", " ", "26."}], "*)"}]], "Input", CellChangeTimes->{{3.4099124971675854`*^9, 3.409912523315184*^9}, { 3.4099152646169825`*^9, 3.4099152866887197`*^9}, {3.4099964532372665`*^9, 3.4099965194562135`*^9}, {3.4099965595632987`*^9, 3.4099966646213193`*^9}}] }, WindowSize->{615, 540}, WindowMargins->{{32, Automatic}, {63, Automatic}}, FrontEndVersion->"6.0 for Microsoft Windows (32-bit) (June 19, 2007)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[590, 23, 205, 4, 31, "Input"], Cell[798, 29, 587, 9, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[1422, 43, 415, 11, 31, "Input"], Cell[1840, 56, 1361, 29, 69, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[3238, 90, 468, 12, 31, "Input"], Cell[3709, 104, 1359, 29, 69, "Output"] }, Open ]], Cell[5083, 136, 779, 20, 92, "Input"], Cell[5865, 158, 929, 24, 132, "Input"], Cell[6797, 184, 367, 10, 52, "Input"], Cell[CellGroupData[{ Cell[7189, 198, 182, 4, 31, "Input"], Cell[7374, 204, 73, 1, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[7484, 210, 173, 4, 31, "Input"], Cell[7660, 216, 72, 1, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[7769, 222, 608, 15, 31, "Input"], Cell[8380, 239, 316, 8, 45, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[8733, 252, 327, 6, 31, "Input"], Cell[9063, 260, 71, 1, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[9171, 266, 218, 4, 31, "Input"], Cell[9392, 272, 71, 1, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[9500, 278, 120, 2, 31, "Input"], Cell[9623, 282, 74, 1, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[9734, 288, 175, 4, 31, "Input"], Cell[9912, 294, 73, 1, 30, "Output"] }, Open ]], Cell[10000, 298, 1092, 17, 132, "Input"] } ] *) (* End of internal cache information *)