41.

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


Listing 4.2 The main part of CIPHERTR.BAS and the calling sequence to invoke the TRANSPORT subroutine.

 REM PROGRAM CIPHERTR.BAS DIM PLAINTEXT$(26), CIPHERTEXT$(26), KEY$(26), TRANS$(26, 26), TEMP$(26)     CLS     PRINT "PROGRAM CIPHERTR.BAS enciphers a message using a                transposition matrix"     PRINT "and a monoalphabetic substitution process based upon a                keyword"     PRINT "or keyword phrase and an alphabetic shift key."     PRINT GOSUB INITIALIZE     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$  '*****     INPUT "Enter transposition matrix method - SIMPLE or NUMERIC :",            ORDER$ GOSUB TRANSPORT     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 

The CIPHERTR.BAS Program

Figure 4.6 illustrates the execution of the program CIPHERTR.BAS to encipher a message based upon the use of a simple transposition mixed sequence alphabet and an alphabetic shift key. This example uses the keyword KEYWORD and the alphabetic shift character C. Note the display of the 4-row-by-7-column matrix formed by the TRANSPORT subroutine. Because a simple transposition method was selected, the letters in the matrix are extracted in column order, KAJT followed by EBLU, and so on. This is verified by the line after the end of the matrix display.


Figure 4.6  The execution of CIPHERTR.BAS program using a simple transposition keyword mixed alphabet.

As in previous examples, an alphabetic shift key character results in the shift of a previously developed alphabet so that the position of the shift key letter is rotated to the right of the alphabet. Entering the shift key C rotates the simple transposition alphabet by ten positions.

The plaintext alphabet should be compared to the shifted keyword mixed alphabet for the encipherment of a message, because the latter alphabet is the ciphertext alphabet. In this example the message to be enciphered is MEET ME IN ST LOUIS ON FRIDAY FEBRUARY THIRTEEN AT NINE PM. The M in the plaintext alphabet corresponds to the letter Q in the shifted keyword mixed alphabet. Thus, the first character in the enciphered message is Q. The character E in the message is located in the plaintext alphabet. Because its position corresponds to the position of the character N in the shifted keyword mixed alphabet, replace E with N and continue the process to verify the operation of the portion of the program which enciphers a message based upon a simple transposition mixed alphabet and alphabetic shift key.

Figure 4.7 illustrates the execution of the program CIPHERTR.BAS when a numeric transposition mixed alphabet was selected. Because D is the lowest character in the keyword KEYWORD, the characters in the column headed by D are extracted first. Thus, DIS are the first three letters displayed for the numeric transposition alphabet. Because E is the next lowest letter in the keyword, the contents of the column headed by E are added to the alphabet. Thus, EBLU follows the characters DIS. You can examine the remainder of Figure 4.7 to verify that the message is indeed enciphered correctly by using the relationship between the plaintext and shifted keyword mixed alphabets displayed in that illustration.


Figure 4.7  The execution of CIPHERTR.BAS program using a numeric transposition keyword mixed alphabet.

The INTERVAL Subroutine

Listing 4.3 contains the contents of the subroutine INTERVAL, which forms an interval extracted alphabet based upon a predefined interval. That interval is passed to the subroutine in the variable INTERVAL.

Listing 4.3 The INTERVAL subroutine used to form an interval extracted alphabet.

 INTERVAL:     REM Subroutine to form interval extracted alphabet     COUNT = 0     I = INTERVAL - 1  'adjust since array starts at 0     X$ = ""     DO UNTIL COUNT >= 26         X$ = X$ + PLAINTEXT$(I)         COUNT = COUNT + 1         I = I + INTERVAL         IF I >= 26 THEN I = I - 26     LOOP     REM Put back into PLAINTEXT$ array     FOR I = 0 TO 25     PLAINTEXT$(I) = MID$(X$, I + 1, 1)     NEXT I RETURN 

Note in Listing 4.3 that the interval value is decreased by 1 since the array starts at element 0. The DO UNTIL COUNT loop extracts each character from the string array PLAINTEXT$ until all of the characters are extracted. Note that whenever I equals or exceeds 26, you should reset I to I-26. This recirculates the sequence. Also note that since you are using the string array PLAINTEXT$, you must invoke the subroutine KEYWORD prior to invoking the subroutine INTERVAL if you wish to use an interval extraction based upon a keyword mixed alphabet. Similar to the TRANSPORT subroutine, conclude the INTERVAL subroutine by placing the interval extracted alphabet back into the array PLAINTEXT$.


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