Google
 

Trailing-Edge - PDP-10 Archives - decuslib20-07 - decus/20-0164/code.mac
There are no other files named code.mac in the archive.
	TITLE Code
	SEARCH MONSYM,MACSYM

;Joshua Brodsky and Larry Hinden - Last updated 7/1/82.

	YES==1
	NO==0

;If it is desired that WHEEL or OPERATOR priveleges be required to
;run this program, set the line below to PRIV==YES.

	PRIV=NO

DEFINE ERROUT($MSG),<HRROI 1,[ASCIZ/$MSG/]
	ESOUT>

DEFINE PARSE,<COMND
	TXNE 1,CM%NOP
	JRST ERROR>

DEFINE NOISE (WORD$),<MOVEI 2,[FLDDB.(.CMNOI,,<POINT 7,[ASCIZ/WORD$/]>)]
	PARSE>

DEFINE CONFRM,<MOVEI 2,[FLDDB.(.CMCFM)]
	PARSE>

	COMAND==17
	EXEC==16
	JFNI==15
	JFNO==14
	ECHO==13

START:	RESET
IFN PRIV,<MOVEI 1,.FHSLF	;Check for priveleges if switch is set.
	RPCAP
	TXNN 3,SC%WHL!SC%OPR
	JRST [ERROUT <Wheel or Operator priveleges enabled required.>
		HALTF
		JRST .-1]>
	MOVEI 1,-1		;Set CCOC to display CTRL-H as
	RFCOC			;^H rather than <backspace> for
	TXO 2,1B17		;Error recovery on COMND.
	TXZ 2,1B16
	SFCOC

BEGIN:	MOVEI 1,CMDBLK
	MOVEI 2,[FLDDB.(.CMINI)]
	COMND

REPARS:	MOVEI 1,CMDBLK
	MOVEI 2,[FLDDB.(.CMKEY,,KEYTAB)]
	PARSE
	JRST @NUM(2)

HELP:	NOISE <with code program>
	CONFRM
	HRROI 1,HLPMSG
	PSOUT
	JRST BEGIN

QUIT:	NOISE <CODE and go to EXEC>
	CONFRM
	HALTF
	JRST START

CODE:	MOVE COMAND,2
	SETZ ECHO,
	SETZ EXEC,
	NOISE <file>
	MOVEI 2,[FLDDB.(.CMIFI)]
	PARSE
	MOVE JFNI,2
	NOISE <to>
	MOVEI 2,[FLDDB.(.CMOFI,<CM%DPP>,,,TTY:)]
	PARSE
	MOVE JFNO,2
	MOVE 5,[JRST TTYOUT]
	MOVE 6,ATOM
	CAME 6,[ASCIZ/TTY:/]
	CAMN 6,[ASCII/TTY: /]
	MOVEM 5,EXPAND
	CAIN COMAND,.ENCOD
	JRST CODE1
	MOVEI 2,[FLDDB.(.CMSWI,,KEY1,,,CONBLK)]
	PARSE
	HRRZ 3,3
	CAIN 3,CONBLK
	JRST CON2
	CAIN 2,.EXEC
	SETO EXEC,
	CAIN 2,.ECHO
	SETO ECHO,
	CAIN 2,.BOTH
	SETO ECHO,
	CAIN 2,.BOTH
	SETO EXEC,
	JRST CON1
CONBLK:	FLDDB.(.CMCFM)
CODE1:	MOVEI 2,[FLDDB.(.CMSWI,,KEY2,,,CONBLK)]
	PARSE
	HRRZ 3,3
	CAIN 3,CONBLK
	JRST CON2
	SETO ECHO,
