16.

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


Since a goal of this book is to provide you with both BASIC and C++ modules you can incorporate into a program of your choice, the BASIC program SHIFT.BAS is also presented as a C++ program. Listing 2.2 provides the C++ program, which when executed produces the same results as those shown in the lower portion of Listing 2.1. As previously mentioned, C++ programs presented in this book were developed using Microsoft’s Visual C++ program development package. Although Visual C++ can be considered to represent a “standardized” version of C++, it is probably worthwhile to review some items in the program listing. First, the array PLAINTEXT is used as a character array to contain the uppercase letters A through Z. Those characters are stored in elements 0 through 25 in the array. The increment operators (++) are positioned after each integer used for looping (i and j), which results in each integer being incremented after it is used in the loop. The first printf statement displays a sequence of 25 characters controlled by the i loop with the percent (%) sign used to represent modulo arithmetic. Once 25 characters are printed, the i loop terminates and the second printf statement simply generates a line feed. Both the program SHIFT.CPP and an executable version of the program stored under the filename SHIFT.EXE are contained on the CD-ROM accompanying this book. Source BASIC language programs and executable files are located in the BASIC directory, while source C++ language programs and executable files are located in the C directory.

Listing 2.2 The SHIFT.CPP program listing.

 /*       PROGRAM SHIFT.C */ /*      This program produces a sequence of shifted alphabets */ #include <stdio.h> int main() {    int i,j;    char PLAINTEXT[26] = {'A','B','C','D','E',            'F','G','H','I','J',            'K','L','M','N','O',            'P','Q','R','S','T',            'U','V','W','X','Y','Z'};     for ( j=0; j<=25; j++)     {for (i=0; i<=25; i++)     { printf("%c",PLAINTEXT[(i+j)%26]);     } printf("\n");     } return (0); } 

In addition to a direct relationship between plaintext and ciphertext alphabets, you can reverse the relationship. That is, you can reverse and displace the ciphertext alphabet with respect to the plaintext alphabet. In doing so, the ciphertext can be applied to the plaintext alphabet at any of 26 points of coincidence between the two alphabets. Thus, you can develop a series of 25 reverse ciphertext alphabets with respect to a plaintext alphabet when both are restricted to uppercase English letters. Figure 2.2 illustrates an example of a reverse ciphertext alphabet in which the first letter of both the plaintext and ciphertext alphabets coincide. Note that the reverse ciphertext alphabet can also be shifted or displaced a total of 25 times prior to the relationship between plaintext and ciphertext characters repeats.


Figure 2.2  Reverse ciphertext alphabet.

The relationship between a plaintext and ciphertext alphabet can be direct or reversed. For either situation, the characters in one alphabet can be shifted n positions, or 0<n<25, with respect to the other alphabet prior to the alphabet repeating.

You can denote the relationship between plaintext and ciphertext alphabets through the location where the ciphertext alphabet coincides with the first letter (A) of the plaintext alphabet. This location is commonly referred to as the alphabetic shift key. For the ciphertext alphabet illustrated in Figure 2.1, the shift key can be expressed as PA=CF, where the P and C denote plaintext and ciphertext alphabets, and the subscript letters indicate the relationship between the two alphabets with respect to the beginning of the plaintext and ciphertext alphabets. For the reverse ciphertext alphabet illustrated in Figure 2.2, the alphabetic shift key can be expressed as PA=R(CA), where R indicates a reversal of the ciphertext alphabet beginning with the letter A.

Encipherment

To illustrate encipherment and decipherment operations, I’ll use the simple displacement relationship between ciphertext and plaintext alphabets previously illustrated in Figure 2.1. In that example, the alphabetic shift key, PA=CF, defined the relationship between the two alphabets.

Suppose you wish to encipher the message MEET ME IN ST LOUIS. You would first locate M in the plaintext and note that it is replaced by R in the ciphertext alphabet. Next, each plaintext E would be replaced by a ciphertext J, and so on. The plaintext message’s completed encipherment would yield RJJY RJ NS XY QTZNX.

In military systems, the resulting enciphered message would more than likely be rewritten into groups of five characters for transmission to minimize the effect of a transmission error and facilitate the transmission and reconstruction of the original message. Thus, if you were transmitting the message you might consider sending it as:

        RJJYR JNSXY QTZNX 

Note that in placing the enciphered message into groups of five characters you remove spaces between words. This is usually done to eliminate obvious word groupings that would facilitate the decipherment of the message if it fell into the hands of the wrong party. Because this message has exactly 15 characters, it fills up three groups of five characters. This is not always the case, however, and unfilled groups are normally filled with one or more predefined letters known as message nulls. The most common message null is the letter X and should not be confused with the ASCII null character which represents a blank.


Care should be taken in selecting characters to fill ending message groups and terminating messages. In many military units, messages were terminated with the abbreviation FTA or one or more of those characters was used to terminate an ending message group. Not only was the abbreviation an obscene message concerning the Army, but more significantly , its inclusion in an enciphered message provided an enemy intercepting the message with the ability to rapidly gain knowledge concerning a portion of the substitution process used to encipher the message. Given that insight, with some additional effort, the entire contents of the message becomes vulnerable to decipherment.


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