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
Figure 4.6 illustrates the execution of the program CIPHERTR.BAS to
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
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
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
Figure 4.7 The execution of CIPHERTR.BAS program using a numeric transposition keyword mixed alphabet.
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