CON1:	CONFRM
CON2:	MOVE 1,JFNI		;Here when all is parsed and done.
	CAIN COMAND,.ENCOD	;If encoding, use SIXBIT
	MOVE 2,[6B5+OF%RD+OF%PLN]	;So you don't lose the last bit. (36/6)
	CAIE COMAND,.ENCOD	;If decoding, use ASCII
	MOVE 2,[7B5+OF%RD]
	OPENF			;Attempt to open input file.
	  JRST ERROR
	MOVE 1,JFNO		;Save JFN in AC JFNO
	CAIN COMAND,.ENCOD	;Attempt to open output file.
	MOVE 2,[OF%WR+7B5]	;If encoding, output in ASCII
	CAIE COMAND,.ENCOD	;If decoding, use SIXBIT (since encoded in it)
	MOVE 2,[OF%WR+6B5]
	OPENF
	  JRST ERROR
	CAIN COMAND,.ENCOD	;If encoding, skip CODE message check.
	JRST PASSW
	MOVE 1,JFNI		;If decoding, make sure header message is
	HRROI 2,TESTA		;there, and skip over it.
	MOVEI 3,^D35
	MOVEI 4,^D10
	SIN
	  ERJMP ERROR
	HRROI 1,TESTA
	HRROI 2,TESTB
	STCMP
	JUMPE 1,PASSW
	ERROUT <Input file is not encoded with CODE.>
	JRST BEGIN
PASSW:	TMSG <Password code:>	;Input password code.
	JUMPN ECHO,INPUT
	MOVEI 1,-1		;Turn off echo.
	RFMOD
	TXZ 2,TT%ECO
	SFMOD
INPUT:	HRROI 1,PASSTR
	MOVEI 2,^D50
	HRROI 3,[ASCIZ/Password code:/]
	RDTTY			;RDTTY in case of echoing.
	  JRST ERROR
	HRRZ 12,2
	JUMPN ECHO,CON3
	MOVEI 1,-1		;Turn on echo.
	RFMOD
	TXO 2,TT%ECO
	SFMOD
	TMSG <
>
CON3:	CAIL 12,^D48
	JRST [ERROUT <No password specified.>
		JRST BEGIN]
	CAIN COMAND,.ENCOD
	JRST ENCODE

;Decoding routine.
DECODE:	MOVE 5,[POINT 7,PASSTR]	;Set up password pointer (or reset it)
DECOD1:	ILDB 6,5		;Get a letter from the password
	CAIN 6,^D13		;If end (CR), reset pointer.
	JRST DECODE
	MOVE 1,JFNI		;Get a character from the file to decode.
	BIN
	  ERJMP DONE		;If error, must be EOF; DONE.
	CAIN 2,"^"		;If "^", translate next char special.
	JRST DECOD2
DECOD3:	ADD 2,6			;Add the two chars together.
	CAIL 2,^D128		;If over the ASCII limit (128),
	SUBI 2,^D128		;subtract 128.
EXPAND:	JFCL
	MOVE 1,JFNO
	BOUT			;Output the encoded character.
	  ERJMP ERROR
	JRST DECOD1		;Get next character.

TTYOUT:	MOVE 7,[JRST TTYOT1]
	MOVEM 7,EXPAND
	MOVE 7,[POINT 6,TTYBFO]
TTYOT1:	IDPB 2,7
	CAME 7,[POINT 6,TTYBFO,35]
	JRST DECOD1
	HRROI 1,TTYBFO
	PSOUT
	MOVE 7,[POINT 6,TTYBFO]
	SETZM TTYBFO
	JRST DECOD1

TTYBFO:	BLOCK 2

DECOD2:	MOVE 1,JFNI		;Special "^" character translation.
	BIN			;Get next character
	  ERJMP ERROR
	CAIN 2,"|"		;If it's a "|", it's really a true "^"
	MOVEI 2,"^"+^D64
	SUBI 2,^D64		;Otherwise, turn it into a CTRL-char.
	JRST DECOD3		;And decode normally.

DONE:	MOVE 1,[JFCL]
	MOVEM 1,EXPAND
	HRROI 1,TTYBFO
	PSOUT
	SETZM TTYBFO
	TMSG < [Done]>		;Here when input file is at EOF (DONE)
	JUMPE EXEC,CON4		;If /RUN specified, save filenames in buffers.
	MOVE 1,[POINT 7,STRING,27]
	MOVE 2,JFNO
	MOVE 3,[1B8+1B11+JS%PAF]
	JFNS
	  ERJMP ERROR
	MOVEI 2,^D13
	IDPB 2,1
	MOVEI 2,^D10
	IDPB 2,1
	SETZ 2,
	IDPB 2,1
	HRROI 1,TEXT
	MOVE 2,JFNO
	MOVE 3,[1B8+1B11+JS%PAF]
	JFNS
	  ERJMP ERROR
