80.

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 7.5 The modified RCONVERTSTORE subroutine.

 RCONVERTSTORE:   REM Routine to convert and store ciphertext on a file   OPEN INFILE$ FOR INPUT AS #1   OPEN OUTFILE$ FOR OUTPUT AS #2   ALPHA = 0     'first alphabetic pointer   PRINT "Enciphering operation in progress ";   DO UNTIL EOF(1)      INPUT #1, TEXT$      PRINT ".";      MSGLEN = LEN(TEXT$)      IF MID$(TEXT$, 1, 1) = "/" THEN GOTO CLEARTXT1      IF MID$(TEXT$, 1, 1) = "\" THEN GOTO DONE2      REM Convert plaintext to ciphertext         FOR I = 1 TO MSGLEN         X = INT(RND * 100)       'get 2-digit integer         X = INT(X / 1.087)       'smooth to 0 to 92         FOR J = 0 TO 92         IF MID$(TEXT$, I, 1) = PLAINTEXT$(J) THEN GOTO MATCH         NEXT J MATCH:     Z = (J + X) MOD 92         MID$(TEXT$, I, 1) = CIPHERTEXT$(ALPHA, Z)         NEXT I         ALPHA = ALPHA + 1         IF ALPHA = 35 THEN ALPHA = 0'reset alphapet pointer CLEARTXT1:    WRITE #2, TEXT$   LOOP DONE2:  CLOSE #2      CLOSE #1 RETURN PRTOUT: REM Subroutine to print results   PRINT   INPUT "Press Return key to display resulting enciphered message", p$   CLS: TEMP$ = ""   PRINT "Resulting enciphered message is:"   OPEN OUTFILE$ FOR INPUT AS #2   DO UNTIL EOF(2)      INPUT #2, TEXT$      IF MID$(TEXT$, 1, 1) = "/" THEN PRINT RIGHT$(TEXT$, LEN (TEXT$) - 1)      IF MID$(TEXT$, 1, 1) = "/" THEN GOTO NOGROUP      PRINT TEXT$ NOGROUP: LOOP   CLOSE #1: CLOSE #2 RETURN 

To provide you with an indication of how to position the random number generator based upon the composition of a secret code, Listing 7.6 gives the contents of the subroutine SETUP. In examining the statements in the subroutine, note that the seed is set to the value of the product of the first and sixth characters in the secret code. Next, the integer value of the product of the ASCII values of the even characters in the six-position code is used as an initial offset, and the product of the ASCII values of the first and third characters in the code are used as a delimiter in a FOR-NEXT loop, with the value of the second character used to step through the loop.

Listing 7.6 The SETUP subroutine positions the random number generator based upon the composition of the secret code.

 SETUP:    REM routine to position the random number generator based upon    REM the composition of the secret code    FOR I = 1 TO LEN(CODE$)    CODE(I) = ASC(MID$(CODE$, I, 1))    NEXT I    SEED = CODE(1) * CODE(6)    MAX = INT(CODE(2) * CODE(4) * CODE(6))    RANDOMIZE SEED    FOR I = 1 TO MAX STEP (CODE(5) * CODE(1))   'position into sequence    DUMMY = RND    NEXT I    FOR I = 1 TO CODE(1) * CODE(3) STEP CODE(2) 'further offset into                                                                sequence    DUMMY = RND    NEXT I RETURN 

The execution of the program ENCIPHER.EXE is illustrated in Figures 7.1 through 7.3. Figure 7.1 illustrates the display of the first screen of the program which first displays information about the program and then prompts you to enter a six-digit “secret” code. Unlike the restrictions on the plaintext characters in a message, the code can consist of most characters in the ASCII character set; however, as discussed in this book, you should select a code that is not difficult to repeat. Thus, I recommend the use of printable characters.


Figure 7.1  The first screen display of the ENCHIPHER.EXE program.

Figure 7.2 illustrates the second screen displayed when the program ENCIPHER.EXE is executed. This screen first displays information concerning the filenames to be used to store the plaintext and ciphertext messages. Because the keyboard was selected for entering the plaintext message, the program then displays information concerning the use of the forward and backslash characters. As in our previously developed programs, the forward slash is used to prefix headers that should remain as plaintext, while the backslash is used to indicate the termination of the message.


Figure 7.2  The second screen displayed upon execution of ENCHIPHER.EXE.

After the previously discussed information is displayed, you can enter your message. After the backslash character is entered, the program displays the message “Enciphering operation in progress…” Because the program can require from a few seconds to half a minute or more depending upon the computer you use to encipher your message, dots are displayed while the program executes so you will know it is working. Once the encipherment operation is completed, the message “Press Return key to display resulting enciphered message” is displayed. Once you press the Return key, the resulting enciphered message is displayed as illustrated in Figure 7.3. In addition, the enciphered message is also written onto the file CIPHERTX.DAT, so you can transfer that file via a communications program if you so desire.


Figure 7.3  The enciphered message created ENCIPHER.BAS.


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