Secret Codes

by Mister Galaxy

As you know, there are always times when one might wish to keep a communication secret.  You might not want a co-worker to see it or you might want to make sure it couldn't be read in case it got intercepted.

If you think back to your early school days, you probably remember simple substitution codes like:

A = 1 
B = 2 
C = 3, and so forth...

By substituting the number 1 for 'A' and the number 2 for 'B' you could easily encode your secret messages.  The problem with this type of code is that certain letters in the English language appear more often than others.  This is the order of frequency of letters in the average English document (reading left-to-right):

e t a o i n s r h l d c u m f w g y p b v k x j q z

A smart person could make a quick analysis of the frequency of the letters in your document and easily decode it.  Keep in mind that the shorter the document is, the harder it is to decode.  This is because the frequency of letters has not yet been established.  Most decoders need a fairly substantial document to decode what you have written.

Another code is called the Book Code.  Select a book which contains many different words, words that you might want to include in a message.  A message created using the book might look like:

4-56, etc...

This code means go to the fifth page of the predetermined book and choose the one hundredth word.  Then, go to the twelfth page and write down the fourth word, etc.  I think you get the idea...  This type of code is very difficult to crack, but both parties must have the identical book, and coding and decoding messages using this method can be very tedious.

Another neat code is call the Square Code.  Take a message that you want to encode and count the number of letters in your message.  Create a square that contains enough boxes in it to hold your message.  The square might contain 3x3 boxes, 4x4, 5x4, and so forth...  For example:

The message "I want to bite your neck" contains 24 characters including spaces.  A square that's five blocks by five blocks could hold this message.  Draw a cube that's five blocks by five blocks and then number the boxes randomly.  See an example below:

21 02 12 05 10
07 20 14 16 23
19 13 08 01 09
25 03 17 15 24
06 18 11 04 22

You and you friends would have several different pre-made boxes.  One would be 5x5, then 6x6, and so forth.  Depending on the length of the message, you or your friends would choose the right size square.  In our case, this time, our message "I want to bite your neck" would look like this:

n - i n -
- - e y c
r t t I o
- w o - k
t u b a e

By following the numbers in order in the decoding cube (from 1 to 25), you can easily decode the message.  In this case I placed dashes instead of spacesin the coded cube.  I also put a dash for the 25th character which we didn't have a need for.  Many do not try to encode the spaces in their message since this might help give the message away...

My favorite code works using a keyword and can easily be programmed on a computer.  First you write your message.  Then you choose a keyword that contains less letters than your message.  Then, convert your message to all lower-case letters.  Do not put spaces in your keyword or phrase.  Now simply do the following:

Message is: I like eggs
Keyword is: fred

Convert the message to: ilikeeggs
Convert the keyword to: FREDFREDF

Note that we have repeated the keyword over and over again until we have the same number of characters as the message.

The longer the keyword is, the harder the message is to decode.  Now, subtract the ASCII code of the first letter of the keyword from the ASCII code of the first character of the message.  Then subtract the ASCII code of the second letter of the keyword from the second letter of the message.  I think you get the idea.  By constantly changing keywords and by choosing long keywords, only the brightest of folks will be able to decode what you've written.

The beauty of this code is that each week you can change it, then you can transfer your message via BBSes, disks, etc., and then easily decode them...

I have included a program written in PowerBASIC 3.0 that codes and decodes messages using this method.  It will allow you to write a message and automatically code it.  Then, you can attach a coded message file to a message on a BBS or simply save it on a disk.  Later, your friends can then quickly decode your message if they have the program and keyword.

Try it!