CON4:	MOVE 1,JFNO		;Set byte size to 7 first, then
	MOVEI 2,7
	SFBSZ
	  JFCL			;No error... might be TTY:
	MOVE 1,JFNO
	CLOSF			;close output file
	  JRST ERROR
	MOVE 1,JFNI		;Close input file
	CLOSF
	  JRST ERROR
	JUMPE EXEC,BEGIN	;If /RUN not specified, go back to start.

;Larry Hinden's execute routine - 2/1/82
EXECUT:	MOVSI 1,(CR%CAP)	;/RUN: first push to EXEC.
	CFORK
	  ERJMP ERROR
	MOVE 11,1
	MOVSI 1,(GJ%OLD+GJ%SHT)
	HRROI 2,[ASCIZ/SYS:EXEC.EXE/]
	GTJFN
	  JRST ERROR
	HRLI 1,(11)
	GET
	MOVE 1,11
	SETZ 2,
	SFRKV
	HRROI 1,STRING		;Then make "EX filename" input with RSCAN
	RSCAN
	  JRST ERROR
	SETZ 1,
	RSCAN
	  JRST ERROR
	MOVEI 1,^D30000		;Wait until EXEC processes it.
	DISMS
	MOVSI 1,(GJ%OLD+GJ%SHT)
	HRROI 2,TEXT
	GTJFN			;Then delete the source file.
	  JRST CANT
	TXO 1,DF%EXP
	DELF
	  JRST ERROR
	MOVE 10,[POINT 7,TEXT]
LODREL:	ILDB 5,10		;Make file.REL
	CAIE 5,"."
	JRST LODREL
	MOVEI 5,"R"
	IDPB 5,10
	MOVEI 5,"E"
	IDPB 5,10
	MOVEI 5,"L"
	IDPB 5,10
	SETZ 5,
	IDPB 5,10
	MOVSI 1,(GJ%SHT+GJ%OLD)	;Get a JFN on it, and
	HRROI 2,TEXT
	GTJFN
	  JRST CANT
	TXO 1,DF%EXP
	DELF			;Delete and expunge it.
	  JRST CANT
WAITFK:	MOVE 1,11
	WFORK			;Wait until POP.
	JRST BEGIN		;Take next command.

CANT:	ERROUT (Cant delete source and .REL files.)
	JRST WAITFK

;Encode routine.
ENCODE:	MOVE 1,JFNO		;Output header.
	HRROI 2,TESTB
	MOVNI 3,^D35
	SOUT
	  ERJMP ERROR
