(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 10.2' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 158, 7] NotebookDataLength[ 39857, 1124] NotebookOptionsPosition[ 37040, 1028] NotebookOutlinePosition[ 37448, 1046] CellTagsIndexPosition[ 37405, 1043] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell[TextData[{ "Cryptography\n", StyleBox["Cryptology (Greek \[OpenCurlyDoubleQuote]kryptos\ \[CloseCurlyDoubleQuote] = hidden, secret, \[OpenCurlyDoubleQuote]logos\ \[CloseCurlyDoubleQuote]= study, science)\nCryptography (\ \[OpenCurlyDoubleQuote]kryptos\[CloseCurlyDoubleQuote]=secret, \ \[OpenCurlyDoubleQuote]graphein\[CloseCurlyDoubleQuote]=writing)", FontSize->18, FontColor->GrayLevel[0]] }], "Title", CellChangeTimes->{{3.655672945408936*^9, 3.655673180513982*^9}, 3.6561344348965673`*^9}], Cell[CellGroupData[{ Cell["Definition: ", "Section", CellChangeTimes->{{3.655673316214323*^9, 3.6556734132644873`*^9}, { 3.655673475661751*^9, 3.655673475665059*^9}, {3.655675468021047*^9, 3.655675596696786*^9}, {3.65567596610952*^9, 3.655675966746636*^9}, { 3.6561344227122393`*^9, 3.656134425411859*^9}, 3.65613460824609*^9, { 3.656134648162128*^9, 3.6561346538024817`*^9}}, TextJustification->1.], Cell[CellGroupData[{ Cell["\<\ Cryptography is the study of hiding information. Cryptography is the science \ of concealing the content of communication between parties, where the channel \ between them is controlled in some way by an unfriendly third party.\ \>", "Subsection", CellChangeTimes->{{3.65613462135196*^9, 3.656134628805244*^9}}, TextJustification->1., FontColor->GrayLevel[0]], Cell[BoxData[ GraphicsBox[{ {FaceForm[RGBColor[1, 1, 0.4]], RectangleBox[{0.1480968474850685, 0.8665679057464064}, {0.4536524030406241, 0.7304567946352953}, RoundingRadius->0.]}, StyleBox[InsetBox[Cell["Alice", GeneratedCell->False, CellAutoOverwrite->False, CellBaseline->Baseline, TextAlignment->Center, TextJustification->0], {0.24151510650842303`, 0.7709829560239398}, { Left, Baseline}, Alignment->{Left, Top}], FontSize->19, FontWeight->Bold, Background->RGBColor[1, 1, 0.4]], {AbsoluteThickness[1], StrokeForm[{GrayLevel[0.], Opacity[1.]}], EdgeForm[{ GrayLevel[0.], Opacity[1.]}], EdgeForm[None], FaceForm[RGBColor[ 1, 0.984955, 0.0643778]], ArrowBox[{{0.4554526850744445, 0.7875414926874938}, {0.9414597482323608, 0.7891606611933221}}]}, {FaceForm[RGBColor[1, 1, 0.4]], RectangleBox[{0.9459534825456406, 0.8587028326454949}, {1.251509038101196, 0.7225917215343838}, RoundingRadius->0.]}, StyleBox[InsetBox[Cell["Bob", GeneratedCell->False, CellAutoOverwrite->False, CellBaseline->Baseline, TextAlignment->Center, TextJustification->0], {1.0483143217172115`, 0.7716364349690423}, { Left, Baseline}, Alignment->{Left, Top}], FontSize->19, FontWeight->Bold, Background->RGBColor[1, 1, 0.4]], StyleBox[InsetBox[ StyleBox[Cell["Eve", GeneratedCell->False, CellAutoOverwrite->False, CellBaseline->Baseline, TextAlignment->Left], TextAlignment->Center, TextJustification->0, FontWeight->Bold, Background->GrayLevel[1.]], {0.6586385154196108, 0.8471647057342799}, { Left, Baseline}, Alignment->{Left, Top}], FontSize->22, FontColor->RGBColor[1, 0, 0]], {AbsoluteThickness[1], StrokeForm[{GrayLevel[0.], Opacity[1.]}], EdgeForm[{ GrayLevel[0.], Opacity[1.]}], EdgeForm[None], LineBox[{{0.28538615996327155`, 0.5319859629573938}, {1.1023944375001897`, 0.5317042850234932}}]}, {AbsoluteThickness[1], StrokeForm[{GrayLevel[0.], Opacity[1.]}], EdgeForm[{ RGBColor[0., 0., 0.], Opacity[1.], AbsoluteThickness[1]}], EdgeForm[None], FaceForm[RGBColor[1, 0.984955, 0.0643778]], ArrowBox[{{0.2815018638022697, 0.5322676408912942}, {0.2815018638022697, 0.7219642256331723}}]}, {AbsoluteThickness[1], StrokeForm[{GrayLevel[0.], Opacity[1.]}], EdgeForm[{ RGBColor[0., 0., 0.], Opacity[1.], AbsoluteThickness[1]}], EdgeForm[None], FaceForm[RGBColor[1, 0.984955, 0.0643778]], ArrowBox[{{1.1012032466409463`, 0.5301080962674384}, {1.1012032466409463`, 0.7198046810093165}}]}, StyleBox[InsetBox[ StyleBox[Cell["Cipher (cryptosystem)", GeneratedCell->False, CellAutoOverwrite->False, CellBaseline->Baseline, TextAlignment->Left], TextAlignment->Center, TextJustification->0, FontWeight->Bold, Background->GrayLevel[ 1.]], {0.42321302193913657`, 0.4391310598018402}, {Left, Baseline}, Alignment->{Left, Top}], FontSize->17, FontSlant->"Italic"], StyleBox[ InsetBox["", {0.2415151065084231, 0.3004190994338287}, {Left, Baseline}, Alignment->{Left, Top}], FontSize->17, FontWeight->Bold, FontSlant->"Italic"], StyleBox[InsetBox[ StyleBox[Cell["Decryption", GeneratedCell->False, CellAutoOverwrite->False, CellBaseline->Baseline, TextAlignment->Left], TextAlignment->Center, TextJustification->0, FontWeight->Bold, Background->GrayLevel[ 1.]], {0.8846426043878275, 0.30183452760084917`}, {Left, Baseline}, Alignment->{Left, Top}], FontSize->17, FontSlant->"Italic"], InsetBox[ StyleBox[Cell["plaintext \[Rule] ciphertext", GeneratedCell->False, CellAutoOverwrite->False, CellBaseline->Baseline, TextAlignment->Left], FontSize->17, FontWeight->Bold, FontSlant->"Italic", Background->GrayLevel[ 1.]], {0.15226038645263884`, 0.22576810649527213`}, {Left, Baseline}, Alignment->{Left, Top}], InsetBox[ StyleBox[Cell["ciphertext \[Rule] plaintext", GeneratedCell->False, CellAutoOverwrite->False, CellBaseline->Baseline, TextAlignment->Left], FontSize->17, FontWeight->Bold, FontSlant->"Italic", Background->GrayLevel[1.]], {0.7774215471525552, 0.22409984605279631`}, { Left, Baseline}, Alignment->{Left, Top}], StyleBox[InsetBox[ StyleBox[Cell["Encryption", GeneratedCell->False, CellAutoOverwrite->False, CellBaseline->Baseline, TextAlignment->Left], TextAlignment->Center, TextJustification->0, FontWeight->Bold, Background->GrayLevel[ 1.]], {0.24151510650842295`, 0.3018345276008494}, { Left, Baseline}, {0.232838400145524, 0.05691605336890588}, {{1., 0.}, { 0., 1.}}, Alignment->{Left, Top}], FontSize->17, FontSlant->"Italic"]}, ContentSelectable->True, ImagePadding->{{0., 0.}, {0., 0.}}, ImageSize->{493.2734375, 368.}, PlotRange->{{0., 1.3333333333333335`}, {0., 1.}}, PlotRangePadding->Automatic]], "Input", CellChangeTimes->{{3.655673668745167*^9, 3.6556736734765177`*^9}, { 3.6556737088263493`*^9, 3.65567371622364*^9}, {3.6556738935727243`*^9, 3.655673925586833*^9}, {3.655673999724197*^9, 3.655674003930023*^9}, 3.6556741429562674`*^9, 3.655674186089778*^9, {3.655674219219914*^9, 3.6556742286916857`*^9}, {3.655674407638921*^9, 3.655674434099668*^9}, { 3.655674535259656*^9, 3.655674538363682*^9}, {3.6556746106685343`*^9, 3.6556746248923388`*^9}, {3.655674686466731*^9, 3.6556747288789377`*^9}, { 3.655674769111513*^9, 3.6556748201835318`*^9}}] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Cipher (Cryptosystem)", "Section", CellChangeTimes->{{3.655675025096904*^9, 3.655675034467052*^9}}], Cell[TextData[{ "- ", StyleBox["a pair of algorithms that create the", FontColor->GrayLevel[0]], " encryption from plaintext to ciphertext, ", StyleBox["and the reversing process", FontColor->GrayLevel[0]], " (decryption from ciphertext to plaintext)\n- ", StyleBox["the algorithms have a secret parameter called", FontColor->GrayLevel[0]], " key ", StyleBox["(ideally known only to Alice and Bob, and which changes from one \ message exchange to the next).", FontColor->GrayLevel[0]] }], "Subsection", CellChangeTimes->{{3.655674893299843*^9, 3.655674983166748*^9}, { 3.655675039241138*^9, 3.655675114826076*^9}, 3.6556751773814774`*^9, 3.655676154328599*^9, {3.656133229795458*^9, 3.656133237456368*^9}}, TextJustification->1.] }, Open ]], Cell[CellGroupData[{ Cell["Cryptanalysis", "Section", CellChangeTimes->{{3.655675025096904*^9, 3.655675034467052*^9}, { 3.655675150056581*^9, 3.655675159035742*^9}}], Cell[TextData[{ "- ", StyleBox["study of methods for obtaining the meaning of encrypted \ information without access to the key normally required to do so (study of \ how to crack encryption algorithms).", FontColor->GrayLevel[0]], "\n- Eve (Eavesdropper, Enemy, Evil third party) ", StyleBox["intercepts the ciphertext. She may know the cipher (the algorithms \ for encryption, decryption, but does not know the key). Eve can have a", FontColor->GrayLevel[0]], " \[OpenCurlyDoubleQuote]passive role\[CloseCurlyDoubleQuote] ", StyleBox["(attemps to recover the plaintext, or to deduce the key), or an", FontColor->GrayLevel[0]], " \[OpenCurlyDoubleQuote]active role\[CloseCurlyDoubleQuote] ", StyleBox["(alter the message sent over the channel). ", FontColor->GrayLevel[0]] }], "Subsection", CellChangeTimes->{{3.655674893299843*^9, 3.655674983166748*^9}, { 3.655675039241138*^9, 3.655675114826076*^9}, {3.655675169946849*^9, 3.6556754407103577`*^9}, {3.655675736490849*^9, 3.65567574434317*^9}, { 3.656133270134527*^9, 3.6561332788035316`*^9}}, TextJustification->1.] }, Open ]], Cell[CellGroupData[{ Cell["History of Cryptography", "Section", CellChangeTimes->{{3.655677594324307*^9, 3.6556776079268703`*^9}}], Cell[TextData[{ "Classical Crytopgraphy \n", StyleBox["- simple methods of encryption and decryption using only pen and \ paper an perhaps simple mechanical aids.\n- non-standard hieroglyphs carved \ into monuments from the Old Kingdom of Egypt (1900 BC), \n- clay tablets from \ Mesopotamia (1500 BC )\n- Hebrew scholars - simple monoalphabetic \ substitution ciphers (500-600 BC) (replace first alphabet letter with last, \ second letter with next to last, ...)\n- Ancient Greeks\n - transposition \ ciphers (500 BC) (Spartan Scytale - thin strip of parchment wrapped around a \ cylindrical rod called scytale; the diameter of the scytale was known only by \ the sender and the receiver) \n - Polybius square (205-123 BC) (pairs of \ numbers substitute for letters\n- Romans - Caesar Cipher (50 BC, Gallic Wars) \ - Shift ciphers +k\n", FontColor->GrayLevel[0]] }], "Subsection", CellChangeTimes->{{3.655677613443364*^9, 3.655677655222932*^9}, { 3.6556776900254517`*^9, 3.6556777422169*^9}, {3.6556777824385843`*^9, 3.65567788262411*^9}, {3.655677935523059*^9, 3.655678113018197*^9}, { 3.655678145859453*^9, 3.6556782710776243`*^9}, 3.655679824693231*^9, { 3.655680074722006*^9, 3.655680084240782*^9}, {3.655680141445714*^9, 3.6556801427098713`*^9}, {3.655680259760624*^9, 3.6556802960607643`*^9}, { 3.656133363082263*^9, 3.656133393161469*^9}}, TextJustification->1.], Cell[TextData[{ "Medieval Cryptography \n\n", StyleBox["- polyalphabetic substitution\n- Alberti\[CloseCurlyQuote]s Cipher \ Disk\n- Vig\[EGrave]nere cipher (~16th century) correspondents agree on a \ keyword,", FontColor->GrayLevel[0]], " ", StyleBox["which controls letter substitution depending on which letter of \ the key word is used.\n", FontColor->GrayLevel[0]] }], "Subsection", CellFrame->{{0, 0}, {0, 2}}, CellChangeTimes->{{3.655678303222743*^9, 3.655678316836789*^9}, { 3.655679642992481*^9, 3.655679697420804*^9}, {3.655679732428117*^9, 3.655679746534357*^9}, {3.655679779508684*^9, 3.6556798153206997`*^9}, { 3.655680091444796*^9, 3.6556801268648357`*^9}, {3.655680184534327*^9, 3.65568020735211*^9}, 3.656133350276567*^9, 3.656133387151228*^9}], Cell["WW1 (ADFGVX) ", "Subsection", CellFrame->{{0, 0}, {0, 2}}, CellChangeTimes->{{3.656133145011795*^9, 3.656133171549947*^9}}], Cell[TextData[StyleBox["- correspondents knew an encoding table for letters & \ ciphers and a keyword; letters A, D, F, G, V, X were chosen deliberately \ because they sound very differently when transmitted via Morse code\n- to \ encipher: the plaintext is coded using the letters A,D, F, G, V, X via the \ chart. The resulting pre-ciphertext is then enciphered using a keyword \ columnar transposition cipher.\n- to decipher: reverse the transposition and \ decode using the chart.", FontColor->GrayLevel[0]]], "Subsection", CellChangeTimes->{{3.6556803600009527`*^9, 3.6556803600019817`*^9}, { 3.6556804689688663`*^9, 3.65568047059203*^9}, {3.655680529766429*^9, 3.6556806081328793`*^9}, {3.65568085373372*^9, 3.655680900923704*^9}, { 3.655682015359901*^9, 3.6556821482831097`*^9}, {3.6561331267850847`*^9, 3.656133136509995*^9}, {3.656133176531041*^9, 3.656133178908285*^9}}, FontColor->GrayLevel[0]], Cell[BoxData[ RowBox[{GridBox[{ {"\[FilledCircle]", "A", "D", "F", "G", "V", "X"}, {"A", StyleBox["F", FontColor->GrayLevel[0]], StyleBox["L", FontColor->GrayLevel[0]], StyleBox["1", FontColor->GrayLevel[0]], StyleBox["A", FontColor->GrayLevel[0]], StyleBox["O", FontColor->GrayLevel[0]], StyleBox["2", FontColor->GrayLevel[0]]}, {"D", StyleBox["J", FontColor->GrayLevel[0]], StyleBox["D", FontColor->GrayLevel[0]], StyleBox["W", FontColor->GrayLevel[0]], StyleBox["3", FontColor->GrayLevel[0]], StyleBox["G", FontColor->GrayLevel[0]], StyleBox["U", FontColor->GrayLevel[0]]}, {"F", StyleBox["C", FontColor->GrayLevel[0]], StyleBox["I", FontColor->GrayLevel[0]], StyleBox["Y", FontColor->GrayLevel[0]], StyleBox["B", FontColor->GrayLevel[0]], StyleBox["4", FontColor->GrayLevel[0]], StyleBox["P", FontColor->GrayLevel[0]]}, {"G", StyleBox["R", FontColor->GrayLevel[0]], StyleBox["5", FontColor->GrayLevel[0]], StyleBox["Q", FontColor->GrayLevel[0]], StyleBox["8", FontColor->GrayLevel[0]], StyleBox["V", FontColor->GrayLevel[0]], StyleBox["E", FontColor->GrayLevel[0]]}, {"V", StyleBox["6", FontColor->GrayLevel[0]], StyleBox["K", FontColor->GrayLevel[0]], StyleBox["7", FontColor->GrayLevel[0]], StyleBox["Z", FontColor->GrayLevel[0]], StyleBox["M", FontColor->GrayLevel[0]], StyleBox["X", FontColor->GrayLevel[0]]}, {"X", StyleBox["S", FontColor->GrayLevel[0]], StyleBox["N", FontColor->GrayLevel[0]], StyleBox["H", FontColor->GrayLevel[0]], StyleBox["0", FontColor->GrayLevel[0]], StyleBox["T", FontColor->GrayLevel[0]], StyleBox["9", FontColor->GrayLevel[0]]} }, GridBoxDividers->{ "Columns" -> {True, {False}, True}, "ColumnsIndexed" -> {}, "Rows" -> {True, {False}, True}, "RowsIndexed" -> {}}], " ", GraphicsBox[ StyleBox[InsetBox[ StyleBox[Cell["\<\ plaintext: WE WILL WIN pre-ciphertext: DFGXDFFDADADDFFDXD \ \>", GeneratedCell->False, CellAutoOverwrite->False, CellBaseline->Baseline, TextAlignment->Left], FontWeight->Bold, Background->GrayLevel[ 1.]], {0.10869023853555523`, 0.5940588602711543}, {Left, Baseline}, Alignment->{Left, Top}], FontSize->18, FontColor->RGBColor[0.25098, 0, 0.501961]], ContentSelectable->True, ImagePadding->{{0., 0.}, {0., 0.}}, ImageSize->{263.078125, 206.}, PlotRange->{{0., 1.3333333333333335`}, {0., 1.}}, PlotRangePadding->Automatic], GridBox[{ { StyleBox["A", FontWeight->"Bold", FontColor->RGBColor[1, 0, 0]], StyleBox["R", FontWeight->"Bold", FontColor->RGBColor[1, 0, 0]], StyleBox["M", FontWeight->"Bold", FontColor->RGBColor[1, 0, 0]], StyleBox["S", FontWeight->"Bold", FontColor->RGBColor[1, 0, 0]]}, { StyleBox["1", FontColor->RGBColor[1, 0, 0]], StyleBox["2", FontColor->RGBColor[1, 0, 0]], StyleBox["3", FontColor->RGBColor[1, 0, 0]], StyleBox["4", FontColor->RGBColor[1, 0, 0]]}, { StyleBox["D", FontColor->GrayLevel[0]], StyleBox["F", FontColor->GrayLevel[0]], StyleBox["G", FontColor->GrayLevel[0]], StyleBox["X", FontColor->GrayLevel[0]]}, { StyleBox["D", FontColor->GrayLevel[0]], StyleBox["F", FontColor->GrayLevel[0]], StyleBox["F", FontColor->GrayLevel[0]], StyleBox["D", FontColor->GrayLevel[0]]}, { StyleBox["A", FontColor->GrayLevel[0]], StyleBox["D", FontColor->GrayLevel[0]], StyleBox["A", FontColor->GrayLevel[0]], StyleBox["D", FontColor->GrayLevel[0]]}, { StyleBox["D", FontColor->GrayLevel[0]], StyleBox["F", FontColor->GrayLevel[0]], StyleBox["F", FontColor->GrayLevel[0]], StyleBox["D", FontColor->GrayLevel[0]]}, { StyleBox["X", FontColor->GrayLevel[0]], StyleBox["D", FontColor->GrayLevel[0]], StyleBox["\[Placeholder]", FontColor->GrayLevel[0]], StyleBox["\[Placeholder]", FontColor->GrayLevel[0]]} }, GridBoxDividers->{ "Columns" -> {True, {False}, True}, "ColumnsIndexed" -> {}, "Rows" -> {True, {False}, True}, "RowsIndexed" -> {}}], " ", GraphicsBox[ StyleBox[InsetBox[ StyleBox[Cell["\<\ keyword: ARMS ciphertext: DDADX GFAF FFDFD XDDD\ \>", GeneratedCell->False, CellAutoOverwrite->False, CellBaseline->Baseline, TextAlignment->Left], FontWeight->Bold, Background->GrayLevel[ 1.]], {0.042653666395827336`, 0.6213254442800895}, {Left, Baseline}, Alignment->{Left, Top}], FontSize->18, FontColor->RGBColor[0.25098, 0, 0.501961]], ContentSelectable->True, ImageSize->{265.3046875, 198.}, PlotRange->{{0, 480/360}, {0, 1}}]}]], "Subsection", CellChangeTimes->{{3.655680660586761*^9, 3.6556808081114273`*^9}, { 3.6556809284343443`*^9, 3.6556809508456984`*^9}, {3.6556809905119953`*^9, 3.6556809961334257`*^9}, {3.65568110777227*^9, 3.6556811317909937`*^9}, { 3.655681181136058*^9, 3.655681238846161*^9}, {3.655681280478944*^9, 3.655681280943248*^9}, {3.655681371125609*^9, 3.655681378714295*^9}, { 3.655681430403372*^9, 3.6556814304034367`*^9}, 3.655681503838024*^9, { 3.655681580432674*^9, 3.6556817871956463`*^9}, {3.655681827215206*^9, 3.6556819283392773`*^9}, 3.6556819916950827`*^9, {3.655682075811728*^9, 3.655682081427494*^9}, 3.6556821612744303`*^9}], Cell[TextData[{ "WW2 \n", StyleBox["- cable and radio transmissions were encrypted\n- Enigma - \ cryptographic machine used by the Germans (Enigma accepted letters as \ keyboard input and implemented a polyalphabetic substitution cipher using an \ electro-mechanical rotor machine with rotating disks; it produced output by \ lighting electrical lamps beneath lettered windows )\n", FontColor->GrayLevel[0]] }], "Subsection", CellChangeTimes->{{3.6556822102538347`*^9, 3.655682432660624*^9}, { 3.6556825865720367`*^9, 3.655682603768626*^9}, 3.6561331884238787`*^9}, TextJustification->1.], Cell[TextData[{ "Modern Cryptography\n\n", StyleBox["- Ciphering operations are too complex to be made by hand; \ computers are needed. Complex ciphering can be obtained by composition of a \ certain number of simpler ciphering functions.", FontColor->GrayLevel[0]], "\n", StyleBox["- Claude Shanon (1949) established solid theoretical basis for \ cryptology and cryptanalysis (confusion/diffusion). \n Confusion - make the \ relation between the key and the ciphertext as complex as possible.\n \ Diffusion - data diffusion: changing one letter in the plaintext will change \ many letters in the ciphertext\n - key diffusion: changing \ even a tiny part of the key should change each bit (letter) in the ciphertext \ with a given probability. \n- ", FontColor->GrayLevel[0]], StyleBox["Symmetric Key Cryptography", FontWeight->"Bold", FontColor->GrayLevel[0]], StyleBox["\n - the sender and the receiver share the same key; the key is \ communicated separately over a different channel.\n - 1970 Data Encryption \ Standard (DES) symmetric block cipher\n - 2001 Advanced Encryption \ Standard (AES) \n AES and Triple DES (with 128, 256-bit keys) are used in \ banking, ATM transactions, e-commerce, industry, mobile communications\n \n\ - ", FontColor->GrayLevel[0]], StyleBox["Asymmetric (public) Key Cryptography", FontWeight->"Bold", FontColor->GrayLevel[0]], StyleBox["\n - new methods of distributing cryptographic keys (no secure \ channel is needed)\n - asymmetric key algorithms use a pair of \ mathematically related keys (one public, one private), each of which decrypts \ the encryption performed by the other; the private key cannot be deduced from \ the public key by any computational method other than trial and error. \ Cracking the encrypted message without the private key requires a major \ computational task. \n - based on number theory\n - Digital Signatures, \ Public Certificates, Authentication Protocols (SSL, SSH)\n - E-banking \ (secure bank transfers), E-commerce (cards), protection against collection of \ personal data by various companies, PGP email encryption, Operating Systems, \ Cryptographic Protection of classified documents, etc. \n ", FontColor->GrayLevel[0]] }], "Subsection", CellFrame->{{0, 0}, {0, 2}}, CellChangeTimes->{{3.655682622455553*^9, 3.655682636120089*^9}, { 3.65568276781847*^9, 3.655682768619512*^9}, {3.6556828285462914`*^9, 3.655683102526792*^9}, {3.65568325469023*^9, 3.65568349231879*^9}, { 3.65568352501476*^9, 3.655683807132378*^9}, {3.655683881662526*^9, 3.655684037933963*^9}, {3.6556842303059196`*^9, 3.655684304959587*^9}, { 3.655684412864929*^9, 3.655684543848795*^9}, {3.655684664135729*^9, 3.65568473372325*^9}, {3.655684800841663*^9, 3.655684823126899*^9}, 3.656133375139233*^9, 3.656134171854871*^9}, TextJustification->1.] }, Open ]], Cell[CellGroupData[{ Cell["Example: The Caesar cipher", "Section", CellFrame->{{0, 0}, {0, 3}}, CellChangeTimes->{{3.624024961252336*^9, 3.6240249772458773`*^9}, { 3.656134154962784*^9, 3.656134160881372*^9}}], Cell[TextData[{ "One of the oldest cryptosystems is due to Julius Caesar. The Caesar cipher \ is defined over the alphabet {A,B,C, ..., Z}, encoded numerically as integer \ numbers between 0 and 25, {A\[RightArrow]0, B\[RightArrow]1, ..., Z", "\[RightArrow]", "25}. The key ", StyleBox["k ", FontWeight->"Bold"], "can be any integer between 0 and 25.", StyleBox[" ", FontWeight->"Bold"], "The cipher shifts each letter in the text cyclicly over k places.", StyleBox[" ", FontWeight->"Bold"], "The encoding function is ", Cell[BoxData[ FormBox[ StyleBox[ RowBox[{ RowBox[{ SubscriptBox["E", "k"], "(", "x", ")"}], "=", RowBox[{"x", "+", RowBox[{"k", " ", RowBox[{"(", RowBox[{"mod", " ", "26"}], ")"}]}]}]}], FontColor->RGBColor[1, 0, 0]], TraditionalForm]], FontWeight->"Bold"], " and the decoding function is ", Cell[BoxData[ FormBox[ StyleBox[ RowBox[{ RowBox[{ SubscriptBox["D", "k"], "(", "x", ")"}], "=", RowBox[{"x", "-", RowBox[{"k", " ", RowBox[{"(", RowBox[{"mod", " ", "26"}], ")"}]}]}]}], FontWeight->"Bold", FontColor->RGBColor[1, 0, 0]], TraditionalForm]]], ". The notation x mod 26 means the remainder of the division of x by 26. \n" }], "Subsubsection", CellChangeTimes->{{3.624025025433765*^9, 3.624025276690935*^9}, { 3.624025338678376*^9, 3.624025343797134*^9}, {3.6240253946837893`*^9, 3.624025455015478*^9}, {3.6240254894316797`*^9, 3.624025530367837*^9}, { 3.624025593398509*^9, 3.624025650368627*^9}, {3.656133457552837*^9, 3.656133534954854*^9}, 3.6561337553516407`*^9}, TextJustification->1., FontColor->GrayLevel[0]], Cell[CellGroupData[{ Cell["\<\ Define the Caeser cipher over integer numbers {0, 1, ..., 25}\ \>", "Subsection", CellFrame->{{0, 0}, {0, 2}}, CellChangeTimes->{{3.624025687745028*^9, 3.624025719795948*^9}, { 3.6561336198760242`*^9, 3.656133642685154*^9}}], Cell[BoxData[ RowBox[{"Clear", "[", RowBox[{"CaesarEncode", ",", " ", "CaesarDecode"}], "]"}]], "Input", CellChangeTimes->{{3.624026493127347*^9, 3.624026506630484*^9}}, FontSize->14], Cell[BoxData[{ RowBox[{ RowBox[{"CaesarEncode", "[", RowBox[{ RowBox[{"x_", " ", "?", "IntegerQ"}], ",", " ", "k_"}], "]"}], ":=", " ", RowBox[{"Mod", "[", RowBox[{ RowBox[{"x", "+", "k"}], ",", "26"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"CaesarDecode", "[", RowBox[{ RowBox[{"x_", " ", "?", "IntegerQ"}], ",", " ", "k_"}], "]"}], ":=", " ", RowBox[{"Mod", "[", RowBox[{ RowBox[{"x", "-", "k"}], ",", "26"}], "]"}]}]}], "Input", CellChangeTimes->{{3.6240257500371323`*^9, 3.6240257987200212`*^9}, { 3.624025831271524*^9, 3.624025842014024*^9}, 3.6240262221904793`*^9, { 3.624026317748263*^9, 3.6240263753323812`*^9}}, FontSize->16, Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData[{ RowBox[{ RowBox[{"SetAttributes", "[", RowBox[{"CaesarEncode", ",", " ", "Listable"}], "]"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"SetAttributes", "[", RowBox[{"CaesarDecode", ",", " ", "Listable"}], "]"}], ";"}]}], "Input", CellChangeTimes->{{3.6240264202656317`*^9, 3.624026437329265*^9}}, FontSize->16, Background->GrayLevel[0.85]], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{"Alphabet1", " ", "=", " ", RowBox[{"Table", "[", RowBox[{"i", ",", " ", RowBox[{"{", RowBox[{"i", ",", "0", ",", "25"}], "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"CaesarEncode", "[", RowBox[{"Alphabet1", ",", "3"}], "]"}], " "}]}], "Input", CellChangeTimes->{{3.624026455242509*^9, 3.624026473713085*^9}, { 3.624026568267642*^9, 3.624026627130677*^9}, {3.624026659287784*^9, 3.624026718879182*^9}, {3.656160245612598*^9, 3.656160248335806*^9}}, FontSize->16, Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData[ RowBox[{"{", RowBox[{ "0", ",", "1", ",", "2", ",", "3", ",", "4", ",", "5", ",", "6", ",", "7", ",", "8", ",", "9", ",", "10", ",", "11", ",", "12", ",", "13", ",", "14", ",", "15", ",", "16", ",", "17", ",", "18", ",", "19", ",", "20", ",", "21", ",", "22", ",", "23", ",", "24", ",", "25"}], "}"}]], "Output", CellChangeTimes->{ 3.6240264751636543`*^9, {3.624026516684729*^9, 3.624026519812101*^9}, { 3.624026563561178*^9, 3.624026585920252*^9}, {3.624026679418692*^9, 3.624026719831361*^9}}], Cell[BoxData[ RowBox[{"{", RowBox[{ "3", ",", "4", ",", "5", ",", "6", ",", "7", ",", "8", ",", "9", ",", "10", ",", "11", ",", "12", ",", "13", ",", "14", ",", "15", ",", "16", ",", "17", ",", "18", ",", "19", ",", "20", ",", "21", ",", "22", ",", "23", ",", "24", ",", "25", ",", "0", ",", "1", ",", "2"}], "}"}]], "Output", CellChangeTimes->{ 3.6240264751636543`*^9, {3.624026516684729*^9, 3.624026519812101*^9}, { 3.624026563561178*^9, 3.624026585920252*^9}, {3.624026679418692*^9, 3.624026719834441*^9}}] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ ButtonBox["ASCI", BaseStyle->"Hyperlink", ButtonData->{ URL["http://www.asciitable.com"], None}, ButtonNote->"http://www.asciitable.com"], " code of alphabet letters" }], "Subsection", CellFrame->{{0, 0}, {0, 2}}, CellChangeTimes->{{3.624026057560267*^9, 3.6240260674802113`*^9}, { 3.624032252678938*^9, 3.624032282152739*^9}}, FontSize->24], Cell[CellGroupData[{ Cell[TextData[{ StyleBox["The Mathematica functions", FontColor->GrayLevel[0]], StyleBox["ToCharacterCode[..]", FontWeight->"Bold"], " ", StyleBox["and", FontColor->GrayLevel[0]], " ", StyleBox["FromCharacterCode[..]", FontWeight->"Bold"], " ", StyleBox["convert symbols to their ASCI code and back (letter A has value \ 65, letter B has value 66, .... , letter a has value 97, letter b has value \ 98, etc.).", FontColor->GrayLevel[0]] }], "Subsubsection", CellChangeTimes->{{3.624026103247713*^9, 3.624026186203649*^9}, 3.624028572429536*^9}], Cell[BoxData[ RowBox[{"FromCharacterCode", "[", "65", "]"}]], "Input", CellChangeTimes->{{3.624028574409688*^9, 3.6240286236888237`*^9}, { 3.6240286843426247`*^9, 3.624028705508407*^9}, {3.624028771275779*^9, 3.624028779637504*^9}}, FontSize->14, Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData[ RowBox[{"FromCharacterCode", "[", RowBox[{"{", "97", "}"}], "]"}]], "Input", CellChangeTimes->{{3.624028574409688*^9, 3.624028635030342*^9}, { 3.624028782323032*^9, 3.624028783658811*^9}}, FontSize->14, Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData[ RowBox[{"ToCharacterCode", "[", "\"\\"", "]"}]], "Input", CellChangeTimes->{{3.6240287116725492`*^9, 3.6240287405630074`*^9}, { 3.624029458383568*^9, 3.6240294744289837`*^9}, {3.624029673477386*^9, 3.624029676130932*^9}}, FontSize->14, Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData[ RowBox[{"ToCharacterCode", "[", "\"\\"", "]"}]], "Input", CellChangeTimes->{{3.6240288020673513`*^9, 3.6240288063469887`*^9}}, FontSize->14, Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData[ RowBox[{"ToUpperCase", "[", "\"\\"", "]"}]], "Input", CellChangeTimes->{{3.6240298888027353`*^9, 3.624029897503586*^9}}, FontSize->14, Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData[ RowBox[{"ToCharacterCode", "[", RowBox[{"ToUpperCase", "[", "\"\\"", "]"}], "]"}]], "Input", CellChangeTimes->{{3.6240288020673513`*^9, 3.6240288063469887`*^9}, { 3.656160272278667*^9, 3.656160274547274*^9}}, FontSize->14, Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData[ RowBox[{" ", RowBox[{"Select", "[", RowBox[{ RowBox[{"{", RowBox[{"4", ",", "46", ",", "2"}], "}"}], ",", " ", RowBox[{ RowBox[{"(", RowBox[{"0", "<=", "#", "\[LessEqual]", "25"}], ")"}], "&"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.624031179811707*^9, 3.624031196282755*^9}}, FontSize->14, Background->RGBColor[0.87, 0.94, 1]] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Define the Caesar cipher over strings", "Subsection", CellFrame->{{0, 0}, {0, 2}}, CellChangeTimes->{{3.62402493148108*^9, 3.6240249388805037`*^9}, { 3.624026025881721*^9, 3.6240260366401997`*^9}}], Cell[CellGroupData[{ Cell["\<\ Encode and decode a given string using the simple encoding A=0, ... , Z=25 \ (stripping all other characters).\ \>", "Subsubsection", CellChangeTimes->{3.624030615904888*^9}], Cell[BoxData[ RowBox[{ RowBox[{"CaesarEncode", "[", RowBox[{ RowBox[{"x_", " ", "?", "StringQ"}], ",", " ", "k_"}], "]"}], ":=", " ", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"n", ",", "numerictext"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"numerictext", "=", RowBox[{ RowBox[{"ToCharacterCode", "[", RowBox[{"ToUpperCase", "[", "x", "]"}], "]"}], "-", "65"}]}], ";", "\[IndentingNewLine]", RowBox[{"numerictext", " ", "=", " ", RowBox[{"Select", "[", RowBox[{"numerictext", ",", " ", RowBox[{ RowBox[{"(", RowBox[{"0", "<=", "#", "\[LessEqual]", "25"}], ")"}], "&"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"n", " ", "=", " ", RowBox[{"Mod", "[", RowBox[{ RowBox[{"numerictext", "+", "k"}], ",", "26"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"FromCharacterCode", "[", RowBox[{"n", "+", "65"}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}]], "Input", CellChangeTimes->{{3.624028875192651*^9, 3.6240290431958923`*^9}, { 3.624029146934134*^9, 3.624029150990426*^9}, {3.624029241976156*^9, 3.624029247566894*^9}, {3.6240293468111877`*^9, 3.624029386520253*^9}, 3.624029584060322*^9, {3.624029709467526*^9, 3.624029740498232*^9}, { 3.624029794693529*^9, 3.624029819155923*^9}, 3.624030642107463*^9, { 3.6240307336864157`*^9, 3.624030843313272*^9}, {3.62403088762917*^9, 3.624030905540133*^9}, {3.624031018135253*^9, 3.624031025782547*^9}, { 3.6240316024618397`*^9, 3.624031624017668*^9}, {3.624031668889161*^9, 3.624031676060876*^9}}, FontSize->16, Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData[ RowBox[{ RowBox[{"CaesarDecode", "[", RowBox[{ RowBox[{"x_", " ", "?", "StringQ"}], ",", " ", "k_"}], "]"}], ":=", " ", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"n", ",", "numerictext"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"numerictext", " ", "=", " ", RowBox[{ RowBox[{"ToCharacterCode", "[", "x", "]"}], "-", "65"}]}], ";", "\[IndentingNewLine]", RowBox[{"n", " ", "=", " ", RowBox[{"Mod", "[", RowBox[{ RowBox[{"numerictext", "-", "k"}], ",", "26"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"FromCharacterCode", "[", RowBox[{"n", "+", "65"}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}]], "Input", CellChangeTimes->{{3.624032008355279*^9, 3.624032090512413*^9}}, FontSize->16, Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData[ RowBox[{"?", "CaesarEncode"}]], "Input", CellChangeTimes->{{3.624029077997566*^9, 3.62402908517857*^9}}, FontSize->16], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{"plain", " ", "=", " ", "\"\\""}], ";"}], "\[IndentingNewLine]", RowBox[{"CaesarEncode", "[", RowBox[{"plain", ",", "2"}], "]"}]}], "Input", CellChangeTimes->{{3.624029109369287*^9, 3.624029140510683*^9}, { 3.624029214544141*^9, 3.624029298890414*^9}, {3.624030537411916*^9, 3.624030537755417*^9}, 3.624030965789339*^9, {3.624031558622876*^9, 3.624031566894158*^9}, {3.624031906221911*^9, 3.624031916911497*^9}}, FontSize->16, Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData["\<\"VARGAQWTVGZVJGTG\"\>"], "Output", CellChangeTimes->{ 3.6240292996872473`*^9, {3.624029351515183*^9, 3.624029353783431*^9}, 3.6240294361100483`*^9, 3.624029763315078*^9, 3.624030538647773*^9, 3.624030966873283*^9, 3.624031061002823*^9, 3.624031460454143*^9, { 3.6240315604264174`*^9, 3.6240315672981157`*^9}, {3.6240316074580708`*^9, 3.624031627278372*^9}, 3.6240316882077827`*^9, 3.6240319403251333`*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"CaesarDecode", "[", RowBox[{"\"\\"", ",", "2"}], "]"}]], "Input", CellChangeTimes->{{3.62403212939228*^9, 3.624032168077726*^9}}, FontSize->16, Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData["\<\"TYPEYOURTEXTHERE\"\>"], "Output", CellChangeTimes->{{3.624032150008956*^9, 3.624032169792116*^9}}] }, Open ]] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Cryptanalysis of the Caesar cipher", "Subsection", CellFrame->{{0, 0}, {0, 2}}, CellChangeTimes->{{3.624032306512216*^9, 3.624032321942761*^9}}], Cell["\<\ An easy way to break the ciphersystem is to try out all possible keys. This \ method is called exhaustive key search, or brute-force approach. \ \>", "Subsubsection", CellChangeTimes->{{3.624032340640184*^9, 3.624032381591173*^9}, { 3.656134298636689*^9, 3.656134315605747*^9}}, FontColor->GrayLevel[0]], Cell[CellGroupData[{ Cell[TextData[{ "Example : The text \[OpenCurlyDoubleQuote]", StyleBox["TFEXIRKLCRKZFEJPFLALJKSIFBVPFLIWZIJKTZGYVI", FontColor->GrayLevel[0]], "\[CloseCurlyDoubleQuote] has been encoded using a Caesar cipher with some \ unknown key k. Decrypt it." }], "Subsubsection", CellChangeTimes->{{3.624032446102212*^9, 3.624032455645838*^9}, { 3.624032513168894*^9, 3.624032625404745*^9}, {3.656134804391982*^9, 3.6561348103356543`*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{ "ciphertext", " ", "=", "\"\\""}], ";"}], "\[IndentingNewLine]", RowBox[{"Table", "[", RowBox[{ RowBox[{"CaesarDecode", "[", RowBox[{"ciphertext", ",", " ", "k"}], "]"}], ",", " ", RowBox[{"{", RowBox[{"k", ",", "0", ",", "25"}], "}"}]}], "]"}]}], "Input", CellChangeTimes->{{3.62403260842509*^9, 3.624032698853478*^9}, { 3.624032741895208*^9, 3.624032762786021*^9}}, FontSize->18, Background->RGBColor[0.87, 0.94, 1]] }, Open ]] }, Open ]] }, Open ]] }, Open ]] }, WindowSize->{1280, 682}, WindowMargins->{{22, Automatic}, {Automatic, 0}}, PrintingCopies->1, PrintingPageRange->{1, Automatic}, FrontEndVersion->"10.2 for Mac OS X x86 (32-bit, 64-bit Kernel) (July 29, \ 2015)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[580, 22, 509, 11, 144, "Title"], Cell[CellGroupData[{ Cell[1114, 37, 393, 6, 64, "Section"], Cell[CellGroupData[{ Cell[1532, 47, 372, 7, 69, "Subsection"], Cell[1907, 56, 5783, 149, 383, "Input"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[7739, 211, 106, 1, 64, "Section"], Cell[7848, 214, 756, 18, 119, "Subsection"] }, Open ]], Cell[CellGroupData[{ Cell[8641, 237, 147, 2, 64, "Section"], Cell[8791, 241, 1095, 21, 144, "Subsection"] }, Open ]], Cell[CellGroupData[{ Cell[9923, 267, 110, 1, 64, "Section"], Cell[10036, 270, 1405, 22, 319, "Subsection"], Cell[11444, 294, 784, 16, 196, "Subsection"], Cell[12231, 312, 131, 2, 46, "Subsection"], Cell[12365, 316, 917, 13, 136, "Subsection"], Cell[13285, 331, 5911, 206, 220, "Subsection"], Cell[19199, 539, 597, 11, 161, "Subsection"], Cell[19799, 552, 2888, 50, 621, "Subsection"] }, Open ]], Cell[CellGroupData[{ Cell[22724, 607, 192, 3, 66, "Section"], Cell[22919, 612, 1692, 48, 131, "Subsubsection"], Cell[CellGroupData[{ Cell[24636, 664, 238, 5, 46, "Subsection"], Cell[24877, 671, 189, 4, 29, "Input"], Cell[25069, 677, 742, 21, 70, "Input"], Cell[25814, 700, 381, 10, 69, "Input"], Cell[CellGroupData[{ Cell[26220, 714, 575, 14, 69, "Input"], Cell[26798, 730, 537, 10, 28, "Output"], Cell[27338, 742, 537, 10, 28, "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[27924, 758, 374, 11, 59, "Subsection"], Cell[CellGroupData[{ Cell[28323, 773, 567, 18, 59, "Subsubsection"], Cell[28893, 793, 292, 6, 45, "Input"], Cell[29188, 801, 262, 6, 45, "Input"], Cell[29453, 809, 299, 6, 45, "Input"], Cell[29755, 817, 204, 4, 45, "Input"], Cell[29962, 823, 198, 4, 45, "Input"], Cell[30163, 829, 291, 6, 45, "Input"], Cell[30457, 837, 387, 12, 45, "Input"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[30893, 855, 207, 3, 54, "Subsection"], Cell[CellGroupData[{ Cell[31125, 862, 185, 4, 35, "Subsubsection"], Cell[31313, 868, 1727, 40, 150, "Input"], Cell[33043, 910, 875, 24, 130, "Input"], Cell[33921, 936, 135, 3, 32, "Input"], Cell[CellGroupData[{ Cell[34081, 943, 542, 11, 69, "Input"], Cell[34626, 956, 440, 6, 28, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[35103, 967, 229, 5, 48, "Input"], Cell[35335, 974, 117, 1, 28, "Output"] }, Open ]] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[35513, 982, 152, 2, 54, "Subsection"], Cell[35668, 986, 317, 6, 35, "Subsubsection"], Cell[CellGroupData[{ Cell[36010, 996, 440, 9, 53, "Subsubsection"], Cell[36453, 1007, 535, 15, 73, "Input"] }, Open ]] }, Open ]] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)