TOP SECRET by John Amphlett from ZX Computing Apr/May.1985 John Amphlett, masterspy of Haverford West, gives us a means of keeping our secrets safe! This secret message encoding / decoding program (16K SPECTRUM) combines a high degree of security with ease of operation. The main features are:- A) The original clear message consists of capital letters, spaces and full stops, making an "alphabet" of 28 characters. B) The coded message, which has the same length as the clear original, uses 52 characters, 26 normal and 26 underlined capital letters. This method of distinguishing the second half of the coded character set was chosen because both the Spectrum and the typewriter can easily underline already printed characters in the same print position. C) The elements of the original message are changed to coded ones by shifting the ZX character codes up and around the alphabet "circle". This is done by adding a variety of fixed and randomly chosen integers to the codes then subtracting the necessary multiples of 26. Decoding is performed in the opposite direction. D) The special feature of this program, and one that really makes such high security possible, is that one of these integers is the ZX code of the already processed previous element. This means that the value of a coded element depends partly on the value of its immediate predecessor and therefore the whole coded message is made much more difficult to break. On running the program, the operator is asked to enter the Code Number (which controls the RANDOMIZE function), the Code Letter (which becomes the first integer to be added to the first element) and the Station Number (the number of the originating operator). Then he must enter "E" or "D" for the encode or decode mode. Next he types in the message, clear or coded as appropriate, and after pressing ENTER the processed message is displayed on the screen. Finally, after the result is verified, both original and processed messages are displayed together. For those readers who are interested in programming techniques, here is a brief description of the program. The first section (lines 10 to 60) sets up some of the fixed variables and gives the initial input prompts. Line 60 ensures that the appropriate clear and coded messages appear on the screen on the right lines by means of variables E and D. The second section (lines 85 to 140) uses the familiar "typewriter" routine to enter the original message. The important part of this section is the OVERprinting routine in line 120 which adds an underline character U$ to a previously printed normal letter when the decode mode is operating. This is done simply by pressing the "0" key immediately after the letter so to be treated. Mistakes can be rectified by pressing the "5" key (line 115) then typing in the correct letter. Repeated pressing of the "5" key will erase letters as far back as you wish. Line 110 provides a BEEP sound when typing and an "end of message" signal which triggers the jump out of the typing loop. The message is printed out on the screen as you go and is also concatenated in B$ in line 125 and subsequently transferred to M$ for use in either of the next two sections. B$ is returned to a null string while O$ is held ready for the final display. The encoding section (lines 200 to 275) takes each element of M$ in turn, carries out the arithmetic, adds an underline where appropriate and types out the coded result along the encoding line on the screen. First, the RANDOMIZE function and the variable T (the code of the "previous" element) are set outside the encoding loop and the random number generator and the variable U (the underline signal) are set inside. Then the two extra characters, the space (code 32) and the full stop (code 46), are given code numbers immediately before the beginning of the letter alphabet (codes 63 and 64 respectively) by line 225. Then, line 230 makes all the even numbers except 90 change U to zero whilst all the odd numbers except 63 are left set to unity. The reason for this is that the letters Y and Z will, after the reverse arithmetic procedure in the decode mode, end up with codes 63 and 64, the same as the space and full stop, and will therefore be incorrectly decoded. Hence the Y and Z are given the underline signal and will have an extra 26 added in line 355. The next three lines perform the necessary arithmetic and in line 250 the value of T is changed to that of the new A and used next time round the loop. Line 255 adds the underline character to the appropriate coded element. The message is printed out on the encoding line on the screen letter by letter, and B$ collects them in a string as before. The last two lines in this section sort out what happens next, line 275 passes the coded message to M$ for use in the next section for the verification routine and to P$ for use in the final section, while line 270 operates in the decode mode and passes straight to the final section. Decoding The decode section (lines 300 to 375) has the same pattern as the encode section so that most of the action is similar. There is, however, one major difference. The coded message M$ is printed near the bottom of the screen and SCREEN$ picks up the elements one by one in line 325. Where there is an underlined character, it is not recognised in line 330. The underline is cancelled by being reprinted, U is changed to unity and the program refers back to line 325 when the normal letter is now recognised and processed. It may be argued that the use of SCREEN$ is a rather clumsy way of doing things. It would be much simpler and neater to use M$(X) directly. I agree, but it is much more fun to watch those underlinings disappear one by one when the decoding section is working. The final section (lines 400 to 420) clears the screen and displays both the original and processed messages in full. Although the program as it stands works well, there is a limitation. Only one line of 31 characters can be dealt with at one time. However, it should be fairly easy to make a few necessary alterations to the print statements to get over that. Other improvements spring to mind, such as multiple coding, speedier action (approximately 12 seconds a line at the moment), expanding the character vocabulary and so on. Perhaps it is better to leave it to others to develop these ideas. Variables A$ elements of M$ A arithmetic process B$ concatenation of A$ B = A/2 (odd or even) E$ encode/decode input D decode L$ code letter E encode M$ complete message N code number O$ original message R random number P$ processed message S station number U$ underline character T "addition" number V$ continue prompt U underline signal Z$ one line of spaces X loop control (CHR$ 8 = back space CHR$ 128 = blank space) -- Another Fine Product transcribed by: Jim Grimwood (jimg@globalnet.co.uk), Weardale, England --