While reading one of the many computer magazines that I read in a month (got to have something to do while I eat my lunch), I read an article in which the columnist talked about security and mail. He was commenting about how open Internet mail (and e-mail in general) is fairly open and easy to tap into.
Simple Mail Transfer Protocol (SMTP), the Internet’s mail protocol, only handles ASCII mail. Most e-mail is sent in the clear, no encryption. Since a mail message can pass through many different sites, it can be copied and read at almost any point.
Having been a Unix system administrator, I know how mail can bounce and be sent to the “Postmaster” for resolution. As “Postmaster” I read other persons mail to figure out where it was supposed to goョ I like to tell people that e-mail is about as private as a post card. You don’t write very private stuff on a post card, so don’t do it with e-mail.
Another general rule of e-mail is not to write anything in a mail message that you would not like to see on the front page of your local newspaper.
I got to thinking about using encryption for e-mail ( encryption is a hot topic these days). But, I did not want to go the the extremes of using Public-Key encryption or DES. Since the whole idea is to make your mail unreadable to the general perusal, a fairly simple algorithm would work.
I also wanted something that could be very easy to port and was not dependent on any computer platform. So, the whole scheme had to rely heavily on the password the user uses.
Ok, now to the details. What this program does is more than just simple rotation of the characters. Simple rotation is just adding a constant number to all characters. If you rotated by 2, A becomes C, B becomes D, etc. Way too simple. So to mix it up, a rotation array is made out of the password. For each letter of the password, a MOD 7 is done and the results put into the array. The longer the password the longer the array. You could make the program do simple rotation with a one character password.
Once the array is created, the program goes through the input file, using the rotation array to rotate a number of characters. The program will cycle through the rotation array many times (like a circular queue) until it reaches the end of the input file. The output file has the general look of the input file (newlines are not touched), but the words are now meaningless.
This encryption is not unbreakable, but to 99% of the population it is unreadable. Someone would have to be pretty determined to try to unencrypt it.
Since this was a fairly simple program to write, I wrote a version in SuperBasic and C. When I get my Fortran compiler up and running, I’ll try to port it to Fortran. Then I’ll try Pascal to try out Computer One Pascal.
100 OPEN #3,con_250x150a50x50
110 PAPER #3,0 : INK #3,4 : BORDER #3,4 : CLS #3
120 INPUT #3,"Name of Input File : ";in_file$
130 INPUT #3,"Name of Output File : ";out_file$
140 INPUT #3,"Password : ";password$
150 INPUT #3,"Rotate or Unrotate (U/R) : ";rot$
160 IF rot$="r" THEN rot$="R"
170 IF rot$="u" THEN rot$="U"
180 IF rot$<>"U" AND rot$<>"R" THEN GO TO 150
190 DIM rot(30)
200 REMark Create Rotation Array
210 pass_len = LEN(password$)
220 FOR x = 1 TO pass_len
230 rot(x) = CODE(password$(x)) MOD 7
240 NEXT x
250 OPEN_IN #4,in_file$
260 OPEN_NEW #5,out_file$
270 rot_mark = 1
280 REPeat loop
290 IF NOT EOF(#4) THEN
300 in$ = INKEY$(#4,-1)
310 ELSE
320 EXIT loop
330 END IF
340 IF CODE(in$) < 32 THEN
350 PRINT #5,in$;
360 ELSE
370 LET temp = CODE(in$)
380 IF rot$="R" THEN temp = temp+rot(rot_mark)
390 IF rot$="U" THEN temp = temp-rot(rot_mark)
400 PRINT #5,CHR$(temp);
410 END IF
420 rot_mark = rot_mark + 1
430 IF rot_mark > pass_len THEN rot_mark = 1
440 END REPeat loop
450 CLOSE #4 : CLOSE #5
460 PRINT #3," Done "
470 CLOSE #3
/* Complex ASCII Rotation
This program takes as input a password and
an ASCII file. From the password a rotation
queue is derived. Then the incomming file is
processed using the rotation queue to rotate
each character differently then those to it's
left and right. The end result is an output
file with the rotated text.
The program also reverses the process and will
produce the original text out of the rotated
file.
*/
#define ROTATE 1
#define UNROTATE 0
#include <stdio_h>
/* Global Array for holding Rotation Queue */
int rot_array[30];
main ()
{
int c, i, fd1, fd2, rot_mark, pass_len, rot;
char *password;
printf("Enter the Input File : ");
fd1 = open_file("r");
printf("Enter the Output File : ");
fd2 = open_file("w");
printf("Enter a Password : ");
gets(password);
pass_len = strlen(password);
/* generate the rotation array from the password */
for ( i=1; i<=pass_len; i++)
rot_array[i] = password[i] % 7;
printf("Rotate or Unrotate (U/R) : ");
c = getchar();
putchar(c);
printf("¥n");
if ( c == 'R' || c == 'r' )
rot = ROTATE;
else
rot = UNROTATE;
/* Start of the main part of the program */
rot_mark = 1;
while (( c=getc(fd1)) != EOF)
{
if ( !isprint(c) )
putc(c,fd2);
else {
if ( rot == ROTATE )
c = c + rot_array[rot_mark];
else
c = c - rot_array[rot_mark];
putc(c,fd2);
rot_mark++;
if ( rot_mark > pass_len )
rot_mark = 1;
}
}
printf("¥n Done!¥n¥n");
}
/* This procedure gets a file name and opens it.
if it fails, it aborts the program.
It takes three values "r", "w", "a"
for Read, Write, Append.
Usage: file_pointer = open_file("r");
*/
open_file(rwa)
char *rwa;
{
char filename[30];
int fd;
gets(filename);
fd = fopen(filename, rwa);
if ( fd == NULL) {
printf("¥n Error Opening File! ¥n");
abort(-1);
}
return fd;
}