This page includes demos of all crypt M-files that were created for Stanoyevitch's book Introduction to Cryptography with Mathematical Foundations and Computer Implementations. All text elements below can be copied and pasted onto the MATLAB, Octave, or FreeMat command window. Anything after the the comment symbol "%" is ignored by MATLAB/Octave/FreeMat so this symbol is used to provide additional information on the syntax (and input/output variables) of some programs. More information about a program called programName can sometimes be obtained by typing "help programName" in the MATLAB command window (in FreeMat one should type "type programName"-- this will display all of the lines of programName; the first few lines (begining with % contain the content of the help). The computer implementation material at the end of each chapter in the book contains much more detailed information about the programs and the underlying algorithms, as well as helpful ideas for readers who wish to write their own programs in any computing platform. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The M-files are of the following three types: 1. Programs whose names do not end in the suffix "_FM" or "Sym." These programs work on MATLAB, Octave, and FreeMat. The outputs should be the same on either platform for given admissible sets of inputs. All of these programs are illustrated in FreeMat. FreeMat will sometimes give some additional warning messages on some of these programs; these can be ignored (and we do not print them below). 2. Programs whose names end in "_FM." This means that the corresponding MATLAB program needed some changes to work in FreeMat. When using Fremat, the "_FM" suffix added to the corresponding program name. 3. Programs whose names end in "Sym." This small collection of programs (placed at the end of the list of Chapter 8 programs) correspond to programs that use MATLAB's symbolic functionality. These will not work in Octave or FreeMat, and should be used when working with large integers. As a general rule, integer arithmetic in Octave and Fremat (and in non-symbolic MATLAB calculations) works fine as long as the number of digits in any computed integers gets no larger than 15. This means, for example, when multiplying integers in a certain modulus m, the number of digits of m should be at most 7 or 8. This is usually fine for most of the book's illustrations and homework problems; but for larger (and real-life) contemporary applications symbolic computations are needed. Such applications and issues are discussed in detail in the computer implementations material at the end of Chapter 8. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Chapter 1: --> Int2LCText([15 17 0 6 20 4]) prague +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Int2UCText([15 17 0 6 20 4]) PRAGUE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> LCText2Int('wenttochina') 22 4 13 19 19 14 2 7 8 13 0 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> LCTextWithSpaces2Int('went to china') 22 4 13 19 26 19 14 26 2 7 8 13 0 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> UCText2Int('WENTTOCHINA') 22 4 13 19 19 14 2 7 8 13 0 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> UCText2LCText('HELLO') ans = hello +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> LCText2UCText('hello') ans = HELLO +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ShiftCrypt('sunshine',3) VXQVKLQH +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> VigenereCrypt('movetothesafehouse','ocean') AQZEGCVLEFOHIHBIUI +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> VigenereDeCrypt('AQZEGCVLEFOHIHBIUI','ocean') movetothesafehouse +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> RandIntGen(0,1,15) 1 1 1 1 0 1 0 0 1 1 0 1 0 1 --> RandIntGen(0,25,15) ans = 7 18 2 10 2 25 11 8 6 24 2 9 15 20 18 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Chapter 2: --> [q r] = DivAlg(12353, 108) q = 114 r = 41 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> EuclidAlg(6192546, 1057428) 6 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> PrimeFactors(1245684) 2 2 3 11 9437 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> EuclidAlgExt(6192546, 1057428) 6 -14621 85624 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ModInv(10,251) 226 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ISBN13Checker([9 7 8 1 4 3 9 8 1 7 6 3],6) No Error detected. --> ISBN13Checker([9 7 8 1 4 3 9 8 1 7 6 3],2) Error Detected: The check digit 6 is different from the last digit 2. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Chapter 3: --> AffineCrypt('threehostilesatairport',5,14) FXVIIXGAFCRIAOFOCVLGVF +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> AffineDeCrypt('FXVIIXGAFCRIAOFOCVLGVF',5,14) threehostilesatairport +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> AffineNulls('threehostilesatairport', 32, 5, 14) [13, 17, 3, 2, 2, 26, 17, 20, 8, 26, 13, 22, 5, 2, 8, 14, 21, 13, 14, 22, 3, 25, 20, 21, 21, 3, 13] 13 17 3 2 2 26 17 20 8 26 13 22 5 2 8 14 21 13 14 22 3 25 20 21 21 3 13 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> AffineNullsDecrypt([13 17 3 2 2 26 17 20 8 26 13 22 5 2 8 14 21 13 14 22 3 25 20 21 21 3 13],32,5,14) threehostilesatairport +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Perm1 = [1:6; 2 4 6 1 3 5]; Perm2 = [1:6; 6 5 4 3 2 1]; --> PermComposer(Perm1,Perm2) 1 2 3 4 5 6 5 3 1 6 4 2 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Perm = [1:6; 2 4 6 1 3 5]; --> PermInverter(Perm) 1 2 3 4 5 6 4 1 5 2 6 3 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> SmallEnigma('ebbe',5,3,1) FFCC --> SmallEnigma('ffcc',5,3,1) EBBE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> DigraphBlockAffineCrypt('threehostilesatairport',211,454) BHWYIHXOJKEYTMWMXLUCOR +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Chapter 4: --> A = [7 5 2;0 6 4;8 2 5] A = 7 5 2 0 6 4 8 2 5 --> MatModInv(A,9) 2 3 4 7 5 4 3 4 3 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> HillCrypt('codebluealert',[1 2; 1 3]) ans = ESLPXICGWHMDTG +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> HillDeCrypt('ESLPXICGWHMDTG',[1 2; 1 3]) ans = codebluealertn +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> HillEncodingMatrixGenerator(3) 10 21 1 13 21 10 16 8 11 --> HillEncodingMatrixGenerator(4) 13 3 11 11 5 8 14 5 18 4 17 20 0 24 13 15 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Chapter 5: --> LCTextWithSpaces2Int('went to china') 22 4 13 19 26 19 14 26 2 7 8 13 0 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> UCTextWithSpaces2Int('MEET ME IN PARIS') 12 4 4 19 26 12 4 26 8 13 26 15 0 17 8 18 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Int2UCTextWithSpaces([12 4 4 19 26 12 4 26 8 13 26 15 0 17 8 18]) MEET ME IN PARIS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> STR = 'AHFBGXVUDPWPAXJTKHYUXMWTUYHMBXYYUDYPMWPFGPNPVPGGUEOHDJUZXGGUNYIGPFUXWLPYFPGGUDXWYWKKDAPFBQNKZWTUNKPDTPGQTXDDUMPZKMJWTUWNUUYWTNKHJTLTXFTJGXZIYUYFKHGDAUFPHJTWKQWTULXDUFKKGVUNPMDPWTPWNPMPNKHMDXWYQKHNYXDUYWTUTKHYULPYPIINKPFTUDAEJNPVUGGUDDNXVULPEYLTXFTLKHMDPAKHWWTNKHJTLXDUYINUPDXMJGPLMYPMDHMDUNWTUXMWUNGPFXMJAKHJTYKQWPGGIKIGPNYPWWTUNUPNWTXMJYLUNUKMUVUMPZKNUYIPFXKHYYFPGUWTPMPWWTUQNKMWWTUNULUNUJNUPWYWPAGUYLTUNUPDKRUMJNKKZYPMDAKEYTUGDQKNWTNKLYKQVXMUFGPDYUNVPMWYFKWWPJUYPMUMDGUYYPMDKNDUNGEPNNPEKQKHWTKHYUYGKMJJNPIUPNAKNYJNUUMIPYWHNUYKNFTPNDYPMDAUNNEIPWFTUYWTUMWTUNULPYWTUIHZIXMJIGPMWQKNWTUPNWUYXPMLUGGPMDWTUAXJFUZUMWWPMBLTUNUOHDJUZXGGUNYAKEYWKKBWTUXNZKNMXMJIGHMJUPMDBUIWFKKGXMWTUTKWPQWUNMKKM'; --> LetterFrequencies(STR) Letter Frequency =============================== A 0.018978 B 0.008759 C 0.000000 D 0.048175 E 0.011679 F 0.029197 G 0.049635 H 0.032117 I 0.023358 J 0.033577 K 0.072993 L 0.023358 M 0.064234 N 0.075912 O 0.002920 P 0.093431 Q 0.016058 R 0.001460 S 0.000000 T 0.061314 U 0.119708 V 0.011679 W 0.077372 X 0.042336 Y 0.067153 Z 0.014599 ans = Columns 1 to 17 0.0190 0.0088 0 0.0482 0.0117 0.0292 0.0496 0.0321 0.0234 0.0336 0.0730 0.0234 0.0642 0.0759 0.0029 0.0934 0.0161 Columns 18 to 26 0.0015 0 0.0613 0.1197 0.0117 0.0774 0.0423 0.0672 0.0146 NOTE: In MATLAB, the corresponding M-file "LetterFrequenciesIgnoreSpaces" should be used. The output will be the same. The needed changes were due to FreMat's using "printf" compared with MATLAB's using "fprintf" (and some corresponding syntax changes). +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> LetterFrequenciesIgnoreSpaces('AHFB GXVUD PW P AXJ TKHYU XM WTU YHMBXYYUD YPMWP FGPNP VPGGUE OHDJU ZXGGUNY IGPFU XW LPY FPGGUD XW YWKKD APFB QNKZ WTU NKPD TPGQ TXDDUM PZKMJ WTU WNUUY WTNKHJT LTXFT JGXZIYUY FKHGD AU FPHJTW KQ WTU LXDU FKKG VUNPMDP WTPW NPM PNKHMD XWY QKHN YXDUY WTU TKHYU LPY PIINKPFTUD AE JNPVUGGUD DNXVULPEY LTXFT LKHMD PAKHW WTNKHJT LXDUYINUPDXMJ GPLMY PMD HMDUN WTU XMWUNGPFXMJ AKHJTY KQ WPGG IKIGPNY PW WTU NUPN WTXMJY LUNU KM UVUM P ZKNU YIPFXKHY YFPGU WTPM PW WTU QNKMW WTUNU LUNU JNUPW YWPAGUY LTUNU P DKRUM JNKKZY PMD AKEY TUGD QKNWT NKLY KQ VXMUFGPD YUNVPMWY FKWWPJUY PM UMDGUYY PMD KNDUNGE PNNPE KQ KHWTKHYUY GKMJ JNPIU PNAKNY JNUUM IPYWHNUY KNFTPNDY PMD AUNNE IPWFTUY WTUM WTUNU LPY WTU IHZIXMJ IGPMW QKN WTU PNWUYXPM LUGG PMD WTU AXJ FUZUMW WPMB LTUNU OHDJU ZXGGUNY AKEY WKKB WTUXN ZKNMXMJ IGHMJU PMD BUIW FKKG XM WTU TKW PQWUNMKKM') Letter Frequency =============================== A 0.018978 B 0.008759 C 0.000000 D 0.048175 E 0.011679 F 0.029197 G 0.049635 H 0.032117 I 0.023358 J 0.033577 K 0.072993 L 0.023358 M 0.064234 N 0.075912 O 0.002920 P 0.093431 Q 0.016058 R 0.001460 S 0.000000 T 0.061314 U 0.119708 V 0.011679 W 0.077372 X 0.042336 Y 0.067153 Z 0.014599 ans = Columns 1 to 17 0.0190 0.0088 0 0.0482 0.0117 0.0292 0.0496 0.0321 0.0234 0.0336 0.0730 0.0234 0.0642 0.0759 0.0029 0.0934 0.0161 Columns 18 to 26 0.0015 0 0.0613 0.1197 0.0117 0.0774 0.0423 0.0672 0.0146 NOTE: In MATLAB, the corresponding M-file "LetterFrequenciesIgnoreSpaces" should be used. The output will be the same. The needed changes were due to FreMat's using "printf" compared with MATLAB's using "fprintf" (and some corresponding syntax changes). +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ NOTE: The program "LetterFrequenciesIgnoreSpacesWithPlot" has the same functionality as the previous on but it also produces a bar plot. It works properly (only) with MATLAB. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> STR = 'AHFB GXVUD PW P AXJ TKHYU XM WTU YHMBXYYUD YPMWP FGPNP VPGGUE OHDJU ZXGGUNY IGPFU XW LPY FPGGUD XW YWKKD APFB QNKZ WTU NKPD TPGQ TXDDUM PZKMJ WTU WNUUY WTNKHJT LTXFT JGXZIYUY FKHGD AU FPHJTW KQ WTU LXDU FKKG VUNPMDP WTPW NPM PNKHMD XWY QKHN YXDUY WTU TKHYU LPY PIINKPFTUD AE JNPVUGGUD DNXVULPEY LTXFT LKHMD PAKHW WTNKHJT LXDUYINUPDXMJ GPLMY PMD HMDUN WTU XMWUNGPFXMJ AKHJTY KQ WPGG IKIGPNY PW WTU NUPN WTXMJY LUNU KM UVUM P ZKNU YIPFXKHY YFPGU WTPM PW WTU QNKMW WTUNU LUNU JNUPW YWPAGUY LTUNU P DKRUM JNKKZY PMD AKEY TUGD QKNWT NKLY KQ VXMUFGPD YUNVPMWY FKWWPJUY PM UMDGUYY PMD KNDUNGE PNNPE KQ KHWTKHYUY GKMJ JNPIU PNAKNY JNUUM IPYWHNUY KNFTPNDY PMD AUNNE IPWFTUY WTUM WTUNU LPY WTU IHZIXMJ IGPMW QKN WTU PNWUYXPM LUGG PMD WTU AXJ FUZUMW WPMB LTUNU OHDJU ZXGGUNY AKEY WKKB WTUXN ZKNMXMJ IGHMJU PMD BUIW FKKG XM WTU TKW PQWUNMKKM'; --> [Pre Post] = AdjacentLetterCounts(STR,6) Letter counts for the letter G ============================================================ Before After Before OR After 1 A 0 1 0 B 0 0 0 C 0 0 1 D 2 3 0 E 1 1 2 F 0 2 7 G 7 14 1 H 1 2 4 I 0 4 1 J 0 1 2 K 1 3 0 L 0 0 0 M 0 0 2 N 0 2 0 O 0 0 5 P 7 12 0 Q 1 1 0 R 0 0 0 S 0 0 0 T 0 0 3 U 8 11 0 V 0 0 0 W 0 0 2 X 2 4 0 Y 0 0 0 Z 0 0 The letter G does not appear before/after 12 ciphertext letters. Pre = 1 0 0 1 0 2 7 1 4 1 2 0 0 2 0 5 0 0 0 0 3 0 0 2 0 0 Post = 0 0 0 2 1 0 7 1 0 0 1 0 0 0 0 7 1 0 0 0 8 0 0 2 0 0 NOTE: In MATLAB, the corresponding M-file "LetterFrequenciesIgnoreSpaces" should be used. The output will be the same. The needed changes were due to FreMat's using "printf" compared with MATLAB's using "fprintf" (and some corresponding syntax changes). +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> STR = 'AHFB GXVUD PW P AXJ TKHYU XM WTU YHMBXYYUD YPMWP FGPNP VPGGUE OHDJU ZXGGUNY IGPFU XW LPY FPGGUD XW YWKKD APFB QNKZ WTU NKPD TPGQ TXDDUM PZKMJ WTU WNUUY WTNKHJT LTXFT JGXZIYUY FKHGD AU FPHJTW KQ WTU LXDU FKKG VUNPMDP WTPW NPM PNKHMD XWY QKHN YXDUY WTU TKHYU LPY PIINKPFTUD AE JNPVUGGUD DNXVULPEY LTXFT LKHMD PAKHW WTNKHJT LXDUYINUPDXMJ GPLMY PMD HMDUN WTU XMWUNGPFXMJ AKHJTY KQ WPGG IKIGPNY PW WTU NUPN WTXMJY LUNU KM UVUM P ZKNU YIPFXKHY YFPGU WTPM PW WTU QNKMW WTUNU LUNU JNUPW YWPAGUY LTUNU P DKRUM JNKKZY PMD AKEY TUGD QKNWT NKLY KQ VXMUFGPD YUNVPMWY FKWWPJUY PM UMDGUYY PMD KNDUNGE PNNPE KQ KHWTKHYUY GKMJ JNPIU PNAKNY JNUUM IPYWHNUY KNFTPNDY PMD AUNNE IPWFTUY WTUM WTUNU LPY WTU IHZIXMJ IGPMW QKN WTU PNWUYXPM LUGG PMD WTU AXJ FUZUMW WPMB LTUNU OHDJU ZXGGUNY AKEY WKKB WTUXN ZKNMXMJ IGHMJU PMD BUIW FKKG XM WTU TKW PQWUNMKKM'; --> CiphertextPartialSub(STR,'UKPWT','eoath') AHFB GXVeD at a AXJ hoHYe XM the YHMBXYYeD YaMta FGaNa VaGGeE OHDJe ZXGGeNY IGaFe Xt LaY FaGGeD Xt YtooD AaFB QNoZ the NoaD haGQ hXDDeM aZoMJ the tNeeY thNoHJh LhXFh JGXZIYeY FoHGD Ae FaHJht oQ the LXDe FooG VeNaMDa that NaM aNoHMD XtY QoHN YXDeY the hoHYe LaY aIINoaFheD AE JNaVeGGeD DNXVeLaEY LhXFh LoHMD aAoHt thNoHJh LXDeYINeaDXMJ GaLMY aMD HMDeN the XMteNGaFXMJ AoHJhY oQ taGG IoIGaNY at the NeaN thXMJY LeNe oM eVeM a ZoNe YIaFXoHY YFaGe thaM at the QNoMt theNe LeNe JNeat YtaAGeY LheNe a DoReM JNooZY aMD AoEY heGD QoNth NoLY oQ VXMeFGaD YeNVaMtY FottaJeY aM eMDGeYY aMD oNDeNGE aNNaE oQ oHthoHYeY GoMJ JNaIe aNAoNY JNeeM IaYtHNeY oNFhaNDY aMD AeNNE IatFheY theM theNe LaY the IHZIXMJ IGaMt QoN the aNteYXaM LeGG aMD the AXJ FeZeMt taMB LheNe OHDJe ZXGGeNY AoEY tooB theXN ZoNMXMJ IGHMJe aMD BeIt FooG XM the hot aQteNMooM +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> FrequencyCounts('ABCABCABCZZZ',1,3) 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> STR='AHFBGXVUDPWPAXJTKHYUXMWTUYHMBXYYUDYPMWPFGPNPVPGGUEOHDJUZXGGUNYIGPFUXWLPYFPGGUDXWYWKKDAPFBQNKZWTUNKPDTPGQTXDDUMPZKMJWTUWNUUYWTNKHJTLTXFTJGXZIYUYFKHGDAUFPHJTWKQWTULXDUFKKGVUNPMDPWTPWNPMPNKHMDXWYQKHNYXDUYWTUTKHYULPYPII'; >> [Record DuplicatedGrams] = FourFiveGramLocator(STR) Record = 4 16 2 189 4 17 2 189 4 46 2 28 4 78 2 111 4 122 2 78 5 16 2 189 DuplicatedGrams = TKHY KHYU PGGU DXWY UYWT TKHYU +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> STR = 'PDYTHXYNAWHMITHLLMGCIFHEWZPULSPEOICCLVNQZTHZPGZHVVDLHWPNEBXGPXYMCZPHTPGZHVVDTMGCIXOVVHXUEZTCNASRCUYHECUGQTOUGRGPUKSSLHWDAFHZSSWCDSPYUGWBLFTGTLWAKPGYVOBPUGRHSYKCHPZHFXEMASHPYFSSWCDSPSIKGTXUDWCRUMOUPHVSDFNKOVPINGAJBBUWEBXAPYHXFDQBXFHNLTAQWYHJTCNASHPQTZADIYKPEYKWHLGRGITWMVXYATBSXIKSDGYKOIEBXHDAIYHWPGPSGPIKRXYUKWAJNASHPJKCQWYFGXYQAWIPQTHTCNASUZUFFPNCGUSZQGTGZGMVTDOFAXEIYSPNBPOKPLXEJTLBBVLHXKAPUIOCOUESPAZKCBEBXOXC' --> ShiftedMatches(STR,5) 30 --> ShiftedMatches(STR,4) 12 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Freq = [.060, .036, .036, .072, .012, 0, .060, .108, .060, .012, .012, .012, 0,.012, 0, .133, .024, .012, .060, .084, .024, .024, .024, .084, 0, .036]; --> ShiftedDotProducts(Freq) 1.0e-002 * Columns 1 to 11 4.0759 3.9555 4.0159 4.1664 4.2172 3.3140 3.3038 4.1014 3.7981 3.1820 3.2302 Columns 12 to 22 4.6795 3.7927 3.2800 4.1523 6.1630 3.7213 2.7416 3.2629 4.6115 3.1966 3.5464 Columns 23 to 26 4.2895 3.7359 3.1104 4.1557 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> STR1 = '01010'; STR2 = '00000'; --> CoincidenceIndex(STR1, STR2) 0.6000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> RandPermGen1to27fix27 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 26 27 2 10 7 22 13 19 26 21 18 16 9 4 1 23 14 8 11 20 25 15 5 6 17 3 24 12 27 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Perm = RandPermGen1to27fix27 Perm = 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 26 27 16 13 12 25 5 22 2 7 4 20 9 17 26 15 21 24 3 19 6 8 10 1 18 14 11 23 27 --> DisplayPerm(Perm) Plaintext Ciphertext =============================== a P b M c L d Y e E f V g B h G i D j T k I l Q m Z n O o U p X q C r S s F t H u J v A w R x N y K z W +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> VecN = [0 1]; TheFreq = [0.2 0.8]; Len =50; --> [RandString Freq] = RandStringProducer(VecN, TheFreq, Len) RandString = Columns 1 to 40 1 0 1 1 0 1 0 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 Columns 41 to 50 1 1 0 1 0 1 1 1 1 1 Freq = 0.2200 0.7800 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Perm = RandPermGen1to27fix27 Perm = 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 26 27 6 25 26 19 7 15 2 1 5 24 16 13 21 18 3 11 10 17 22 14 9 23 12 20 4 8 27 --> PermCipher('went to china',Perm) ans = LGRN NC ZAERF --> PermCipher('stand by in tromso for instructions',Perm) ans = VNFRS YD ER NQCUVC OCQ ERVNQIZNECRV +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Chapter 6: --> bin2int('1001010') 6170 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> baseb2int([8 3 4 0 1], 9) 55000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> int2bin(6170) 1 1 0 0 0 0 0 0 1 1 0 1 0 --> int2bin(6170, 15) 0 0 1 1 0 0 0 0 0 0 1 1 0 1 0 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> baseb_add([2 1 0 2 2],[1 0 2],3) 2 1 2 0 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> baseb_sub([2 1 2 0 1],[1 0 2],3) 2 1 0 2 2 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> baseb_mult([2 1 2 0 1],[1 0 2],3) 1 0 0 1 0 2 0 2 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> FastExp(2,2011,15) 8 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Chapter 7: --> BitString2Vec('1010111') 1 0 1 0 1 1 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Vec2BitString([1 0 1 0 1 1 1]) 1010111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> FeistelSystem3RoundsEx7_1_Encrypt('00011010','111100001111') 01010001 Note: Needed to create an XOR M-File for FreeMat (this is a compiled function in MATLAB). +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ScaledDownInitPerm([1 1 0 1 1 1 1 1]) 1 1 1 0 1 1 1 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ScaledDownDESRoundKeys('001011011001') 0 0 0 0 1 1 1 1 0 1 0 1 0 1 1 0 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ScaledDownSBox([0 1 0 1], 1) 0 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ScaledDownDESRoundKeyFunction([1 1 1 1],[0 0 0 0 1 1 1 1]) 0100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ScaledDownInvInitPerm([0 1 1 0 1 0 1 0]) 1 0 0 0 1 0 1 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ScaledDownDES('11011111','001011011001') 10001011 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ScaledDownDESDecrypt('10001011','001011011001') 11011111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Ptext = [1 0 1 1 1 0 1 1 0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 0 0 0 0 1 1 0 0 1 0 1 0 1 1 0 0 0 0 1 1 0 0 1 1 1 0 0 1 1 1 0 0 1 1 0 1 0 1 0 0 1]; --> InitPerm(Ptext) ans = 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 0 0 1 0 0 1 1 0 1 1 1 0 1 0 1 1 1 0 0 0 0 1 0 1 1 1 1 0 0 1 0 1 1 1 0 1 1 1 1 1 0 0 1 0 0 1 0 1 --> InvInitPerm(ans) 1 0 1 1 1 0 1 1 0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 0 0 0 0 1 1 0 0 1 0 1 0 1 1 0 0 0 0 1 1 0 0 1 1 1 0 0 1 1 1 0 0 1 1 0 1 0 1 0 0 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Key = [1 0 0 1 0 0 1 0 1 0 1 0 0 1 1 1 0 1 1 0 0 0 1 0 0 0 1 1 1 1 0 1 1 1 1 1 1 1 1 0 0 1 1 0 1 0 1 1 1 0 0 1 1 0 0 0 1 0 0 1 1 0 1 1]; --> DESRoundKeys(Key) 0 0 1 1 1 0 1 1 0 1 1 1 0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1 1 0 1 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 0 1 0 0 0 1 1 0 1 1 0 0 0 1 1 1 0 1 1 1 0 1 0 1 0 1 0 1 0 0 0 1 1 0 1 0 1 0 0 1 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 1 1 1 1 0 1 1 0 0 1 0 0 1 1 1 1 0 1 0 1 0 1 0 1 1 1 0 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 1 0 0 1 1 1 1 0 0 1 1 0 1 1 1 0 0 0 0 0 1 1 1 1 0 1 1 0 1 0 1 1 1 1 0 0 1 1 1 1 1 0 0 0 1 1 0 0 0 0 1 1 1 0 1 1 0 1 0 1 0 1 1 1 1 1 0 1 1 1 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 1 0 0 1 0 1 1 1 1 0 1 0 0 1 1 1 0 1 1 1 1 0 1 0 0 0 1 0 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 1 0 0 0 1 0 0 0 1 1 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 1 1 0 0 0 1 1 1 0 1 0 1 0 0 1 0 1 1 1 1 0 0 0 1 0 1 1 1 1 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 1 0 1 1 0 1 0 1 1 1 0 1 1 1 1 1 1 0 1 0 0 1 1 1 1 0 0 0 1 0 1 0 1 1 1 1 0 1 0 1 0 1 0 1 0 0 1 1 1 1 1 0 1 1 1 0 1 0 0 0 1 0 0 1 0 0 1 1 0 1 1 0 0 1 1 1 1 0 1 0 0 0 0 1 1 0 1 1 0 1 0 1 1 1 1 0 0 0 0 1 1 0 0 1 1 0 1 1 1 0 1 1 0 1 0 1 1 0 1 1 1 1 0 0 1 0 0 1 1 0 1 1 1 1 1 0 1 0 1 1 1 0 1 0 0 1 1 0 1 1 0 0 0 1 0 1 0 1 0 1 0 1 1 0 1 1 0 1 0 0 1 0 1 1 1 0 1 1 0 0 1 1 1 0 0 1 1 0 0 0 0 0 1 0 0 1 1 0 1 0 1 1 1 0 1 0 1 0 1 0 1 1 1 0 1 0 0 0 1 1 0 1 0 1 1 1 0 1 1 1 1 0 1 0 0 1 1 1 1 1 1 0 0 1 0 1 1 1 0 1 1 0 0 1 1 1 1 1 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 0 0 0 0 0 1 1 1 0 0 0 0 1 0 0 1 1 1 1 1 1 0 1 0 1 0 0 1 0 0 0 1 1 1 1 0 1 0 1 0 1 0 1 0 1 1 0 0 1 1 1 1 1 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 0 1 0 1 0 0 1 0 0 1 0 1 1 1 1 1 1 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> SBox([0 1 1 0 1 1],2) 1 0 0 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> R0 = '10000101111001011101111100100101'; --> RoundKey = '001110110111010000011110011011110111101110110000'; --> DESRoundKeyFunction(R0,RoundKey) 1 1 0 1 1 0 0 0 1 1 0 1 1 0 0 0 1 1 0 1 1 0 1 1 1 0 1 1 1 1 0 0 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Ptext = [1 0 1 1 1 0 1 1 0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 0 0 0 0 1 1 0 0 1 0 1 0 1 1 0 0 0 0 1 1 0 0 1 1 1 0 0 1 1 1 0 0 1 1 0 1 0 1 0 0 1]; --> Key = [1 0 0 1 0 0 1 0 1 0 1 0 0 1 1 1 0 1 1 0 0 0 1 0 0 0 1 1 1 1 0 1 1 1 1 1 1 1 1 0 0 1 1 0 1 0 1 1 1 0 0 1 1 0 0 0 1 0 0 1 1 0 1 1]; --> DES(Ptext,Key) 0 1 1 0 0 0 0 1 0 1 1 1 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 1 1 0 0 0 1 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Chapter 8: --> EulerPhi(19239) 11440 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> EulerPhiInv(22) 23 46 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Order(2,101) 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> FermatTest(841) Inputted number was proved composite using the Fermat test. Here is a corresponding witness: 17 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> MillerRabinTestEnhanced(9783) Inputted integer was proved composite using the Miller-Rabin test. Here is a corresponding witness: 3503 The corresponding exponent paramters for 2^j*m are [j m]=: 0 4891 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Pollardpminus1(58932967,12) The following factor of n has been found: d = 7351. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Symbolic Programs (MATLAB Only): >> [d x y] = gcdSym(sym(112123123412345123456),sym(98765432123456789)) d = 16 x = 2173884457375910 y = -2467894991780724431 >> p = sym('1634733645809253848443133883865090859841783670033092312181110852389333100104508151212118167511579'); >> q = sym('1900871281664822113126851573935413975471896789968515493666638539088027103802104498957191261465571'); >> n=p*q n = 3107418240490043721350750035888567930037346022842727545720161948823206440518081504556346829671723286782437916272838033415471073108501919548529007337724822783525742386454014691736602477652346609 >> FastExpSym(sym(1345),p,sym(112123123412345123456)) ans = 100519652220422356417 >> ModInvSym(ans,sym(112123123412345123456)) 22719251729985081921 >> FermatTestSym(n, 4) Inputted number was proved composite using the Fermat text. Here is a corresponding witness: a = 2814674387357589089278003868506047400465685457879454124904559036952301872688607472049239239141968681458768482813997417403629891346894020264157297275374132587997380905452018216939719257145263072 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Chapter 9: --> DiffieHellmanKey(53,2,5,22) %DiffieHellmanKey(p,g,B,a) 29 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> NextPrime(888888) 888917 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> RSAEncrypt(44,49,1517) %RSAEncrypt(P,e,n) 1069 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> RSADecrypt(1069,529,1517) %RSADecrypt(C,d,n) 44 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> RSADigitalSig(1776,103,1817) %RSADigitalSig(P,d,n) 1790 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> RSADigitalSigAuthenticate(1790,883,1817) %RSADigitalSigAuthenticate(s,e,n) 1776 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> [A, C] = ElGamalEncrypt(44,22,5,53,2) %[A, C] = ElGamalEncrypt(P,a,B,p,g) A = 43 C = 4 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ElGamalDecrypt(43,4,47,53) %ElGamalDecrypt(A,C,b,p) 44 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> [P r s] = ElGamalDigitalSig(44,22,15,53,2) %[P r s] = ElGamalDigitalSig(P,a,d,p,g) P = 44 r = 14 s = 24 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Q = ElGamalDigitalSigAuthenticate(P,r,s,43,53,2) %Q = ElGamalDigitalSigAuthenticate(P,r,s,A,p,g) Q = 44 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> [Bestx BestValue] = KnapsackBruteFindAllBest([3 4 6 8 10 12], 28) %[Bestx BestValue] = KnapsackBruteFindAllBest(Weights, s) Bestx = 0 0 1 0 1 1 0 1 1 1 1 0 BestValue = 28 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> KnapsackSuperIncreasing([1 2 4 9 20 48], 27) %KnapsackSuperIncreasing(Weights, s) 1 1 1 0 1 0 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> PrivateWeights = [1 2 4 9 20 48]; --> PublicWeights = mod(38*PrivateWeights,101); --> MerkleHellmanEncrypt(PublicWeights, [0 1 1 1 0 1]) %MerkleHellmanEncrypt(PublicWeights, xPlaintext) 172 --> MerkleHellmanDecrypt(PrivateWeights,101, 38, 172) %MerkleHellmanDecrypt(PrivateWeights,m, w, C) 0 1 1 1 0 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Chapter 10: NOTE: All polynomials are stored as vectors in the following format: X^4 +3X^2 + 1 ---> [1 3 0 1] --> ZpPolyAdd([1 0 4 0 0 2],[3 0 1 0],5) ans = 1 0 2 0 1 2 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ZpPolyMult([1 0 4 0 0 2],[3 0 1 0],5) 3 0 3 0 4 1 0 2 0 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> [qx rx] = ZpDivAlg([1 0 0 3 2], [1 0 2], 5) %[qx rx] = ZpDivAlg(fx,gx,p) qx = 1 0 3 rx = 3 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ZpIrredCheck([1 0 1 1],2) ans = irreducible --> ZpIrredCheck([1 1 0 1 1],2) ans = 1 1 %means X + 1 is a factor of X^4 +X^3 + X + 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> fgx = ZpModmMult([1 0 1 1],[1 1 0],[1 0 0 1 1],2) %fgx = ZpModmMult(fx,gx,mx,p) fgx = 1 1 1 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> outHex = GF16Mult('A','7') %outHex = GF16Mult(n1Hex,n2Hex) outHex = 3 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> outHex = GF256Mult('A7', '7A') %outHex = GF256Mult(n1Hex, n2Hex) outHex = ED +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> GF16Inv('B') 5 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> GF256Inv('B3') EF +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Chapter 11: --> NibbleXOR('A','C') 6 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> NibbleMult('A','C') 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ScaledDownAESRoundKeys('2A74') 2A74E4904CDC +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ScaledDownAESSBox('D') 5 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ScaledDownAESStateXOR(['D' 'A'; '2' '6'], ['2' '7'; 'A' '4']) %ScaledDownAESStateXOR(SHex, KeyHex) FD 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> OutStateHex = ScaledDownAESNibbleSub(['F' 'D'; '8' '2']) OutStateHex = 75 A6 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ScaledDownAESShiftRow(['7' '5'; 'A' '6']) 75 6A +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ScaledDownAESMixColumn(['7' '5'; '6' 'A']) CB 9D +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> CtextHex = ScaledDownAES('D2A6','2A74') %CtextHex = ScaledDownAES(PtextHex,KeyHex) CtextHex = 29B9 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ScaledDownAESInvSBox('0') A +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ScaledDownAESInvNibbleSub(['7' '5';'A' '6']) FD 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> ScaledDownAESInvMixColumn(['C' 'B'; '9' 'D']) 75 6A +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> PtextHex = ScaledDownAESDecrypt('29B9','2A74') %PtextHex = ScaledDownAESDecrypt(CtextHex,KeyHex) PtextHex = D2A6 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ FULL AES Programs: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ I am grateful Boian Kolev for having created the following programs and allowing them to be posted and shared on this cryptography webpage. To make the inner-workings of the programs easier to follow, rather than work with length 32 hex strings, the programs work with 4x4 matrices of integers in the range {0,1, ..., 255}, each corresponding to a pair of hex characters (= 1 byte). The pairs of hex integers are converted into their integer equivalents and filled into the matrix by columns. The "toMatrix" below performs this transformation. Each of the remaining programs are similar to the corresponding scaled-down AES programs, but we will sometimes need to use this "toMatrix" program to illustrate some of them. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ NOTE: For all of these full-AES programs, any inputted hex strings can be inputted either using the upper-case alphabet {A,B,C,D,E,F} or using the lower-case alphabet {a,b,c,d,e,f}. This is in contrast to the scaled-down AES programs above, which require to input strings using the upper-case alphabet. The outputted hex strings (ciphertexts) will still use the upper-case alphabet. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> ByteXOR('2A','FA') D0 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> ByteMult('2A','F5') 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> AESSBox('3B') E2 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> KeyHexStr = '000102031011121314A1A2A3A4F1F2FA'; >> keyMat = AESRoundKeys(KeyHexStr) keyMat = Columns 1 through 4 0 16 20 164 1 17 161 241 2 18 162 242 3 19 163 250 Columns 5 through 8 160 176 164 0 136 153 56 201 47 61 159 109 74 89 250 0 Columns 9 through 12 127 207 107 107 180 45 21 220 76 113 238 131 41 112 138 138 Columns 13 through 16 253 50 89 50 88 117 96 188 50 67 173 46 86 38 172 38 Columns 17 through 20 144 162 251 201 105 28 124 192 197 134 43 5 117 83 255 217 Columns 21 through 24 58 152 99 170 2 30 98 162 240 118 93 88 168 251 4 221 Columns 25 through 28 32 184 219 113 104 118 20 182 49 71 26 66 4 255 251 38 Columns 29 through 32 46 150 77 60 68 50 38 144 198 129 155 217 167 88 163 133 Columns 33 through 36 206 88 21 41 113 67 101 245 81 208 75 146 76 20 183 50 Columns 37 through 40 51 107 126 87 62 125 24 237 114 162 233 123 233 253 74 120 Columns 41 through 44 80 59 69 18 31 98 122 151 206 108 133 254 178 79 5 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> S = '000102031011121314A1A2A3A4F1F2FA'; >> M = toMatrix(S) M = 0 16 20 164 1 17 161 241 2 18 162 242 3 19 163 250 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> S = '000102031011121314A1A2A3A4F1F2FA'; >> K = '2B7E151628AED2A6ABF7158809CF4F3C'; >> AESStateXOR(toMatrix(S),toMatrix(K)) 43 56 191 173 127 191 86 62 23 192 183 189 21 181 43 198 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> S = '000102031011121314A1A2A3A4F1F2FA'; >> AESByteSub(toMatrix(S)) 99 202 250 73 124 130 50 161 119 201 58 137 123 125 10 45 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> id = toMatrix('01000000000100000000010000000001') %identity matrix id = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 >> AESShiftRowR(id,3) %shifts entries in the 3rd row one unit to the right (w/ cycling) 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 >> AESShiftRowNR(id) %shifts entries in the ith row i-1 units to the right (w/ cycling) 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 >> AESShiftRowL(id,3)%shifts entries in the 3rd row one unit to the left (w/ cycling) 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 >> AESShiftRowNL(id)%shifts entries in the ith row i-1 units to the left (w/ cycling) 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> id = toMatrix('01000000000100000000010000000001') %identity matrix >> AESMixColumn(id) ans = 2 3 1 1 1 2 3 1 1 1 2 3 3 1 1 2 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> PtextHex = '6bc1bee22e409f96e93d7e117393172a'; >> KeyHex = '2b7e151628aed2a6abf7158809cf4f3c'; >> Ctext = AES(PtextHex,KeyHex) Ctext = 3AD77BB40D7A3660A89ECAF32466EF97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> AESInvSBox('E2') 3B +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> S = '000102031011121314A1A2A3A4F1F2FA'; >> M = AESByteSub(toMatrix(S)) >> AESInvByteSub(M) 0 16 20 164 1 17 161 241 2 18 162 242 3 19 163 250 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> id = toMatrix('01000000000100000000010000000001'); >> M = AESMixColumn(id); >> AESInvMixColumn(M) 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> CypherTextHex = '3AD77BB40D7A3660A89ECAF32466EF97'; >> KeyHex = '2b7e151628aed2a6abf7158809cf4f3c'; >> AESDecrypt(CypherTextHex, KeyHex) 6BC1BEE22E409F96E93D7E117393172A +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Chapter 12: --> SumPoints = EllipticCurvePointAddition([2 4], [4 8], -4, 16) %SumPoints = EllipticCurvePointAddition(P1, P2, a, b) SumPoints = -2 4 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Points = EllipticCurvePointsModp(7, 5, 11) %Points = EllipticCurvePointsModp(a, b, p) Points = 0 4 0 7 2 4 2 7 3 3 3 8 4 3 4 8 5 0 7 1 7 10 8 1 8 10 9 4 9 7 Inf Inf +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Points = EllipticCurvePointsModp3Mod4(7, 5, 11) %Points = EllipticCurvePointsModp(a, b, p) Points = 0 4 0 7 2 4 2 7 3 3 3 8 4 3 4 8 5 0 7 1 7 10 8 1 8 10 9 4 9 7 Inf Inf +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> SumPoints = EllipticCurvePointAdditionModp([2 4], [5 0], 7, 5, 11) %SumPoints = EllipticCurvePointAdditionModp(P1, P2, a, b, p) SumPoints = 7 10 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Order = EllipticCurvePointsModpOrder([0 4], 7, 5, 11) %Order = EllipticCurvePointsModpOrder(P, a, b, p) Order = 16 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> Q = EllipticCurveFastScalMult([9954 8879], 32, 4601, 548, 11027) %Q = EllipticCurveFastScalMult(P, k, a, b, p) Q = 2562 8449 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> PtextRep = EllipticCurvePlaintextRepModp(22, 22, 153, 307, 10) %PtextRep = EllipticCurvePlaintextRepModp(m, a, b, p, K) PtextRep = 220 287 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++