47.

Learn Encryption Techniques with BASIC and C++
(Publisher: Wordware Publishing, Inc.)
Author(s): Gil Held
ISBN: 1556225989
Publication Date: 10/01/98

Previous Table of Contents Next


The DCIPHER6.CPP Program

Similar to the program DCIPHER6.BAS, its C++ version which is stored on the CD-ROM under the filename DCIPHER6.CPP has a large number of functions used in the same manner as its encipher version. Thus, in this section we will focus our attention on examining the function that provides the program with its decipherment capability. That function is the decipher function whose statements are given in Listing 4.9. Listing 4.9 includes a number of built-in comments that define the logic of the program. You can find the complete program and the executable version on the CD-ROM in the C directory.

Listing 4.9 The C++ decipher function used in the program DCIPHER6.CPP.

 //---------------------------------------------------------------- //Function: decipher() //Parameters: in - the input file we are deciphering //      out - the output file we are writing the deciphered //         text to //      PTEXT - the plaintext alphabet (used to decipher) //      ctext - the ciphertext //Return Type: None //Purpose: Decipher the input file and write the contents to the //output file specified by the user. //---------------------------------------------------------------- void decipher(ifstream in, ofstream out, const char PTEXT[], char ctext[]) {   char enc_file_data[SIZE];   //continue this process until we get to the end of the file   while (in.getline(enc_file_data, SIZE, '\n')){      if (enc_file_data[0] == '/'){         out << enc_file_data << endl;      }      else {      //format the data - i.e., get rid of all spaces           formatData(enc_file_data);         //dump data to file         for (int ix=0; ix<strlen(enc_file_data); ix++){         //used to keep track of what plaintext character           //we are going to use           int jx;           for (jx=0; jx<TWENTYSIX; jx++){           //find where the encrypted data is in the           //ciphertext - this location corresponds to           //the plaintext character location             if (enc_file_data[ix] == ctext[jx])             break;           }      //conditionals for grouping by five and inserting         //new lines         if (!(ix%TWENTYFIVE))            out << endl;         if ((ix!=0) && (!(ix%FIVE))){            out << " " << PTEXT[jx];         }         else {           out << PTEXT[jx];         }        }     }   }   return; }//end decipher() 

Monoalphabetic Combinations

Regardless of the technique or techniques used to form a monoalphabetic cipher alphabet, the maximum number of trials necessary to correctly decipher a message remains the same. That number is 26!, which is approximately 4.0329E+26—a very large number. However, that large number can be very deceptive, as it is relatively easy for a trained cryptanalyst to decipher a lengthy message by a frequency analysis of the characters in the enciphered message. For example, E is the most common letter in the English language, followed by the letter T, which has the next highest frequency of occurrence. By performing a frequency analysis of the characters in an enciphered message a trained analyst may be able to note that E was replaced by one character, T by another, and so on. By deciphering a few characters correctly, patterns may become visually identifiable. For example, deciphering three enciphered characters as EET may provide the analyst with a clue that the character prefixing the first deciphered E is the plaintext M. This monoalphabetic substitution weakness means you should keep messages relatively short to hinder the possibility of a frequency analysis being used as a wedge by a cryptanalyst to initiate the deciphering of your message. This weakness also resulted in the development of polyalphabetic substitution encipherment and pseudo-random encipherment techniques—topics I will cover in the next two chapters of this book.


Previous Table of Contents Next


Learn Encryption Techniques with Basic and C++
Learn Encryption Techniques with BASIC and C++
ISBN: 1556225989
EAN: 2147483647
Year: 2005
Pages: 92
Authors: Gil Held

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net