QL Program: QL Crypt File Encoder

See all articles from CATS v5 n5
Author(s): Tim Swenson
Publication: CATS Newsletter
Pub Details: CATS v5 n5 (Volume 5, Issue 5)
Date: August 1987
Pages: 8-9

This program encrypts (endcodes) an ASCII file and converts it back. Once the file has been encrypted, it is almost impossible for anyone to convert it back with out the password that was used to encrypt it.

I first saw this program on an IBM PC/XT. The program came with some documentation explaining how the program worked. A while back I remembered the program and figured I’d give it a try on the QL.

Basically what the program does is this: It first takes the password that you entered and converts it to a single integer. This number is used as a seed to the random number table. The seed tells the computer where to start on the random number table.

Now a character is read from the file. A random number between 1 and 4 is generated, added to the ASCII value of the character, and then outputed to the output file. This is repeated until all of the file is encrypted.

Now the random number table is basically a long list of pseudo-random numbers. The seed points to a start place in the table. Once at this start place, the generator just reads off the numbers as it goes down the table. So with the same seed one can get the same random numbers in the same order.

This is what is used to decode the file, except that a random number between 1 and 4 is subtracted from the character, thus giving us the original character.

‘QL-CRYPT’ Listing

100 WINDOW #1,512,256,0,0
110 PAPER 0 : INK 4: CLS
120 CSIZE 3,1
130 PRINT\\
140 PRINT " QL-CRYPT"
150 CSIZE 0,0
160 PRINT
170 PRINT "
An Encoding and Decoding
Utility"
180 AT 21,25: PRINT "by Timothy
Swenson"
190 AT 13,8: INPUT " Input
Password : ";password$
200 LET length = LEN(password$)
210 LET pass = 0
220 FOR x = 1 TO length
230 LET pass = pass +
CODE(password$(x))
240 NEXT x
250 LET pass = INT(pass/length)
260 RANDOMISE pass
270 CLS
280 AT 5,2
290 CSIZE 3,1
300 PRINT " M A I N M E N U "
310 PRINT "
----------------"\\
320 CSIZE 0,0
330 PRINT " 1)
List Instructions"\\
340 PRINT " 2)
Encode a file"\\
350 PRINT " 3)
Decode a File"\\
360 PRINT " 4)
Quit program"\\\\\
370 INPUT " Enter
your choice : ";choice
380 IF choice = 1 THEN
instructions
390 IF choice = 2 THEN encrypt
400 IF choice = 3 THEN decrypt
410 IF choice <> 4 THEN GO TO
270
420 DEFine PROCedure encrypt
430 CLS : RANDOMISE pass
440 AT 7,3: PRINT "Please enter
file to encode."
450 INPUT infile$
460 AT 10,3: PRINT "Please enter
output file."
470 INPUT outfile$
480 OPEN_IN #5,infile$
490 OPEN_NEW #6, outfile$
500 CLS : PRINT\\
510 PRINT " Current line working
on :"
520 LET inline = 0
530 REPeat loop
540 IF EOF(#5) THEN EXIT loop
550 INPUT #5, in$
560 LET inline = inline + 1
570 AT 4,5: PRINT inline
580 LET length= LEN(in$)
590 FOR x = 1 TO length
600 LET rand = RND(1 TO 4)
610 LET out =
CODE(in$(x))+rand
620 PRINT #6,CHR$(out);
630 END FOR x
640 PRINT #6
650 END REPeat loop
660 CLOSE #5 : CLOSE #6
670 END DEFine decrypt
680 DEFine PROCedure decrypt
690 CLS : RANDOMISE pass
700 AT 7,3: PRINT "Please enter
file to decode."
710 INPUT infile$
720 AT 10,3: PRINT "Please enter
output file."
730 INPUT outfile$
740 OPEN_IN #5,infile$
750 OPEN_NEW #6,outfile$
760 CLS : PRINT\\
770 PRINT " Current line working
on :"
780 LET inline = 0
790 REPeat loop2
800 IF EOF(#5) THEN EXIT loop2
810 INPUT #5, in$
820 LET inline = inline + 1
830 AT 4,5: PRINT inline
840 LET length= LEN(in$)
850 FOR x = 1 TO length
860 LET rand = RND(1 TO 4)
870 LET out =
CODE(in$(x))-rand
880 PRINT #6,CHR$(out);
890 END FOR x
900 PRINT #6
910 END REPeat loop2
920 CLOSE #5 : CLOSE #6
930 END DEFine decrypt
940 DEFine PROCedure
instructions
950 CLS
960 AT 2,0
970 PRINT " This program
will encode a Sinclair ASCII
file such that it can"
980 PRINT "not be decoded by
this program, or any program,
with out the same "
990 PRINT "password that was
used to encode it."
1000 PRINT " Sinclair ASCII
is any character code that can
be printed to the "
1010 PRINT "screen. This
includes international
characters. Machine code and "
1020 PRINT "other like files can
not be used."
1030 PRINT " The file format
will stay the save. That is all
spacing and number"
1040 PRINT "of characters per
line will be the same as the
input file"
1050 PRINT " Hit any key to
go on "
1060 IF INKEY$="" THEN GO TO
1060
1070 END DEFine instructions

…This program from TIMELINEZ newsletter

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.