10 on error goto 3000:color
15,1,1:rem Codeit Version 2.0 - A freeware program / Power Basic 3.0 (will not run under QBASIC)
12 cls:print:print:print"Welcome to CODEIT Version 2.0 By MRGALAXY":print"MRGALAXY@AOL.COM":print:print"A FREEWARE PROGRAM - (C)opyright 1995":delay 3:cls
18 cls:dim c$(1000):on error goto 3000
19 if command$="?" or command$="/?" then goto 2000
22 if command$="" then goto 26 else fe$=command$:open fe$ for input as 1
23 b=0
24 if eof(1) then close:b=b+1:goto 26 else b=b+1:line input #1, c$(b):goto 24
26 print:input"Enter a code keyword/phrase or (Q)uit: ";a$:a$=ucase$(a$)
27 if left$(a$,1)="Q" then stop
28 if command$<>"" then goto 152
30 cls:print:input"Do you want to (C)ode, (D)ecode, or (Q)uit (C, D, or Q): ";f$
40 f$=ucase$(f$):f$=left$(f$,1)
50 if f$<>"C" and f$<>"D" and f$<>"Q" then goto 30
55 if f$="Q" then stop
60 if f$="D" then goto 400
70 cls:b=1:print
72 print"Begin typing in your message.  Check each line for mistakes before"
74 print"hitting the ENTER button.  Hitting ENTER alone stops the program"
76 print"from asking for input....":
78 print
79 print
80 print"Enter line ";b;" of message: "
90 input c$(b):if c$(b)="" then goto 120
100 b=b+1:goto 80
120 for a=1 to b-1:c$(a)=lcase$(c$(a))
150 next a
152 cls:print:input "Code to (F)ile, (S)creen, or (Q)uit (F, S, or Q): ";x$:x$=ucase$(x$):if x$="Q" then stop
153 x$=left$(x$,1):if x$="Q" then stop
154 cls:if x$="F" then cls:input "Enter path/filename to use: ";u$
155 if x$<>"F" then goto 158
156 on error goto 3000:open u$ for output as 1
158 if x$="F" then print:print"Writing to a file and the screen....":print
159 if x$="S" then print:print"Writing codes to screen....":print
160 for a=1 to b-1
165 v$=""
170 if len(v$)<len(c$(A)) then v$=v$+a$:goto 170
180 for l=1 to len(c$(a))
185 print asc(mid$(c$(a),l,1))-asc(mid$(v$,l,1)),
187 if x$="F" then print #1, asc(mid$(c$(a),l,1))-asc(mid$v$,l,1));
190 next l
192 if x$="F" then print #1,255
200 print "255":if x$="F" then print #1,""
210 next a
220 close
230 print:print:input"Press ENTER to continue: ";he$:goto 152
400 cls:print:print:input "From (K)eyboard or (F)ile? (K or F): ";hj$
405 hj$=ucase$(hj$:hj$=left$(hj$,1)
410 if hj$<>"K" and hj$<>"F" then goto 400
420 if hj$="F" then goto 600
430 je$=""
435 je$=je$+a$:if len(je$)<240 then goto 435
440 qq=1
445 input "Enter number (0 quits): ";vv
447 if vv=0 then run
450 if vv<>255 then print"The letter is: ";chr$(vv+asc(mid$(je$,qq,1)))
460 if vv=255 then print"New line starts here":print:let qq=1:goto 445
470 qq=qq+1:goto 445
600 cls:print:input"Enter path and filename: ";ef$:cls:print
605 je$=""
606 je$=je$+a$:if len(je$)<240 then goto 606
610 on error goto 3000:open ef$ for input as 1
612 qq=1
620 if eof(1) then goto 700
625 input #1,za
630 if za<>255 then print chr$(za+asc(mid$(je$,qq,1)));
635 if za=255 then print:qq=0:input #1,za
640 qq=qq+1:goto 620
700 print:print:input"Press ENTER to continue: ";re$:run
2000 cls
2005 print:print
2010 print"Welcome to CODEIT Version 2.0.":print
2020 print"To code an ASCII text file, type: ":print
2030 print"CODEIT filename.ext":print
2040 print"or you can simply type CODEIT to manually code a message...":print
2050 print
2060 print"By P. H."
2065 print"710 Peachtree St. NE 430"
2070 print"Atlanta, GA 30308":print
2080 print"MRGALAXY@AOL.COM"
2090 stop
3000 cls:print:print"An error has occured!  Either a file name or path was entered incorrectly,"
3005 print"or another problem has occurred... Please try again...":stop

Code: codeit.bas

Return to $2600 Index