78.

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 ENCIPHER.EXE Program

Up to this point, the programs developed in this book had significant restrictions concerning the character set available for encipherment. For example, most programs restricted the composition of a message to the uppercase alphabet, forcing users to spell out punctuation characters, such as COMMA for a “,” and PERIOD or STOP to signify the end of a sentence.

Because you may prefer to type a message following a minimum of constraints, a new set of programs was developed to perform message enciphering and deciphering operations. The enciphering program is contained in the file ENCIPHER.EXE on the CD-ROM in the form of a directly executable file. The source version of the program is stored on the file ENCIPHER.BAS, with both files located in the BASIC directory.

In a previous version of this book, only the executable version of the ENCIPHER program was provided. If you are curious as to why no source version of this program was provided, if you will let your curiosity wait a few minutes, the rationale for only providing executable versions of the pair of programs whose use is described in this chapter will become apparent.

The program ENCIPHER.EXE was created using seven previously developed subroutines as a foundation for enciphering. Listing 7.1 contains the main module of ENCIPHER.BAS, illustrating the sequence in which different subroutines are called. Our examination of the coding used in several subroutines will provide you with the ability to modify one or more subroutines or use different groups of subroutines to tailor an enciphering program to your specific requirements. This will ensure your program differs from this program and will make it much more difficult for someone to decipher a message they may gain access to. In fact, the author recommends that you develop your own program rather than rely upon any program available for use by the general public, since such a program is equivalent to one government providing a cipher machine to another government, especially if the latter is unfriendly. When this occurs, the unfriendly government will use the machine to attempt to decipher messages illicitly obtained by putting the machine through its paces, attempting one combination after another. The unfriendly government will more than likely also take the machine apart to determine what weaknesses exist and attempt to exploit those weaknesses. Due to the preceding, not all of the subroutines in the program ENCIPHER.BAS were discussed in the earlier version of this book.

Listing 7.1 The main portion of the ENCIPHER.BAS program.

 REM PROGRAM ENCIPHER.BAS DIM PLAINTEXT$(128), CIPHERTEXT$(36, 92), KEY$(128)   CLS   PRINT "ENCIPHER.EXE PROGRAM enciphers text based upon the use"   PRINT "of enciphering techniques contained in the book TOP SECRET:"   PRINT "TRANSMITTING ELECTRONIC MAIL USING PRACTICAL ENCIPHERING TECHNIQUES"   PRINT   PRINT "This program supports the use of upper and lower case letters,"   PRINT "digits, punctuation characters and other characters whose ASCII"   PRINT "values range between 32 and 128, but EXCLUDES the use of the"   PRINT "foward slash (/), backslash (\) and double quote characters."   PRINT   PRINT AGN1:   INPUT "Enter your secret code (6 characters required): "; CODE$   IF LEN(CODE$) = 6 THEN GOTO OK   CLS   PRINT "Your secret code must be 6 characters - please try again"   PRINT   GOTO AGN1 OK:  CLS GOSUB INITIALIZE         'initialize plaintext values GOSUB SETUP              'obtain random seed and position in seed GOSUB MSGFILE            'assign I/O files, place message on a file GOSUB KEYWORD            'form keyword based alphabet of 96 characters GOSUB PFORMCIPHER        'create 36 cipher alphabets GOSUB RCONVERTSTORE      'convert and store ciphertext on a file GOSUB PRTOUT             'print results STOP 

The subroutine INITIALIZE was modified to expand the ability of ENCIPHER.BAS to accept a wider mixture of characters. The subroutine, whose coding is listed in Listing 7.2, was modified to initialize a string array labeled PLAINTEXT$ to all characters whose ASCII values are between 32 and 127, except those characters whose ASCII values equal 34, 47, and 92. The latter restriction eliminates the forward and backslash characters as well as the quote (”) character from use in a message, except the first two characters can be used to denote a message header or the end of a message. In addition, those characters whose ASCII values equal or exceed 128 or are below 32 should not be used in your plaintext message. ASCII characters whose values are below 32 are control characters that are either non-printable or whose printing results in some strange effects, such as horizontal and vertical tabs, form feeds, and so on. This can significantly alter the display of an enciphered message, and the exclusion of those characters enables an enciphered message to more easily be input via the keyboard if this should become necessary. ASCII characters whose values exceed 127 are known as extended ASCII. Several popular electronic mail systems will not accept those characters, hence, I have excluded their use in both the plaintext message and the resulting ciphertext. The latter is accomplished by structuring the creation of a modulo addition process that results in ciphertext characters whose ASCII values are between 32 and 127. In spite of these restrictions, the program opens up the vast majority of your keyboard for use in creating messages. You can use all uppercase and lowercase alphabetic characters, the space character, all digits, and most punctuation characters to prepare your message.

Listing 7.2 The modified INITIALIZE subroutine.

 INITIALIZE:      RESTORE      REM Initialize plaintext values      I = 0      K = 32 GOOD:   IF K = 47 OR K = 92 OR K = 34 THEN GOTO NOGD'skip \, /  and "      PLAINTEXT$(I) = CHR$(K)      I = I + 1 NOGD:    K = K + 1      IF I < 128 GOTO GOOD RETURN 

When you examine the statements in the modified subroutine INITIALIZE, you may note that the variable I serves as the array index, while the variable K serves as the ASCII character value. Thus, when PLAINTEXT$(0)=CHR$(32), the 0 element of the string array PLAINTEXT$ is set to a space character. Thus, the coding in Listing 7.2 replaces the use of READ and DATA statements used in previous INITIALIZE subroutines.


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