44.

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 CIPHER6.BAS Program

To illustrate the execution of the interval extraction subroutine, I’ll incorporate that routine into a program which enciphers messages based upon any one of the three alphabet formation techniques presented earlier in this chapter—interval extraction, simple transposition, and numeric transposition. This program, which is contained on the file CIPHER6.BAS on the companion CD-ROM, contains extraneous PRINT statements highlighted with five asterisks as comments which were included to facilitate explaining the operation of the program. You may want to remove those statements from the program if you wish to use it or distribute it to associates for use.

Listing 4.6 contains the statements that make up the main portion of the CIPHER6.BAS program. The first group of statements starting with the label “START” simply displays the program’s options, accepts the user-specified enciphering method, and assigns a value to the string variable ORDER$ based upon the type of enciphering technique selected.

Listing 4.6 The main portion of the CIPHER6.BAS program.

 REM PROGRAM CIPHER6.BAS DIM PLAINTEXT$(26), CIPHERTEXT$(26), KEY$(26), TRANS$(26, 26), TEMP$(26) START:  CLS     PRINT "PROGRAM CIPHER6.BAS ENCIPHERS A MESSAGE USING ONE"     PRINT "OF THE FOLLOWING TECHNIQUES TO FORM A CIPHER ALPHABET"     PRINT " (1) INTERVAL EXTRACTION SEQUENCE"     PRINT " (2) SIMPLE TRANSPOSITION SEQUENCE"     PRINT " (3) NUMERIC TRANSPOSITION SEQUENCE"     PRINT     INPUT "Enter method to form enciphered message 1, 2 or 3: ", X     IF X < 1 OR X > 3 THEN GOTO START     IF X = 2 THEN ORDER$ = "SIMPLE"     IF X = 3 THEN ORDER$ = "NUMERIC"     IF X > 1 THEN GOTO TRAN     INPUT "Enter the interval as a numeric between 1 and 25: ", INTERVAL TRAN:   INPUT "Enter keyword or keyword phrase in UPPERCASE: ", TEXT$     PRINT GOSUB INITIALIZE     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$     '***** ON X GOSUB INTERVAL, TRANSPORT, TRANSPORT     IF X = 1 THEN PRINT "Interval Alphabet is              : "; X$     IF X > 1 THEN PRINT ORDER$; " Transposition 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 MSGFILE             'assign I/O files, place message on a file GOSUB CONVERTSTORE        'convert and store ciphertext on a file GOSUB PRTOUT              'print results STOP 

If an interval extraction technique is selected, the user is prompted to enter the interval to be used. Regardless of the enciphering method selected, the user is then prompted to enter a keyword or keyword phrase that will be used to form a keyword-based mixed alphabet. Both the plaintext alphabet and keyword-based mixed alphabet are displayed through the use of extraneous PRINT statements you can remove. You should note that the subroutines INITIALIZE and KEYWORD, as well as the other subroutines invoked from the main portion of CIPHER6.BAS, contain the statements previously described in this book and will not be reviewed again.

The ON X GOSUB statement causes a branch to the INTERVAL or TRANSPORT subroutine based upon the user-selected encipherment method that was assigned to the variable X. After one of those subroutines is invoked, the appropriate alphabet is displayed by the use of extraneous IF-THEN PRINT statements that can be removed from the program. The program accepts an alphabetic shift key, invokes the FORMCIPHER subroutine, and displays the shifted keyword mixed alphabet which, in effect, is the cipher alphabet. Again, you can remove the extraneous PRINT statements if you so desire. Thereafter, the program invokes four more subroutines that reinitialize the plaintext array, assign I/O files and place a message on a file, convert and store the ciphertext on a file, and print the results of the encipherment operation.

Figure 4.8 illustrates the execution of CIPHER6.BAS when an interval extraction technique is used to form a cipher alphabet. In this example, the keyword MICROSOFT was used to form the keyword-based alphabet. It is that alphabet that is used as the basis for forming the interval alphabet. Because 3 was entered as the extraction interval, every third character in the keyword-based alphabet is removed to form the interval alphabet. Thus, C is extracted, followed by S, and so on from the keyword-based alphabet.


Figure 4.8  The execution of CIPHER6.BAS.

The selection of B as the shift key causes the interval alphabet to be rotated so that the character B in the alphabet is positioned at the extreme right. The resulting shifted keyword mixed alphabet formed using an interval extraction method represents the ciphertext alphabet. Thus, first locate each character in the message in the plaintext alphabet and then extract the character in the equivalent position in the shifted-keyword mixed alphabet.

Note that the message WE MUST MEET… results in the enciphered message MYWUJ NWYYN… You can verify the accuracy of the encipherment process by noting that the position of W in the plaintext message is equivalent to M in the shifted keyword mixed alphabet, E has the same position as Y, and so on, verifying the accuracy of the enciphering process.


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