Previous | Table of Contents | Next |
After developing CIPHER5.BAS and CIPHER5.CPP, its only logical that a mechanism is required to restore a received message to its original plaintext content. In this section, several previously developed subroutines are modified and incorporated into programs appropriately named DCIPHER5.BAS and DCIPHER5.CPP as they perform the inverse function of CIPHER5.BAS and CIPHER5.CPP. Although you could incorporate deciphering operations into CIPHER5.BAS and CIPHER5.CPP, it is easier to explain deciphering coding operations as a separate entity. In addition, some organizations may prefer to limit non-headquarters or certain corporate locations capability to deciphering messages and preclude those locations from originating enciphered messages. Thus, the separation of enciphering and deciphering operations may be preferred by some users. For other users who prefer a program that combines both operations, Ill develop such programs using more sophisticated enciphering techniques later in this book. However, because the focus is on the development of modular routines, Ill show you the ease in which modules from both programs can be combined.
Prior to developing the coding required to decipher a message created through the use of a keyword or keyword phrase and an alphabetic shift, it may be useful to review the manual process required to decipher a message enciphered in this manner.
To correctly decipher an enciphered message developed using a keyword or keyword phrase and shift key requires knowledge of both elements. Once both elements are known, you can construct a keyword-based mixed alphabet and shift the alphabet to obtain the cipher alphabet. To initiate the deciphering process, place the cipher alphabet above the plaintext alphabet. For each letter in the enciphered message, first locate its position in the cipher alphabet and extract the plaintext character at the position in the alphabet which equals the position of the enciphered character in the cipher alphabet. For example, assume the keyword phrase was GODSAVETHEQUEEN and that the shift key is the character B. In this case the keyword-based alphabet becomes GODSAVETHQUNBCFIJKLMPRWXYZ. Because the shift key is the character B, shift the keyword-based alphabet until it is positioned so that the character B is on the extreme right. Remember that the alphabetic shift key was previously defined as an uppercase character in the plaintext alphabet that defines the location where the right end of the resulting shifted alphabet ends. Thus, using the shift key character B results in the cipher alphabet becoming: CFIJKLMPRWXYZGODSAVETHQUNB.
Now that you have constructed the cipher alphabet based upon the predefined keyword phrase and shift key, place that alphabet above the plaintext alphabet as shown below:
Cipher alphabet: CFIJKLMPRWXYZGODSAVETHQUNB Plaintext alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Now suppose the first two groups of five enciphered characters in a received message are LRAKW OVKDP. Searching the cipher alphabet, you would first locate the character L and read down the same position into the plaintext alphabet to extract the character F. Similarly, locating R in the cipher alphabet results in extracting I from the plaintext, A results in extracting R from the plaintext alphabet, K in the cipher alphabet produces E in the plaintext alphabet, and so on. Thus, LRAKW OVKDP in the enciphered message is equivalent to FIREJOSEPH in plaintext. Now that you have a feeling for the manual process required to decipher an enciphered message, lets construct a program to automate this process.
To automate deciphering of a previously enciphered message based upon the use of a keyword or keyword phrase and an alphabetic shift key, Ill first construct a program appropriately named DCIPHER5.BAS. In doing so, Ill use all of the previously developed subroutines included in CIPHER5.BAS as is, or in a slightly modified form. To indicate that a change was made to a previously developed subroutine, Ill prefix its name with the character D to indicate its modification for deciphering a received message.
Listing 3.5 contains the statements that make up the main portion of DCIPHER5.BAS. Similar to the statements in CIPHER5.BAS, a comment of five asterisks is used to denote a PRINT statement included for illustrative purposes and whose elimination will not affect the operation of the program.
Listing 3.5 The main portion of the DCIPHER5.BAS program.
REM PROGRAM DCIPHER5.BAS DIM PLAINTEXT$(26), CIPHERTEXT$(26), KEY$(26) CLS GOSUB INITIALIZE PRINT "DCIPHER5.BAS PROGRAM deciphers text based upon the use of a keyword or keyword" PRINT "phrase and an alphabetic shift key using a monoalphabetic substitution process." PRINT INPUT "Enter keyword or keyword phrase in UPPERCASE: ", TEXT$ PRINT "Plaintext based alphabet is : "; '***** FOR I = 0 TO 25: PRINT PLAINTEXT$(I);: NEXT I '***** GOSUB KEYWORD 'form keyword-based mixed alphabet PRINT "Keyword-based alphabet is : "; X$ '***** 1 INPUT "Enter UPPERCASE Alphabetic Shift Key: ", K$ FOR I = 0 TO 25 IF K$ = PLAINTEXT$(I) GOTO 2 NEXT I PRINT "You must enter a letter from A to Z" GOTO 1 2 REM Position I represents shift key letter GOSUB FORMCIPHER 'create cipher alphabet PRINT "Shifted keyword mixed alphabet is : "; '***** FOR I = 0 TO 25: PRINT CIPHERTEXT$(I);: NEXT I: PRINT '***** GOSUB INITIALIZE 'reinitialize plaintext array GOSUB DMSGFILE 'assign I/O files, place message on a file GOSUB DCONVERTSTORE 'convert and store plaintext on a file GOSUB PRTOUT 'print results STOP
It should be noted that the only difference between the main portion of CIPHER5.BAS and DCIPHER5.BAS is the subroutine names DMSGFILE and DCONVERTSTORE. Since you noted that the character D would be used as a prefix to indicate a change to a previously developed subroutine for decipherment operations, let us focus our attention on those two subroutines.
Previous | Table of Contents | Next |