Assignment #2 – DES and RSA ECE428 – Computer Networks and Security 1. DES The DES algorithm was implemented in C++. The following is an outline of the DES implementation. A function was created for each step of the DES algorithm to ensure that the implementation was correct. boolpermute(char * text, intlen_in, char * out, intlen_out, ptbl table); intip_tbl[64]; intiip_tbl[64]; intep_tbl[48]; intp_tbl[32]; int pc1_tbl[56]; int pc2_tbl[48]; intls_tbl[16]; intsboxes[8][64]; intleft_shift_map[56]; voidp1(char * key, char * p); voidp2(char * shifted, char * p/*, int round*/); voidpi(char * word, char * p); voidexpand(char * h_word, char * p); voidsubstitute(char *e_word, char * p); voidpr(char * s_word, char * p); voidlast_swap(char * p_word, char * p); voidiip(char * word, char * p); voidf_box(char * text, int round); voiddes (char * msg_string, char * key, char * output, int size, int decrypt); voiddo_des (char * input, char * output, int decrypt); voidgenerate_keys(char * key); voidshow(char *object, size_t size); The implementation method is based on an observation made about the DES algorithm operation in general: the operation of the algorithm mainly involves permuting a string of bits in accordance to a permutation table. Because of this, a permute function was created that accepts a bit string and permutation table, and outputs the permuted bit string. This general function was used as a basis to almost all operations of the DES algorithm, from the bit shifting and PC1/PC2 permutations of the keys to the expansion and permutation of the message strings. Outside of this, there is a des function that breaks strings down into 64-bit chunks that can be processed through the DES algorithm, and a do_des function that will execute the DES algorithm on the input message. To verify the correctness of the DES implementation, debug statements were placed whenever a bit string was modified, and the changes were outputted in binary. This way, it is possible to verify – bit by bit – that a bit has moved from one position to its correct destination. Also, we were able to locate a 3rd party DES implementation “calculator”, which was able to accept a plaintext string as input, and output the encrypted message, as well as display each and every permutation and key that is generated during encryption, which we then used to verify our implementation. The calculator can be found at the following URL: http://people.eku.edu/styere/Encrypt/JS-DES.html. The following plaintext and cryptext can be obtained when using the key (in hex) 3b 38 98 37 15 20 f7 5e. Using our implementation, the text can be encrypted and decrypted successfully in DES: Plaintext: The Data Encryption Standard (DES) is a block cipher (a form of shared secret encryption) that was selected by the National Bureau of Standards as an official Federal Information Processing Standard (FIPS) for the United States in 1976 and which has subsequently enjoyed widespread use internationally. It is based on a symmetric-key algorithm that uses a 56-bit key. The algorithm was initially controversial with classified design elements, a relatively short key length, and suspicions about a National Security Agency (NSA) backdoor. DES consequently came under intense academic scrutiny which motivated the modern understanding of block ciphers and their cryptanalysis. Cryptext (string format): _¬µ_¬©hT_¬ø√ç h“ %<)H¬ø¬µ_¬©l∑√§O√µ√ܬ¥‹_√Æ__k ⁄√鬕”P∆¬ØJ˜{yh_√ç_Y√ú√é-TŸ ¬Æ_√ßZ¬∏√°-:√Ö√ç>_R0d._ M_√∫– _ƒ_6‡qN∏\™w√ä¬∏¬©∆√ج¥¬®√ïB√∏˝gJ‰¬©{.— ’¬•‘≤√≤√£¬ÆKL_9√†¬Ø√∑‹c,fi¬ªeh‹{√≤‰q˜√ü^~¬Ø∏¬†_√≠√ÆW_ √≠√µ√™d√µ7_∂fi√ì#J√ú–√£DZ‹∂√ò Cryptext (binary): 00010011 11000000 00111100 01101100 11011100 11011010 01001010 00010011 00001010 00101101 00110000 10011100 01110001 11111100 01000010 01111011 10011000 10001000 11001000 01110001 11001010 10010010 10110110 10110101 11101010 00101001 10110111 00000110 11101011 11110111 01011001 10101000 00111010 01100100 11010000 01001110 10101001 10111111 00101110 10001011 11111000 01100101 11110111 00000100 10011011 11011110 00001111 11110000 01001000 10001010 10010100 10110100 01111011 10000110 00010100 10000001 00101110 00000111 10111000 11000110 11111101 11010001 10101000 11010110 01101000 10100111 10010010 10010000 11101110 10101001 01101000 11000000 01001111 00010100 11010011 01111001 11101011 10001101 11101010 00000100 11000100 01011100 10010101 01100111 11010101 01001011 11011100 11011100 01011110 10010100 01100100 00100011 01101000 11010010 10110101 10011011 00010001 01010000 01101000 00101101 01011010 00111110 00001001 00000100 10101010 10101011 01001010 10110100 01001100 01100011 01111011 01111110 01010111 10011011 01001010 01010100 00001001 00000011 10101110 01101011 11000110 00000111 01010100 11111100 00011010 01001101 00110110 01110111 10101100 11100100 11010100 00001110 00101100 10011000 11111000 00001000 00110111 10000110 00000110 00100101 10101001 10101011 00001001 11111000 11101010 11011001 10000111 01010010 00011101 11100000 11100110 11001101 10101001 10110010 00111001 11011110 11100100 10111000 00001101 00010011 11010000 10001011 11100100 00100110 01000100 01100000 11110010 01110111 01001001 00111111 10101010 11101101 11011010 01110111 01010110 11000100 11000111 01011000 10011111 10000000 10101110 11000001 11100001 01111100 10011000 00111110 00000010 01001111 00001111 01000111 11010001 11001101 10110110 01000001 11111111 00001011 00101111 11101111 11011111 00011010 10001111 10001110 11001110 11010101 01110110 11011111 01010001 11011011 00100000 00001100 11011110 01000011 00011001 10110111 11010111 00011001 10110100 01000100 11100101 11001011 00101011 11000011 00111001 10101000 11011100 01011100 10000101 10101100 10010110 11111100 10010001 11011000 01111111 01010001 01100011 10101111 11000100 00010000 10111000 00100100 11000001 00001011 00100010 00100100 10100110 10101111 00001111 00001110 01111101 01010010 00111111 11101100 00111000 10100101 00000110 10011010 10110100 01111001 10001011 01010001 01110010 10010000 00110001 01010111 11000011 11111100 00110010 11001101 11110111 00000111 00000000 00010010 11000000 01011010 10011100 00010001 00111000 00100001 11101011 00010011 00000111 01110000 01010110 10100010 00111011 11010111 11101110 00111011 11111100 01111010 11001100 11101101 11110101 00010110 11010101 01001011 01011000 01100010 01110110 01000110 01111110 01101110 00000101 00000101 10101100 00110100 10001000 00101010 01100010 00111101 11111101 11110111 00100001 00100001 00100010 01000100 01111000 00011010 10011111 10011111 01001101 10000010 10101001 01011010 10110100 11000010 01010111 10011010 00010110 11011100 01011001 11101110 01110101 00000101 01000110 00100000 11111110 10001110 01100100 11011010 00001110 11001111 11111011 00001110 01011101 11111010 00101000 01110100 11010010 11001100 01100000 00010001 00011110 10111000 10010010 10011101 11001010 00111101 01111101 11011101 11010110 11000110 10011010 01101100 00110010 10110010 00000111 11110101 10110110 00101111 00100001 01111100 10110011 10100100 11110001 11101011 00010000 10011000 00111111 11110010 10101000 01011011 10000111 10011010 11011100 10110110 10100010 01000001 10000001 01100001 10010100 01100100 01000001 01001001 01111100 11110011 11110010 01011011 01000011 11000100 10010101 10010001 00100011 10011110 00100101 11100111 11101111 00101010 01111111 10000010 10110000 11011011 10101110 10111001 11010000 11011010 10001101 11101110 11010101 00100001 11111010 01011101 00011101 01100111 00110001 10011010 01110100 10100010 00000111 10010011 00110011 00010010 11001101 00101000 01000110 11110011 11111101 00011001 00000101 11100011 00110100 10101111 11010011 00111000 01100100 01001101 00000011 00011111 00000010 10000101 11001011 00011001 10111001 00100001 10010001 01001011 10000010 11100110 01100011 01100011 11001011 11111100 11100101 00010110 01110001 00100010 01100001 11001010 01010101 01110000 00110010 10110000 10101001 11101100 01111010 01001000 11110001 00001000 11011100 00010000 00100011 10101011 01001000 01010100 00100110 00011011 10001101 10000011 10101101 10010001 10110000 11000100 00011111 01101101 10001001 11110001 10110111 00000000 11010111 00010011 10111011 11101111 00110111 10010000 00101110 11101011 00011100 11011110 10011010 01110111 11110010 01011111 00110100 01000010 10111110 11011011 01100001 01111100 01110000 11000001 11010011 10111110 11100101 10110100 10011101 11111110 00100110 01110100 11110101 10111011 11111111 00001100 00101101 10001000 00110010 00100010 00001101 00011110 11000011 00010011 11001100 10011101 11001011 01011111 00111001 00111001 01100010 10110101 01111100 01001010 10001100 11001000 01001111 00001110 01111111 00101000 00110100 00101101 10001110 10111111 00011011 00110001 01010111 00110100 11011110 11101100 10011111 10011000 00100100 01110000 11100111 11001011 10011011 10001001 00111010 01011010 00100100 01001010 01000100 01010011 11001001 01110000 10111110 11000111 10110001 10010011 10110111 10001001 11000101 11110101 01001101 11101001 10011101 10010011 10111110 10011100 01001001 11000001 00110110 00000101 00000110 11110001 00100011 11010000 11010110 11000100 01000001 00101010 00110101 00100011 10111101 11010001 11000010 00010010 00000111 01110100 11110001 00010001 00011111 11001111 11011000 11111010 10011000 10001000 11110011 01011010 00010011 01100011 01111010 11100101 11100000 10011110 11110001 11001100 11010001 11111111 01100100 11100011 01111000 01111001 01011000 01101101 00011111 10010000 11111001 01100101 10110011 00011000 11101000 11010010 01111111 10000011 11101011 10010010 11111110 00100111 00110000 00010011 10000011 11100000 00111011 10101001 01000111 11001100 00010100 10111101 01101111 11100101 01100000 10001011 00101000 01101110 01101001 00100011 When the 3rd bit of the 499th byte is flipped, the following plaintext message is obtained. Notice the error only affects a single word. One instance of “National Security Agency” becomes “a√µ{_≈√ú√¶F√Öl Security Agency”: The Data Encryption Standard (DES) is a block cipher (a form of shared secret encryption) that was selected by the National Bureau of Standards as an official Federal Information Processing Standard (FIPS) for the United States in 1976 and which has subsequently enjoyed widespread use internationally. It is based on a symmetric-key algorithm that uses a 56-bit key. The algorithm was initially controversial with classified design elements, a relatively short key length, and suspicions about a√µ{_≈√ú√¶F√Öl Security Agency (NSA) backdoor. DES consequently came under intense academic scrutiny which motivated the modern understanding of block ciphers and their cryptanalysis. 2. RSA The RSA algorithm for this assignment was implemented in Java. The reason for this was to take advantage of the built in BigInteger class to process the large integers required by RSA. The algorithm was implemented using two classes: the RSA class and the RSAKey class. The RSAKey class was used to represent the keys, both private and public. The RSA class was responsible for all number generations and encryption and decryption calculations. A third class was also used to drive the RSA simulation. The correctness of our implementation was verified by checking the correctness of independent functions. For testing purposes small prime numbers were used. Also, the fact that a long message can be encrypted and successfully decrypted shows that the implementation is not incorrect. We also checked the crypt text against a third party RSA implementation to further verify the correctness. One of the samples that we ran on our RSA implementation is the following: Original message: ECE428: Assignment 2 - Implementation of RSA Encrypted message: 8077922667640783203 5046253358820482373 8077922667640783203 1712729367884595395 6519377116757479951 5208185422105530023 439297322082640741 3698387137592412698 4914288835186659083 522485690492515212 522485690492515212 6870139161631047745 5831946615431867907 5258601660850745835 690019284392425593 5508373806630766094 5258601660850745835 7250153813889153509 3698387137592412698 6519377116757479951 3698387137592412698 1500530885814479914 3698387137592412698 1040946361584735089 690019284392425593 8866940273540819672 8159042064335923026 5508373806630766094 690019284392425593 5508373806630766094 5258601660850745835 7250153813889153509 2594058306111789289 7250153813889153509 6870139161631047745 5806716958016824933 5258601660850745835 3698387137592412698 5806716958016824933 2376823557801398871 3698387137592412698 5672934259409692898 6673580357575861323 4914288835186659083 Decrypted message: ECE428: Assignment 2 - Implementation of RSA The keys used in the encryption are: Public key: (8934552687755886703, 6586553260683432281) Private key: (8934552687755886703, 3673604478326708129)