Classic Computer Magazine Archive COMPUTE! ISSUE 20 / JANUARY 1982 / PAGE 103

THE ATARI® GAZETTE

Cryptogram

Ronald and Lynn Marcuse Freehold, NJ

Word games are just one of many applications which can be programmed on the versatile ATARI computers. While not challenging your reflexes as does Space Invaders or Star Raiders, they do challenge your mind. With the number of graphic action games approaching infinity in our house, we predicted that our two school-age offspring will be competent space shuttle pilots by the time they reach 18. Unfortunately, they may not be able to read. An educational computer word game may be capable of swinging the pendulum the other way, or at least slow down the onrushing invaders.

Most of the electronic word games currently being marketed are variations of the "hangman" game, where you are required to guess an unknown word by specifying its letter content within a certain number of tries. If you fail, you are then "hanged" or punished in some similar manner. A cryptogram, however, challenges your ability to decipher coded phrases or messages. Not wanting to generate an "unbreakable" code, we used a simple letter substitution. Each letter in the statement is replaced uniformly by some other alphabetic character. For example, all of the A's may appear as G's, the B's as Y's, etc. Don't bother to memorize these relationships because the structure of the code changes each game. Spaces between words and punctuation remain intact.

There are two skill levels in the game, selectable through the OPTION key. With the first, the program will decipher the vowels for you, leaving you only the consonents to decode. With the second option you are on your own. We had originally programmed three options, the third being a compression of the statement into one long string (removal of spaces), but deciphering of the phrase became rather difficult. The SELECT key is utilized to vary the number of participants. For the two person version, one player would enter a statement for the other to decode. In the one player game, the computer will randomly select one of fifty popular (?) expressions stored in the program. These phrases appear as the DATA statements in lines 1010-1500. You may change this list if you desire. Just make sure that you wind up with exactly 50 statements and that each one is no longer than 75 characters (including spaces and punctuation). You may use any punctuation with the exception of the comma.

How To Play

A game in progress may be saved to either disk or tape. Program 1 contains the disk version. Program 2 displays changes required for the recorder. In saving the game, the disk version will request a three character (or less) name which will be appended to the file name. The tape version will require you to insert a blank tape in the recorder. Make a note of the recorder counter. The procedure for loading a saved game is similar, but you must supply either the file name extender or tape that has been positioned (using the counter) in the recorder.

To start a game type "N" to the program prompt "SHOULD I LOAD A SAVED GAME" and then pick the skill level and number of players by pressing the OPTION and SELECT keys. Press the START key to begin. You may need to depress the keys for a second or two to register your action. This may be speeded up by shortening the timing loop at line 990. If you had chosen the two player option, the program will prompt you to enter a phrase or message to be encoded. This must be from 20 to 75 characters in length. Shorter phrases are actually harder to decipher than long ones. In the one player option, the program will randomly select one of the fifty DATA statements.

After the encoding process is completed (it takes approximately 15 seconds to generate the code and substitute the letters), the game screen is displayed. At the top of the display is a table showing the code letters and values that you have assigned to the code. The next group of lines contain the "secret phrase" and your working translation. These alternate if the phrase is longer than one line in length. If skill level 1 had been selected, the vowels would have already been translated for you. At the bottom of the display is the input area for code letters and values. Enter a code letter and then the substitution you would like to perform. An arrow cursor alternates between the two input lines. To erase a previous entry, first type the code letter and then press the space bar.

When you have correctly substituted all of the characters, the program will notify you graphically. You may also press the ESCAPE key to end the game. This will allow you to save the game, quit, or try a new phrase. If you are short on RAM (under 24K), the REMARK statements may be omitted with no ill effects.

Lines 18 through 30 comprise the "housekeeping" section of the program. The left screen margin is set to 1 (POKE 82,1) for those TV sets that overscan, the keyboard is OPENed and the variables are DIMensioned here. The alphabet is stored in A$, the substitution code in B$, and the table entries for the game display in T$, P$, C$, and Q$ are the actual phrase, the coded phrase, and the working translation, respectively. The array X (with 26 elements) is used by the code generation routine.

If a saved game is being reloaded (prompt in line 40), the data is input and control is sent directly to the main game display at line 400. Otherwise, the variables are cleared (lines 80-90) and the option screen is generated (starting at line 100). Memory location 53279 is the register used to read the console keys on the ATARI computer. The address is first cleared by POKE 53279,8 and then queried by PEEKing at it in the loop from lines 120 through 180. We are concerned with the binary value that is stored in that address.

The START key is assigned to bit 0, the SELECT key to bit 1, and the OPTION key to bit 3. A value of zero in the bit position means that the key was pressed. For example, if the START key is hit, the SELECT and OPTION keys would register decimal values of 2 and 4 in their respective bit positions. The START key would return a zero in the low order bit, giving a total of 6 (decimal). Likewise, the SELECT key would equal a decimal 5 (4 + 1) and the OPTION key would be 3 (2 + 1).

If the two player option was selected, the phrase would be input in line 220, otherwise the program will randomly select one of the fifty data statements in line 240. In lines 250 through 290, the program generates the substitution code. A random letter (from A$) is selected and, if that element of the X array is still set to zero, the B$ sub-string position is equated to the letter. The array is used to check off letters that have already been used. This type of algorithm could easily be expanded to a card shuffling routine if you prefer poker to word games.

The substitution of the code letters into the phrase is done in lines 300 to 380. If skill level 1 was selected (SK = 1) then the ATASCII value of the phrase letter is checked to see if it is a vowel (values of 1,5,9,15, and 21). If it is, the letter is moved into the translation line Q$, otherwise the character "-" occupies that position. The program must also count backwards from 38 looking for the first space to break the line on.

The game board is displayed in lines 400-430 and the input of code letters and substitutions is performed in lines 500-520. After the data is received, the modified table elements are redisplayed in line 530 and the revised translation line in 540-560. If the translation is the same as the phrase (line 560), you are sent to the winners circle at line 700, otherwise you go back to 510 for more data. Pressing the ESCAPE key (an ATASCII value of 27) would cause a jump to line 800 for your exit options. The POP statement in line 915 is necessary to reset the stack pointer for the non-RETURN exit out of the subroutine.

The remainder of the program is routines for the winning and losing displays, input and printing of data, the exit options, and the saving of games in progress. The variables saved, either on disk or tape, are P$, C$, and Q$ (the original phrase, the coded phrase the the current translation), T$ (the assignment table), and the lengths of the phrase (L) and its first line segment (L1). For the disk version of the program, the format of the saved game is D:CRYPTG. + the 3 character name that was entered.