Google
 

Trailing-Edge - PDP-10 Archives - SRI_NIC_PERM_SRC_3_19910112 - utilities/crypt.fai
There are no other files named crypt.fai in the archive.
	TITLE	CRYPT

;THE TAMPERING DETECTOR

S:	MOVSI	2,S-LAST	;INITIALIZE INDEX AND WORD COUNT
	SETOB	3,4		;INITIALIZE X^N AND TOTAL TO -1
	IMUL	3,0		;X^(N-1) CHANGED TO X^N
	MOVE	5,S(2)		;GET THE WORD
	IMUL	5,3		;MULTIPLY IT BY X^N
	ADD	4,5		;ADD IT TO THE TOTAL
	AOBJN	2,S+2		;END OF LOOP
	CAME	4,1		;TEST IF TOTAL CAME OUT RIGHT
	HALT			;SKIP OVER THIS IF TEST PASSED



	JRST	GO		;NO NEED TO CHECK THIS ONE

define ... <>
FAC_1 ... SWAC_2 ... CNT1_3			;FILE NAME SCANNER

DMODE:	10		;DEVICE AND MODE SPEC
DEV:	0
IOBUF:	0

FN1:	0		;FILE NAME SPEC
FN2:	0
PROT:	0
PPN:	0

DEFN1:	0		;DEFAULT FILE NAME
DEFN2:	0		;DEFAULT EXTENSION
DEFPN:	0		;DEFAULT PPN
DEFDV:	SIXBIT	/DSK/	;DEFAULT DEVICE

PNTR:	0

RDFIL:	SETZ	SWAC,		;FIRST NAME AND/OR DEVICE
	MOVE	0,DEFDV		;SET UP THE DEFAULT DEVICE
	MOVEM	0,DEV
	MOVE	0,DEFN2		;DEFAULT SECOND FILENAME
	MOVEM	0,FN2
	MOVE	0,DEFPN		;DEFAULT PPN
	MOVEM	0,PPN
TRYG:	MOVE	0,DEFN1		;AND DEFAULT FIRST FILE NAME
	MOVEM	0,FN1
	MOVE	0,[POINT 6,FN1] ;SIXBIT BYTE POINTER INTO FN1 WORD
	MOVEM	0,PNTR
	MOVEI	CNT1,6
	INCHWL	FAC		;GET THE NEXT CHARACTER
