www.jupiter-ace.co.uk

Previous Page > Listings Index > Electronic Scrambler


NOTE: Update November 2007

Ricardo found a bug in this article and has a fix;-

Analysing the code I have found that the strings in the "Z" word was oversized and it causes the screen lines to scroll up messing with the decode process. Shortening "characters" to "chars" on that strings solved the problem.

Below is the code in action.
The code for this article can be found in the software index see [Software Tab > Archive & download]

ELECTRONICS & COMPUTING MAY 1982 page 42
JUPITER ACE ELECTRONIC
SCRAMBLER
 

by Ralph Hilton

This article details the listing and theory behind a program that enables one to scramble screens of data in such a fashion that they can only be decoded by use of a specific codeword. This is not a simple substitution code that can be broken by studying the frequencies of symbols but one that uses a bit by bit coding available with the use of the exclusive-or function of the Ace.



First of all I shall go into the logic methods of the coding technique then, as FORTH is a new language for a lot of readers, I shall explain the listing step by step.
The basic XOR function in the Ace compares 2 bytes of memory bit by hit returning a 1 whenever the 2 bits compared are different. For example( in base 2) 11110000 10101010 xor gives 01011010. It is an interesting and useful feature of the xor function that if you perform the operation twice with the same numbers then you get back what you started with so that x y xor y xor gives y. In our earlier example 01011010 10101010 xor gives us back the original 11110000.
As each character in the memory of the computer is held as an 8 bit binary number it is fairly simple to hold a code word in memory and xor a message to be coded with it. This gives us a scrambled message that is totally lacking any pattern and will not yield to any attempts at frequency analysis.
To crack this form of coding would, I imagine, require a considerable time from a large computer which would have to analyze the billions of possible combinations in a long and laborious fashion. While it is not totally undecodable it is probably safe from anything but a large mainframe with some pretty intricate software.
The program itself performs all its coding and decoding operations with the display file so that one puts the message to be coded or decoded onto the screen and the result appears there. This makes it very simple to store as the saving facilities of the Ace allow one to save a series of bytes. With the program loaded the coding operations can be performed in a matter of seconds. 224 bytes of data can be coded at one time and with each screen being saved as it is coded there is no real limit to the capacity.
I shall give each word of the listing and explain what it does as I go along. Comments in brackets should not be typed in.


: DISP (Puts your message into the display file area)
CLS ." Type in your message of up to
7 lines ending with ↑"
QUERY ASCII ↑ WORD DUP 1+
SWAP C@ INVIS CLS TYPE ;
The word WORD is explained on page 97 of the Ace manual and should make clear how the above works.

: Z INVIS 21 0 AT ." Enter number of complete lines of message"
21 SPACES QUERY NUMBER
DROP 32 *
21 0 AT ." Enter number of characters
in any partial line or 0 if none"
QUERY NUMBER DROP + DUP
224 > IF DROP 224 THEN
21 0 AT ." Enter code word up to
63 characters with no spaces"
16 SPACES QUERY 32 WORD
DROP
9216 + 9216 ;
First of all this word is used by the code and decode functions so it written separately and called by each to save memory.
It asks for the exact length of your message. This is done as we do not want to code a lot of spaces at the end because this would give away the code word.
It then asks for the code word and puts it into a section of memory called the PAD. This is essentially a workspace used for character and string handling by the Ace.
The 2 numbers left on the stack are the parameters for the code and decode functions telling them which section of the screen to code/decode.
 
: CODE Z 7 0 AT 32 SPACES
  DO
   I C@ I 9216 - PAD C@ MOD
   PAD 1+ + C@
   I 3 MOD 128 * +
   XOR 91 +
   I 256 + C!
  LOOP :
 


This takes a character from the top section of the screen arid XORs it with a character from the code word then prints it 8 lines further down. The sections of coding I 3 MOD 128 * + and 91 + are just to add complexity to the procedure and avoid any repetitions which could reveal the code. These become apparent if you change the words to leave them out.

 






ELECTRONICS & COMPUTING MAY 1982 page 43

: DECODE Z 7 0 AT 32 SPACES

DO
I C@ 91 - I 9216 - PAD C@
MOD
PAD 1+ + C@
I 3 MOD 128 * +
XOR I 256 + C!
LOOP ;

This is the reversal procedure similar to the code routine except for the positioning of the 91.
It takes a message from the top of the screen and decodes it into the section 8 lines down.

: TRANS
0 0 AT 8448 224 TYPE ;

This just transfers the lower section of the screen to the top part used mainly for testing your program.

: CLRC
0 0 AT 224 SPACES ;

: CLRD
8 0 AT 224 SPACES ;
These 2 words clear the upper and lower sections of the screen as needed. Next, to simplify the save and load procedures, the next words allow saving from the coded section of the screen and loading into the upper part of the screen. They are used just like LOAD and SAVE.

: CSAVE 8448 224 BSAVE ;

: CLOAD 8192 224 BLOAD ;

That completes the listing. You can now use the program by entering DISP then entering your message. Entering CODE
and then following the instructions on the screen enable you to get the coded version of the text. If you want to decode it again then move it to the top of the screen with TRANS then enter DECODE and follow the instructions on the screen.
A coded message is saved by entering CSAVE messagename. Reloading with CLOAD will put it into the top section of the screen ready for decoding.
To ensure that one's coded message is secure you should be careful with the exact length of the message being put in correctly. The degree of security provided rises exponentially as the length of the code word. If you use a single letter code then it would only take a few hours to crack whereas a code word as long as the message itself would make it totally impossible.