36.

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 DCIPHER5.CPP Program

Once again a C++ version of a previously constructed BASIC language program is presented for readers who prefer this programming language. Maintaining our naming conventions, the C++ version of DCIPHER5.BAS is appropriately named DCIPHER5.CPP, while the executable version of the program is named DCIPHER5.EXE. To distinguish the executable version of DCIPHER5.BAS from DCIPHER5.CPP, remember that there are two directories on the CD-ROM accompanying this book and that source and executable BASIC programs are stored in the BASIC directory while C++ source and executable programs are stored in the C directory.

Listing 3.8 contains the complete listing of DCIPHER5.CPP. As you read through the code you will note that, similar to the BASIC program, large segments of code were reused. Of particular interest is the function appropriately named decipher, which locates where the encrypted data is in the ciphertext.

Listing 3.8 The DCIPHER5.CPP program listing.

 /* dcipher5.cpp C++ code written by Jonathan Held using Microsoft Visual C++, version 5.0, on March 12, 1998. */ //standard include files #include<iostream.h> #include<fstream.h> #include<stdlib.h> #include<string.h> #include<ctype.h> //function prototypes bool checkInput(char * &); void createAlphabet(char *, char[]); void decipher(ifstream, ofstream, const char[], char[]); void formatData(char []); void getFileNames(char *&, char *&); void getFileToDecipher(const char[], char[]); bool getMessage(char* input, char* output, char msg_to_decipher[],                   const char PTEXT[], const char CTEXT[]); int getInputType(); void getKeyword(char *&); void getShiftKey(char &); void shiftKeyword(char [], char); //constants we will use const int FIVE = 5, TWENTYFIVE = 25, TWENTYSIX = 26,     TWENTYSEVEN = 27, SIXTYFIVE = 65, NINETY = 90,     NINETYTWO = 92, SIZE = 256; //------------------------------------------------ //Function: main() //Parameters: None //Return Type: int - 0 execution is normal, 1 abnormal termination //Purpose: Runs the main part of the program. //------------------------------------------------ int main() { char plaintext[TWENTYSEVEN] = {'A','B','C','D','E','F','G','H', 

Alternative Relationships

Up to this point the focus has been on using the development of a keyword-based mixed alphabet to create a ciphertext alphabet. Once that was accomplished, an alphabetic shift key was used to further mix the relationship between plaintext and ciphertext alphabets. In performing those tasks, the only information a message recipient requires is the keyword or keyword phrase and the alphabetic shift key to decipher a message through the use of a program. With a little knowledge of the method used to create a keyword-based mixed alphabet and the use of a shift key, most people can learn how to manually decipher a message. The major benefit of the previously described encipherment method is the ability of most persons to manually perform encipherment and decipherment with a minimum of information.

You can extend the use of keyword or keyword phrase mixed alphabets and alphabetic shifting to the plaintext alphabet. In fact, you can develop nine common alphabetic relationships that are listed in Table 3.1. You could also reverse the resulting plaintext, ciphertext, or both plaintext and ciphertext alphabets to further increase the number of alphabetic relationships. However, this may add a degree of confusion to both encipherment and decipherment due to the large number of options users could be forced to consider and remember. To keep your techniques practical, I’ll simply illustrate the use of two keyword-based mixed sequence alphabets for enciphering a message and leave it to you to modify CIPHER5.BAS to obtain other plaintext-ciphertext relationships.

Table 3.1 Common alphabetic relationships
plaintext alphabet in normal sequence ciphertext alphabet in normal sequence and shifted
plaintext alphabet in normal sequence ciphertext alphabet in keyword mixed sequence
plaintext alphabet in normal sequence ciphertext alphabet in keyword mixed sequence and shifted
plaintext alphabet in keyword mixed sequence ciphertext alphabet in normal sequence and shifted
plaintext alphabet in keyword mixed sequence ciphertext alphabet in keyword mixed sequence
plaintext alphabet in keyword mixed sequence ciphertext alphabet in keyword mixed sequence and shifted
plaintext alphabet in keyword mixed sequence and shifted ciphertext alphabet in normal sequence and shifted
plaintext alphabet in keyword mixed sequence and shifted ciphertext alphabet in keyword mixed sequence
plaintext alphabet in keyword mixed sequence and shifted ciphertext alphabet in keyword mixed sequence and shifted


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