ENCOD4:	MOVE 5,[POINT 7,PASSTR]	;Make or reset pointer to password.
ENCOD1:	ILDB 6,5		;Get character from password.
	CAIN 6,^D13		;If end (CR), reset pointer.
	JRST ENCOD4
	MOVE 1,JFNI		;Get character from file to encode.
	BIN
	  ERJMP DONE		;If error, must be EOF; DONE.
	SUB 2,6			;Subtract the two characters.
	CAIGE 2,0		;If outside ASCII, (negative),
	ADDI 2,^D128		;Add 128 to put it in range.
	MOVE 1,JFNO		;Prepare to output it.
	CAIG 2,^D31		;But wait! Is it a CTRL-char?
	JRST ENCOD2		;Yes! translate it!
	CAIN 2,"^"		;Is it an up-arrow? (Don't confuse with CTRL)
	JRST ENCOD3		;Yes, output special sequence
	BOUT			;None of the above, output it.
	  ERJMP ERROR
	JRST ENCOD1		;Get next character.

ENCOD2:	MOVE 3,2		;Routine to translate CTRL-char.
	MOVEI 2,"^"		;Output signal (^)
	BOUT
	  ERJMP ERROR
	MOVEI 2,^D64(3)		;Turn char into regular char (i.e. CTRL-A is
	BOUT			;"^A") and output it.
	  ERJMP ERROR
	JRST ENCOD1		;Loop normally now.

ENCOD3:	BOUT			;Here to output up-arrow.
	  ERJMP ERROR		;Output an up-arrow
	MOVEI 2,"|"		;And special symbol to indicate trueness.
	BOUT
	  ERJMP ERROR
	JRST ENCOD1		;And loop normally.

;Keyword table.
KEYTAB:	NUM,,NUM
	[ASCIZ/Decode/],,0
.ENCOD:	[ASCIZ/Encode/],,0
	[ASCIZ/Help/],,0
	[ASCIZ/Quit/],,0
	NUM==.-KEYTAB-1
ADDRES:	CODE
	CODE
	HELP
	QUIT
	NUM2==.-ADDRES
IFN NUM-NUM2,<PRINTX ?Tables of different lengths.>

HLPMSG:	ASCIZ"
                                 CODE

	CODE is an all-purpose  encoder/decoder for any file.   Unlike
most encoders, CODE can even encode and decode .EXE and .REL files and
decode them back to  executable form. CODE  preserves line numbers  on
EDIT (SOS) files, which are still recognizable by EDIT after decoding.
To sum  up: CODE  encodes and  decodes files  back to  their  original
state, letter by letter. It will work on RUNOFF output, complete  with
bolding and underlining intact.
	CODE's method of encoding is simple: When encoding, CODE  asks
for a password code.  This can  be any string of characters  including
spaces. Remember this  password; you  will need  to tell  CODE it  for
decoding. CODE takes the  ASCII value of the  password, and the  text,
and adds them together. It takes the file letter by letter and rotates
the  password.   (When  decoding,   CODE  subtracts  letters).    When
outputting, CODE represents control codes as ^char, so the file cannot
be edited, or  if it is,  it cannot be  destroyed.  CODE never  prints
carriage returns, so its output can't usually go into EDIT. Note  that
line numbers in a file  are unwise since it  may be possible to  guess
the password from them.
	CODE is not entirely secure; but  it will take at least a  few
days to break the password. For general security, CODE is safe.
	CODE was  written by  Joshua Brodsky  and Larry  Hinden.  This
version was last updated 7/1/82.
	The /RUN switch, typed after a DECODE command, will cause CODE
to push  a  command level,  execute  the  program after  it  has  been
encoded, and delete and expunge the decoded source and .REL files.

                               COMMANDS

	CODE accepts the following commands:

CODE>Encode (file) FILESPEC (to) FILESPEC [TTY:]  [/Echo]
	This encodes the specified file. Default output file is  TTY:.
/Echo will cause the password to echo on your terminal.

CODE>Decode (file) FILESPEC (to) FILESPEC [TTY:]  [/Echo, /Run, /Both]
	This decodes  a previously  encoded  file. Default  output  is
TTY:. /Echo will echo the password, /Run will execute the program, and
/Both will do both.

CODE>Help (with CODE program)
	This causes this message to print.

CODE>Quit (CODE and go to exec
	This exits from CODE. CONTINUE is allowed.

"
ERROR:	HRROI 1,ERS
	MOVE 2,[.FHSLF,,-1]
	SETZ 3,
	ERSTR
	JFCL
	JFCL
	HRROI 1,ERS
	ESOUT
	JRST BEGIN
ERS:	BLOCK 10		;standard form.
PASSTR:	BLOCK 10
KEY1:	3,,3
.BOTH:	[ASCIZ/Both/],,0
.ECHO:	[ASCIZ/Echo/],,0
.EXEC:	[ASCIZ/Run/],,0
KEY2:	1,,1
.ECHO2:	[ASCIZ/Echo/],,0
TESTA:	BLOCK 10
TESTB:	ASCIZ/Note: This file has been encoded.
/
CMDBLK:	REPARS
	.PRIIN,,.PRIOU
	POINT 7,[ASCIZ/CODE>/]
	POINT 7,BUFFER
	POINT 7,BUFFER
	200
	Z
	POINT 7,ATOM
	200
	GETBLK
BUFFER:	BLOCK 40		;a default Command State Block.
ATOM:	BLOCK 40
GETBLK:	BLOCK 20
STRING:	ASCIZ/EXE /
	BLOCK 4
TEXT:	BLOCK 5

	END START		;End, end.