FNL:	JUMPN	SWAC,QUOT	;IF IN QUOTE MODE, SKIP THE NEXT FOUR TESTS
	CAIN	FAC,":"		;IF :, THIS WAS A DEVICE PARSE, NOT FN1
	JRST	[ MOVE	0,FN1	;MOVE THE ASSEMBLED STRING INTO
		  CAIL	CNT1,6	;DEVICE FIELD
		  SETZ	0,
		  MOVEM	0,DEV
		  JRST	TRYG]
	CAIN	FAC,"."		;IN CASE OF DOT, JUMP TO FN2 PARSE
	JRST	DOTP
	CAIN	FAC,"["		;IF [, JUMP TO PROJ NAME PARSE
	JRST	PARP
	CAIN	FAC," "		;SKIP OVER BLANKS
	JRST	NOP
QUOT:	CAIE	FAC,""		;IF , TOGGLE THE QUOTE FLAG
	JRST	NQ
	CAIL	CNT1,6		;ANY CHARACTERS ENTERED INTO THE FIELD YET?
	SETZM	FN1		;IF NOT, CLEAR THE FIELD, TO WIPE OUT DEFAULT
	XOR	SWAC,1		;QUOTE FLAG TOGGLE
	ADDI	CNT1,1
	JRST	NOP
NQ:	CAIE	FAC,15		;WAS IT A CARRIAGE RETURN?
	CAIN	FAC,12		;OR LINEFEED?
	JRST	TERP		;IF SO, FINISH UP
	CAIN	FAC,175		;ALTMODE?
	JRST	TERP		;SAME THING
	CAIGE	FAC,40		;CHECK IF AN ILLEGAL CHARACTER
	JRST	[ FNER:	OUTSTR [ASCIZ "Illegal file name, try again:"]
			CLRBFI
			JRST   RDFIL ]
	CAIL	FAC,140		;ELSE, THIS IS A REAL TEXT CHARACTER
	SUBI	FAC,40		;CONVERT IT TO SIXBIT
	SUBI	FAC,40
	CAIL	CNT1,6		;CLEAR OUT DEFAULT IF IT WAS FIRST CHARACTER
	SETZM	FN1
	IDPB	FAC,PNTR	;AND DEPOSIT IT IN THE FN1 FIELD
NOP:	INCHWL	FAC
	SOJGE	CNT1,FNL	;GET NEXT CHAR, UNLESS SIX ALREADY MET
	JRST	FNER

DOTP:	SETZM	FN2			;SAME STUFF AS ABOVE, BUT FOR
	MOVE	0,[POINT 6,FN2]		;EXTENSION, INSTED OF FN1
	MOVEM	0,PNTR
	MOVEI	CNT1,3
	INCHWL	FAC
FNL2:	JUMPN	SWAC,QUOT2
	CAIN	F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,40
	SUBI	FAC,40
	LSH	0,6
	OR	0,FAC
	HRRM	0,PPN
NOP4:	INCHWL	FAC
	SOJGE	CNT1,FNL4
	JRST	FNER

TERP:	CAIE	FAC,175			;END OF INPUT LINE PROCESSING
	CAIN	FAC,12
	POPJ	17,
	INCHWL	FAC			;GOBBLE EXTRA CHARACTER IF <CR>
	JRST	TERP
STACK:	BLOCK	10

IHD:	BLOCK	3			;INPUT BUFFER HEADER
OHD:	BLOCK	3			;OUTPUT BUFFER HEADER
KEY1_15 ... KEY2_16

GO:	MOVEI	17,STACK
	MOVEI	1,0
;;	DSKPPN	1,
	MOVEM	1,DEFPN
	OUTSTR	[ASCIZ "Encode or decode:"]
FMO:	SETZ	5,
INLM:	INCHWL	2		;GET A CHARACTER
	JUMPN	5,STAN		;IF IT IS THE FIRST ONE
	ANDI	2,37		;STRIP OFF THE TOP BITS
	MOVE	5,2		;AND SAVE IT
STAN:	CAIN	2,15		;ELSE, WAS IT A CARRIAGE RETURN
	INCHWL	2		;IF SO,GET NEXT CHARACTER
	CAIN	2,12		;OR LINEFEED
	JRST	IDNM		;IF SO, STOP READING
	CAIE	2,175		;SAME THING IF AN ALTMODE
	JRST	INLM		;OTHERWISE, GET NEXT CHARACTER
IDNM:	CAIE	5,4		;WAS THE FIRST CHARACTER A "D"
	CAIN	5,5		;OR AN "E"
	JRST	MOK		;IF SO, CARRY ON
	OUTSTR	[ASCIZ "Whazzat? Try again:"]
	JRST	FMO
MOK:	OUTSTR	[ASCIZ "Input file:"]	;GET INPUT FILE NAME
	MOVE	0,[ 0,,IHD]		;READY INPUT BUFFER HEADER
	MOVEM	0,IOBUF
	MOVEI	0,14			;IN MODE 14
	MOVEM	0,DMODE
INFL:	PUSHJ	17,RDFIL		;NOW PARSE FILENAME
	OPEN	1,DMODE			;OPEN IT
	JRST	.+2			;IF IT FAILED, GIVE ERROR MESSAGE
	LOOKUP	1,FN1
	JRST	[ OUTSTR [ASCIZ "Can't find it, try again:"]
		  JRST	INFL]
	OUTSTR	[ASCIZ	"Output file:"]	;GET OUTPUT FILE READY
	MOVE	0,[ OHD,,0]
	MOVEM	0,IOBUF			;SET UP OUTPUT BUFFER HEADER
	MOVEI	0,14			;MODE 14
	MOVEM	0,DMODE
OUFL:	PUSHJ	17,RDFIL		;PARSE FILENAME
	OPEN	2,DMODE			;OPEN AND TEST FOR ERROR
	JRST	.+2
	ENTER	2,FN1
	JRST	[ OUTSTR [ASCIZ "Can't write there, try again:"]
		  JRST	OUFL]
	OUTSTR	[ASCIZ "Keyword:"]	;ASK FOR KEYWORD
	;;CTLV				;SUPRESS ECHO
	SETOB	KEY1,KEY2		;INITIALIZE KEYS FOR EACH GENERATOR
INL:	INCHWL	2			;GET A CHARACTER
	CAIN	2,15			;CHECK FOR END OF LINE
	INCHWL	2
	CAIE	2,12
	CAIN	2,175
	JRST	IDN
	ANDI	2,177			;IF NOT END OF LINE, CONVERT CHAR
	CAIL	2,140			;TO RANGE 40 TO 137 ASCII, MAPPING
	SUBI	2,40			;LOWER CASE TO UPPER, AND STANFORD
	CAIGE	2,40			;SPECIALS TO REGULAR ASCII
	ADDI	2,40
	ROTC	KEY1,57			;NOW ROTATE THE KEY1,KEY2 DOUBLEWORD
	XOR	KEY1,2			;57 PLACES, AND XOR IN THE CONVERTED CHAR
	JRST	INL			;AND FETCH NEXT CHAR
IDN:	;;CTLV				;END OF KEYWD SCAN, RESUME ECHOING
	CLRBFI				;CLEAR INPUT BUFFER FOR GOOD MEASURE
	OUTSTR	[ ASCIZ	"
"]
	INPUT	1,0			;INITIALIZE INPUT AND
	OUTPUT	2,0			;OUTPUT BUFFERS
	CAIE	5,5			;IF FILE IS TO BE ENCODED,
	JRST	DEC
	MOVE	4,[714153265353]
	IDPB	4,OHD+1			;WRITE OUT ENCRYPTED FILE FLAG
	SOS	OHD+2
	;;ACCTIM	4,		;GET THE TIME OF DAY AND DATE
	gtad
	move	4,1
	IMULI	4,777775		;RANDOMIZE IT
	IDPB	4,OHD+1			;AND WRITE IT OUT
	SOS	OHD+2			;ALSO SAVE IT TO COMBINE WITH THE KEYS
	JRST	RDL
DEC:	ILDB	4,IHD+1			;OTHERWISE, IF DECODE, READ THE FIRST
	SOS	IHD+2			;WORD OF THE FILE
	CAME	4,[714153265353]	;AND SEE IF IT AN ENCRYPTED FILE FLAG
	JRST	[ OUTSTR [ASCIZ "
The input file is not encrypted  try again-

"]
		RESET
		JRST	GO]
	ILDB	4,IHD+1			;IF IT IS, USE THE SECOND WORD TO
	SOS	IHD+2			;MODIFY THE KEYS
RDL:	XOR	KEY1,4			;XOR THE RANDOMIZED TIME OF DAY WITH KEY1
	SUB	KEY2,4			;AND SUBTRACT IT FROM KEY2


	;THE MAIN READ, TRANSFORM, WRITE LOOP

RDLOOP:	SKIPG	IHD+2			;TEST FOR INPUT BUFFER EMPTY
	IN	1,0			;IF SO, READ THE NEXT
	JRST	NOIN
	OUTPUT	2,0			;IF NO MORE, FINISH OFF
	CLOSE	1,0
	CLOSE	2,0
	EXIT
NOIN:	ILDB	1,IHD+1			;OTHERWISE, GET NEXT WORD
	CAIE	5,5
	JRST	MAPSYN
	SETZ	5,
	CAME	1,[714153265353]	;IF ENCODE, CHECK FIRST WORD
	JRST	MAPSYN
	OUTSTR	[ASCIZ "
The input file seems to be already encrypted
should I go on anyway?"]
	INCHRW	4			;FOR POSSIBLY BEING A ENCRYPTED
	OUTSTR	[ASCIZ "

"]
	ANDI	4,137			;FILE HEADER
	CAIN	4,"Y"
	JRST	MAPSYN
	RESET	
	JRST	GO
MAPSYN:	MOVEI	12,44			;BEGIN TO SYNTHESIZE RANDOM MASK
	SETZ	13,
NOTNF:	IMULI	KEY1,377775		;GET NEXT NUMBER IN KEY1 SEQUENCE
	IMULI	KEY2,100003		;AND IN KEY2
	MOVEI	14,44
RLOOP:	TRNN	KEY1,1			;BESM-6 BIT MAP, EXTRACT THE BITS IN
	JRST	BDON			;KEY2 CORRESPONDING TO ONE BITS IN
	ROT	13,-1			;KEY1
	TRNE	KEY2,1
	TRO	13,1
	SUBI	12,1
BDON:	ROTC	KEY1,-1
	SOJG	14,RLOOP		;THE PREVIOUS LOOP EXCHNGD KEY1, KEY2
	EXCH	KEY1,KEY2		;SO RESTORE THEM TO THEIR RIGHTFUL PLACES
	JUMPG	12,NOTNF		;HAVE WE MADE 36 BITS YET?
	XOR	1,13			;IF SO, XOR THEM WITH THE WORD WE READ
	SOS	IHD+2
	SKIPG	OHD+2			;IF CURRENT OUT BUFFER IS FULL,
	OUTPUT	2,0			;WRITE IT OUT
	IDPB	1,OHD+1			;NOW DEPOSIT THE WORD
	SOS	OHD+2
LAST:	JRST	RDLOOP			;AND GET READY TO WORK ON NEXT ONE
	END GO