hlb@loral.UUCP () (09/20/84)
Msg #8072 on 09/03/84 @18:53 (62) Subj: NEW SAFECOM DETAILS!, To: All From: Bill Parker, Los Angeles, CA Here is the new version of SAFECOM that I promised to post on this board some time ago. As you recall, SAFECOM is a program that encrypts and decrypts text files. The purpose of this program is to allow us to communicate on topics that some people (employers and others) either do not want us to discuss or who want to monitor what we say. I wrote the program and made it PUBLIC DOMAIN. It is liberally sprinkled with comments that explain how it works. You should have little trouble converting it to run on your computer. There will be four levels of security: CONFIDENTIAL, SECRET, TOP SECRET, and EYES ONLY. Each level of security has its own password to encrypt and decrypt the files. You can get the CONFIDENTIAL password from any original PMS Commando (I'll be mailing them the password soon). I'll leave it up to their judgement to decide who gets the CONFIDENTIAL password. To get the SECRET password, you have to leave a message for me. If I know you, I'll mail it to you. I haven't decided what TOP SECRET will be used for. EYES ONLY is for direct communication between two people. You can use it among yourselves any way you like. It's sort of like LOCX on this system. Just agree with someone else what the password will be. To make this system universal, start out your encrypted messages like this: SECURITY LEVEL: CONFIDENTIAL A1B300X99B... The security level will tell the recepient what password to use to decode the message. Some details on this version of SAFECOM: I tried to incorporate all the suggestions you sent me on previous versions. I removed the text editor. It was too crude, slow and buggy. Besides, everyone has a text editor anyway and there's no point in learning a new set of editing commands. I used BASIC to express the algorithm because BASIC is so doggone universal. As soon as Borland comes out with a 6502 based $49.95 Turbo Pascal, you can bet things are gonna be different... Send corrections, suggestions, and versions for different computers and languages to me, so that I can incorporate them into new versions. I'll give you full credit. By the way, for those of you who noticed that I use a "~" symbol for a prompt on this system instead of the usual ":", it is for purposes like this...to upload long BASIC programs. I tried it before while using the ":" prompt and found that this system confused the ":" that separates BASIC statements with the system ":" symbol. As a result, some BASIC lines were truncated at the ":". And if you're wondering how good the security is on SAFECOM, suffice it to say that I sent an encrypted version to one of those experts who writes letters to the editors on encryption and found that he was not able to solve it. SAFECOM doesn't use any of the standard "book" techniques that the experts are always quoting. ------------------------------------------------------------------- FP MONICO 1000 REM *************************************************** 1010 REM * SAFECOM BY BILL PARKER * 1020 REM * * 1030 REM * =-= A PUBLIC DOMAIN PROGRAM! =-= * 1040 REM * * 1050 REM * VERSION 1.0 - DEC 1983 * 1060 REM * VERSION 4.0 - AUG 1984 * 1070 REM * * 1080 REM * (VERSION 4.0 IS A SCALED DOWN FORM OF 1.0) * 1090 REM * * 1100 REM * SAFECOM ALLOWS YOU TO ENCODE AND DECODE TEXT * 1110 REM * FILES WITH LINES LESS THAN 80 CHARS LONG. * 1120 REM * YOU MUST USE A TEXT EDITOR OR WORD PROCESSOR * 1130 REM * TO CREATE THE ORIGINAL (PLAIN TEXT) MESSAGE. * 1140 REM * THE TEXT FILE MUST BE SEQUENTIAL (RANDOM ACCESS * 1150 REM * FILES SOMETIMES CONTAIN ZEROES WHICH ARE * 1160 REM * INCORRECTLY INTERPRETED AS END OF FILE CHARS BY * 1170 REM * APPLE DOS). * 1180 REM * * 1190 REM * ENCRYPTION & DECRYPTION IS PERFORMED BY MEANS * 1200 REM * OF A "KEY" (PASSWORD) OF YOUR OWN CHOICE. YOU * 1210 REM * MUST REMEMBER THE KEY TO BE ABLE TO WORK WITH * 1220 REM * ENCRYPTED FILES. * 1230 REM * * 1240 REM * THIS PROGRAM IS WRITTEN IN APPLESOFT (BASIC FOR * 1250 REM * THE APPLE II). NO TRICKY PROGRAMMING IS USED, * 1260 REM * SO YOU SHOULD BE ABLE TO ADAPT IT FOR OTHER * 1270 REM * COMPUTERS. ** NOTE: "& INPUT" IS AN APPLESOFT * 1280 REM * EQUIVALENT OF "LINPUT" IN OTHER BASICS. IT * 1290 REM * READS STRINGS CONTAINING COMMAS, ETC. * 1300 REM * * 1310 REM * THIS PROGRAM IS DESIGNED TO HELP ALL OF US * 1320 REM * WITH SECURE COMMUNICATION CHANNELS. FEEL FREE * 1330 REM * TO GIVE AWAY COPIES AND TO INCORPORATE IT IN * 1340 REM * YOUR OWN PROGRAMS, MAGAZINE ARTICLES, ETC. * 1350 REM * JUST GIVE ME CREDIT. THANKS AND GOOD LUCK! * 1360 REM *************************************************** 1370 : 1380 REM +========================+ 1390 REM : INITIALIZATION SECTION : 1400 REM +========================+ 1410 : 1420 TEXT : REM MAKE SURE GRAPHICS MODE IS TURNED OFF 1430 : 1440 REM ----------- 1450 REM CONSTANTS 1460 REM ----------- 1470 : 1480 LET BEEP = 7: REM SPEAKER BEEP = CHR$(7) 1490 : 1500 REM ----------------------------------------------- 1510 REM INIT APPLE -- YOU CAN DELETE FROM HERE TO THE 1520 REM MAIN PROGRAM IF SAFECOM IS NOT RUNNING ON AN 1530 REM APPLE COMPUTER. 1540 REM ----------------------------------------------- 1550 : 1560 LET D$ = CHR$ (4): REM GETS DOS ATTENTION 1570 : 1580 PRINT CHR$ (12): HOME : REM 80/40 CLMN SCRN CLEAR 1590 INVERSE : PRINT " S A F E C O M ": NORMAL 1600 VTAB 5: PRINT "Can your Apple display a screen": PRINT 1610 PRINT "that's 80 columns wide? (Y/N/<CR>):"; 1620 GET ANS$: PRINT ANS$ 1630 IF ANS$ = CHR$ (13) THEN 4780 1640 IF ANS$ < "a" OR ANS$ > "z" THEN 1660 1650 LET ANS$ = CHR$ ( ASC (ANS$) - 32): REM L.C. --> U.C. 1660 IF ANS$ = "Y" THEN PRINT D$"PR#3": GOTO 1780 1670 IF ANS$ < > "N" THEN PRINT CHR$ (BEEP): GOTO 1600 1680 : 1690 REM INPUT ANYSTRING ROUTINE -- THE FOLLOWING ROUTINE 1700 REM ALLOWS APPLESOFT TO INPUT STRINGS CONTAINING 1710 REM COMMAS, SEMICOLONS, ETC. BASED ON A PUBLIC 1720 REM DOMAIN PROGRAM WRITTEN BY BOB SANDER-CEDERLOF 1730 REM AND SHERM OSTROWSKY ON PP. 16-17 OF THE 1740 REM DEC. 1981 ISSUE OF APPLE ASSEMBLY LINE. 1750 REM STRINGS CAN BE ENTERED WITH THIS ROUTINE BY 1760 REM USING: &INPUT 1770 : 1780 PRINT CHR$ (12): HOME : REM 80/40 CLMN SCRN CLEAR 1790 INVERSE : PRINT " S A F E C O M ": NORMAL 1800 PRINT : PRINT : PRINT "Please wait a few secs --": PRINT 1810 PRINT "Creating machine code input routine..." 1820 LET SAV(1) = PEEK (1014):SAV(2) = PEEK (1015): REM SAVE & HOOK 1830 : 1840 REM INPUT ANYSTRING ROUTINE: 1850 DATA 160, 0,177,184,201 1860 DATA 132,208, 44, 32,177 1870 DATA 0, 32,227,223, 32 1880 DATA 44,213,232,189, 0 1890 DATA 2,208,250,134,157 1900 DATA 138, 32, 82,228,160 1910 DATA 0,145,131,200,165 1920 DATA 113,145,131,200,165 1930 DATA 114,145,131,160, 2 1940 DATA 162, 0,165,157, 76 1950 DATA 226,229 1960 : 1970 REM PUT MACHINE CODE INTO MEMORY 1980 ONERR GOTO 2020: REM LOAD UNTIL OUT OF DATA 1990 LET PG3 = 768 2000 READ BYTE: POKE PG3 + C,BYTE:C = C + 1: GOTO 2000 2010 : 2020 LET C = 0: REM CLEAR COUNTER 2030 POKE 1014,0: POKE 1015,3: REM SET UP & HOOK 2040 : 2050 REM ============================================================== 2060 : 2070 REM +==============+ 2080 REM : MAIN PROGRAM : 2090 REM +==============+ 2100 : 2110 PRINT CHR$ (12): HOME : REM 80/40 CLMN SCRN CLEAR 2120 : 2130 INVERSE : PRINT " S A F E C O M ": NORMAL 2140 PRINT : PRINT 2150 PRINT "Choose one:": PRINT 2160 PRINT " C(atalog": PRINT 2170 PRINT " D(ecode sequential text file": PRINT 2180 PRINT " E(ncode sequential text file": PRINT 2190 PRINT " Q(uit": PRINT 2200 : 2210 REM ------------ 2220 REM GET CHOICE 2230 REM ------------ 2240 : 2250 VTAB 23: PRINT "Which?";: GET ANS$ 2260 IF ANS$ > = "a" AND ANS$ < = "z" THEN 2280 2270 GOTO 2290 2280 LET ANS$ = CHR$ ( ASC (ANS$) - 32): REM L.C --> U.C. 2290 IF ANS$ = CHR$ (13) THEN VTAB 22 2300 PRINT ANS$; 2310 : 2320 REM ----------- 2330 REM DO CHOICE 2340 REM ----------- 2350 : 2360 IF ANS$ = "C" THEN 2570 2370 IF ANS$ = "D" THEN 2700 2380 IF ANS$ = "E" THEN 3520 2390 IF ANS$ = "Q" THEN 4730 2400 : 2410 REM ---------------- 2420 REM INVALID CHOICE 2430 REM ---------------- 2440 : 2450 PRINT CHR$ (BEEP): GOTO 2250 2460 : 2470 REM ============================================================== 2480 : 2490 REM +=================+ 2500 REM : MODULES SECTION : 2510 REM +=================+ 2520 : 2530 REM ================ 2540 REM CATALOG MODULE 2550 REM ================ 2560 : 2570 PRINT CHR$ (12): HOME : REM 80/40 CLMN SCRN CLEAR 2580 INVERSE : PRINT " S A F E C O M ": NORMAL 2590 VTAB 5: PRINT " Which drive would you like": PRINT 2600 PRINT " to see a directory of? (1 or 2):";: GET DR$: PRINT DR$ 2610 IF DR$ < "1" OR DR$ > "2" THEN PRINT CHR$ (BEEP): GOTO 2590 2620 PRINT D$"CATALOG,D";DR$ 2630 PRINT : PRINT "Press any key:";: GET ANS$: PRINT ANS$ 2640 GOTO 2110 2650 : 2660 REM =================== 2670 REM DECRYPTION MODULE 2680 REM =================== 2690 : 2700 PRINT CHR$ (12): HOME : REM 80/40 CLMN SCRN CLEAR 2710 INVERSE : PRINT " S A F E C O M ": NORMAL 2720 : 2730 REM ------------ 2740 REM GET FILENAME 2750 REM ------------ 2760 : 2770 VTAB 4 2780 PRINT "This module decodes a SAFECOM encrypted" 2790 PRINT "text file. You must know the password" 2800 PRINT "used to encrypt the file. Remember to" 2810 PRINT "use the '.COD' file name extension, if" 2820 PRINT "one was used on the encoded file.": PRINT 2830 PRINT "Press RETURN to quit or type the name" 2840 PRINT "of the seq. text file you want to" 2850 PRINT "decode: (,Dn ending OK)": PRINT 2860 & INPUT FILNAME$ 2870 IF FILNAME$ = "" THEN 2110 2880 : 2890 REM ----------------- 2900 REM CK IF FILE EXISTS 2910 REM ----------------- 2920 : 2930 ONERR GOTO 2950 2940 GOTO 2970 2950 POKE 216,0: REM CLEARS APPLE DOS ERROR CONDITION 2960 PRINT : PRINT CHR$ (BEEP);"SAY WHAT?": GOTO 2770 2970 PRINT D$"VERIFY ";FILNAME$ 2980 LET TN$ = MID$ (FILNAME$, LEN (FILNAME$) - 2,2) 2990 IF TN$ < > ",D" THEN 3060 3000 LET FILNAME$ = LEFT$ (FILNAME$, LEN (FILNAME$) - 3) 3010 : 3020 REM ------- 3030 REM GET KEY 3040 REM ------- 3050 : 3060 PRINT : PRINT "Enter password:";: & INPUT KEY$ 3070 IF KEY$ = "" THEN 2110 3080 : 3090 REM --------------- 3100 REM DECODE THE FILE 3110 REM --------------- 3120 : 3130 LET F1$ = FILNAME$:F2$ = F1$ 3140 IF RIGHT$ (F2$,4) = ".COD" THEN F2$ = LEFT$ (F2$, LEN (F2$) - 4) 3150 LET F2$ = F2$ + ".PLN" 3160 PRINT D$"OPEN "F1$ 3170 PRINT D$"OPEN "F2$ 3180 PRINT D$"DELETE "F2$ 3190 PRINT D$"OPEN "F2$ 3200 ONERR GOTO 3440: REM EOF 3210 LET KPTR = 0:PLAIN$ = "" 3220 PRINT D$"READ "F1$ 3230 & INPUT CODE$ 3240 : 3250 REM == ACTUAL CONVERSN == 3260 : 3270 FOR I = 1 TO LEN (CODE$) - 1 STEP 2 3280 LET KPTR = KPTR + 1 3290 IF KPTR = LEN (KEY$) + 1 THEN KPTR = 1 3300 LET KEY = ASC ( MID$ (KEY$,KPTR,1)) 3310 LET D1$ = MID$ (CODE$,I,1):D2$ = MID$ (CODE$,I + 1,1) 3320 LET PLAIN = ( ASC (D1$) - 48 - (7 * (D1$ > = "A"))) * 16 3330 LET PLAIN = PLAIN + ( ASC (D2$) - 48 - (7 * (D2$ > = "A"))) 3340 IF PLAIN = 13 THEN KPTR = KPTR - 1: PRINT D$"WRITE "F2$ 3350 IF PLAIN = 13 THEN PRINT PLAIN$:PLAIN$ = "": GOTO 3380 3360 LET PLAIN = PLAIN - KEY 3370 LET PLAIN$ = PLAIN$ + CHR$ (PLAIN) 3380 NEXT 3390 : 3400 GOTO 3220: REM DO NEXT REC 3410 : 3420 REM == HANDLE EOF == 3430 : 3440 POKE 216,0: REM CLEARS APPLE DOS ERROR CONDITION 3450 PRINT D$"CLOSE" 3460 GOTO 2110: REM MAIN MENU 3470 : 3480 REM ============ 3490 REM ENCODING MOD 3500 REM ============ 3510 : 3520 PRINT CHR$ (12): HOME : REM 80/40 CLMN SCRN CLEAR 3530 INVERSE : PRINT " S A F E C O M ": NORMAL 3540 : 3550 REM ------------ 3560 REM GET FILENAME 3570 REM ------------ 3580 : 3590 VTAB 4 3600 PRINT "This module encodes a text file accor-" 3610 PRINT "ding to a password that you supply." 3620 PRINT "The password can be up to 80 characters" 3630 PRINT "long. It can contain any type of char." 3640 PRINT "Each line of the original text file can" 3650 PRINT "be no longer than 80 chars. This" 3660 PRINT "module produces an encrypted copy of" 3670 PRINT "the original text file, but with '.COD'" 3680 PRINT "appended to the file name. The" 3690 PRINT "encryption process produces two chars" 3700 PRINT "for every original char. The chars" 3710 PRINT "produced are letters and digits, making" 3720 PRINT "them easily transmittable with a modem.": PRINT 3730 PRINT "Press RETURN to quit or type the name" 3740 PRINT "of the seq. text file you want to" 3750 PRINT "encode: (,Dn ending OK)": PRINT 3760 & INPUT FILNAME$ 3770 IF FILNAME$ = "" THEN 2110 3780 : 3790 REM ----------------- 3800 REM CK IF FILE EXISTS 3810 REM ----------------- 3820 : 3830 ONERR GOTO 3850 3840 GOTO 3900 3850 POKE 216,0: REM CLEARS APPLE DOS ERROR CONDITION 3860 PRINT CHR$ (12): HOME : REM 80/40 CLMN SCRN CLEAR 3870 INVERSE : PRINT " S A F E C O M ": NORMAL 3880 PRINT : PRINT CHR$ (BEEP): PRINT "Can't find a file by that name" 3890 PRINT : PRINT "Press any key:";: GET ANS$: PRINT ANS$: GOTO 3520 3900 PRINT D$"VERIFY ";FILNAME$ 3910 REM GOT THIS FAR, SO FILE MUST EXIST 3920 LET TN$ = MID$ (FILNAME$, LEN (FILNAME$) - 2,2) 3930 IF TN$ < > ",D" THEN 4000 3940 LET FILNAME$ = LEFT$ (FILNAME$, LEN (FILNAME$) - 3) 3950 : 3960 REM ----------------------------- 3970 REM CHECK FILE FOR LONG RECORDS 3980 REM ----------------------------- 3990 : 4000 PRINT CHR$ (12): HOME : REM 80/40 CLMN SCRN CLEAR 4010 INVERSE : PRINT " S A F E C O M ": NORMAL 4020 PRINT : PRINT : PRINT "Checking file for records that are" 4030 PRINT "too long (greater than 80 chars)...": PRINT 4040 ONERR GOTO 4140 4050 PRINT D$"OPEN ";FILNAME$: PRINT D$"READ ";FILNAME$ 4060 & INPUT REC$: IF LEN (REC$) < 80 THEN 4060 4070 PRINT CHR$ (7)"Whoops! Found a long record:": PRINT : PRINT REC$ 4080 PRINT : PRINT "Sorry, but you can't encrypt this file." 4090 PRINT : PRINT "Use your text editor to make the file's" 4100 PRINT "lines no longer than 80 characters." 4110 POKE 216,0: PRINT D$: PRINT D$"CLOSE" 4120 PRINT : PRINT "Press any key:";: GET ANS$: PRINT ANS$: GOTO 2110 4130 : 4140 POKE 216,0: PRINT "File checks OK": PRINT 4150 : 4160 REM ----------- 4170 REM GET THE KEY 4180 REM ----------- 4190 : 4200 PRINT : PRINT "Enter password:";: & INPUT KEY$ 4210 IF KEY$ = "" THEN 2110 4220 : 4230 REM --------------- 4240 REM ENCODE THE FILE 4250 REM --------------- 4260 : 4270 LET F1$ = FILNAME$:F2$ = F1$ 4280 IF RIGHT$ (F2$,4) = ".PLN" THEN F2$ = LEFT$ (F2$, LEN (F2$) - 4) 4290 LET F2$ = F2$ + ".COD" 4300 PRINT D$"OPEN "F1$ 4310 PRINT D$"OPEN "F2$ 4320 PRINT D$"DELETE "F2$ 4330 PRINT D$"OPEN "F2$ 4340 ONERR GOTO 4700: REM EOF 4350 : 4360 REM == ACTUAL CONVERSN == 4370 REM 4380 REM KPTR = KEY POINTER. FINDS NEXT CHAR TO ENCODE 4390 REM C = CHAR COUNTER. 4400 LET KPTR = 0:C = 0:CODE$ = "" 4410 PRINT D$"READ "F1$ 4420 & INPUT PLAIN$ 4430 IF LEN (PLAIN$) = 0 THEN 4410: REM BLANK LINE 4440 : 4450 FOR I = 1 TO LEN (PLAIN$) 4460 LET KPTR = KPTR + 1 4470 IF KPTR > LEN (KEY$) THEN KPTR = 1 4480 LET KEY = ASC ( MID$ (KEY$,KPTR,1)) 4490 LET CODE = ASC ( MID$ (PLAIN$,I,1)) + KEY 4500 REM D1 = LEFT DIGIT OF ENCRYPTED DIGIT PAIR 4510 REM D2 = RIGHT DIGIT OF ENCRYPTED DIGIT PAIR 4520 LET D1 = INT (CODE / 16):D2 = CODE - D1 * 16 4530 LET D1$ = CHR$ (D1 + 48 + (7 * (D1 > 9))) 4540 LET D2$ = CHR$ (D2 + 48 + (7 * (D2 > 9))) 4550 LET CODE$ = CODE$ + D1$ + D2$ 4560 LET C = C + 1 4570 IF C > = 29 THEN PRINT D$"WRITE "F2$: PRINT CODE$ 4580 IF C > = 29 THEN CODE$ = "":C = 0 4590 NEXT 4600 : 4610 REM 0D IS A RESERVED CODE TO TELL THE DECODER 4620 REM THAT THIS IS THE END OF THE LINE. 4630 LET CODE$ = CODE$ + "0D" 4640 LET C = C + 1 4650 : 4660 GOTO 4410: REM GET NEXT REC 4670 : 4680 REM == HANDLE EOF == 4690 : 4700 POKE 216,0: REM CLEARS APPLE DOS ERROR CONDITION 4710 IF C THEN PRINT D$"WRITE "F2$: PRINT CODE$ 4720 PRINT D$: PRINT D$"CLOSE": GOTO 2110: REM MAIN MENU 4730 : 4740 REM ==== 4750 REM QUIT 4760 REM ==== 4770 : 4780 PRINT CHR$ (12): HOME : REM 80/40 CLMN SCRN CLEAR 4790 PRINT "Bye..." 4800 : 4810 REM DELETE THE POKES BELOW IF THIS PROGRAM IS NOT 4820 REM RUNNING ON AN APPLE. 4830 POKE 1014,SAV(1): POKE 1015,SAV(2): REM RESTORE & HOOK SAVE SAFECOM