Trailing-Edge
-
PDP-10 Archives
-
decuslib10-12
-
43,50554/2/crypt.mac
There are 24 other files named crypt.mac in the archive. Click here to see a list.
title crypt
;
;program to encrypt a file
;
search uuosym,scnmac
.request rel:endecr,rel:scan,rel:helper
;
;for information regarding this program contact:
; Dr. Edmund West
; University of Toronto Computing Services
; 255 Huron St.
; Toronto, Ontario M5S 1A1
; (416-978-4085)
;
;version parameters
cryver==2
cryedt==2
crymin==0
crywho==0
loc 137
byte (3)crywho(9)cryver(6)crymin(18)cryedt
twoseg
reloc 0
;
;conditional assembly parameters
ifndef ftdeb,<ftdeb==0>
ifn ftdeb,<if2,printx [debug version]>
ife ftdeb,<if2,printx [production version]>
;
;ac definitions
s==0
t1==1
t2==2
t3==3
t4==4
c==5
b==6
a==7
p==17
;
;parameter definitions
;
;status bits
s.ccl==1 ;ccl entry
s.in==10 ;input file seen
s.inx==20 ;input file seen two or more times
s.out==100 ;output file seen
s.outx==200 ;output file seen two or more times
s.filb==s.inx!s.outx ;bad bits from file spec processing
s.key==1000 ;key switch was in command line
s.keyx==2000 ;key switch seen two or more times
s.keyn==10000 ;key switch was null
s.keyi==200000 ;key switch has illegal character
s.keyt==400000 ;key switch has too many characters
s.keyb==s.keyx!s.keyn!s.keyi!s.keyt ;switch problem
s.clr==s.key!s.keyb!s.in!s.out!s.filb ;bits to clear during .tscan init
s.tscn==s.keyb!s.filb ;bits to test after .tscan call
;
;value definitions
pdll==100 ;length of push down list
keyl==5 ;number of disk blocks in encryption key
keymax==5*keyl ;characters in key
di==1 ;disk input channel
do==2 ;disk output channel
tty==3 ;tty channel
nblks=5 ;number of disk blocks per i/o buffer
bufl==nblks*200 ;length of i/o buffer
sblkl==.fxlen
oblkl==4
lblkl==.rbsiz+1 ;length of lookup/enter block
c.ret==15 ;return
c.lf==12 ;line feed
c.esc==33 ;escape
c.ctlz==32 ;control-z
c.spc==40 ;space
c.zlc==172 ;z (lower case)
;
;macro definitions
;
;define scan switches
define swtchs<
sp key,keyflg,keypro,,fs.vrq!fs.nfs
>
;define message macros
define msg(a),<
movei t1,[asciz\a\]
pushj p,.tstrg##
>
define msgcr (a),<
msg <a>
pushj p,.tcrlf##
>
;define error message macros
define emsg(a,b),<
msg <?CRY'a >
msg <b>
>
define emsgcr (a,b),<
emsg (<a>,<b>)
pushj p,.tcrlf##
>
;define error message subroutine macro
define errmsg (a,b),<
pushj p,[emsgcr(<a>,<b>)
popj p,]
>
;
;
;data storage
;
pdl: block pdll ;push down list
keyflg: block 1 ;key switch flag for scan
key1: block keyl ;encryption key
block 1 ;guaranteed null character
key2: block keyl ;second key for verification
seed: block 1 ;encryption seed
nwdsr: block 1 ;number of words remaining to transfer
olist: block 1 ;output io list
block 1 ;iolist terminator
ilist: block 1 ;input io list
block 1 ;iolist terminator
elist: block 1 ;encryption aobjn word
buf: block bufl ;i/o buffer
iblk: block 6 ;iscan data
iblkl=.-iblk
tblk: block 11 ;tscan data
tblkl=.-tblk
sblki: block sblkl ;scan block for input file
oblki: block 4 ;open block for input file
bcbi: block 3 ;input buffer control block
lblki: block lblkl ;lookup block for input file
pblki: block .ptmax ;path block for input file
sblko: block sblkl ;scan block for output file
oblko: block 4 ;open block for output file
bcbo: block 3 ;output buffer control block
lblko: block lblkl ;enter block for output file
pblko: block .ptmax ;path block for output file
oblkt: block 3 ;open block for tty
bcbt: block 4 ;tty buffer control block
;
;execution
;
reloc 400000
crypt::
tdza s,s ;clear status
movei s,s.ccl ;ccl entry
outstr [asciz\[CRYPT, /H for help]\]
ifn ftdeb,<
outstr [asciz\ [DEBUG version]\]
>;end ftdeb
go:
reset
andi s,s.ccl ;clear most status bits
;set up blocks for .iscan
move p,[iowd pdll,pdl]
pushj p,.tcrlf##
move t1,[xwd iblkl,iblk] ;set up for scanning
pushj p,.iscan##
;set up blocks for .tscan
move t1,[iowd cryswl,cryswn] ;set up for scan switchs
movem t1,tblk
move t1,[xwd cryswd,cryswm]
movem t1,tblk+1
move t1,[xwd 0,cryswp]
movem t1,tblk+2
move t1,[sixbit\crypt\] ;help file name
movem t1,tblk+3
move t1,[xwd clra,0] ;clear all answers
movem t1,tblk+4
move t1,[xwd alli,allo] ;scan block allocation routines
movem t1,tblk+5
movei t1,fs.mot ;allow multiple output file specs
hrrm t1,tblk+7
move t1,[xwd tblkl,tblk] ;scan command line
pushj p,.tscan##
trnn s,s.tscn ;was an error detected?
jrst getin ;no, get file specs
;fall through to tell user about command line error
;tell user about all the errors he had
trne s,s.inx ;extra input files?
errmsg XIF,Extra input files
trne s,s.outx ;extra output files?
errmsg XOF,Extra output files
trne s,s.keyx ;extra key switchs?
errmsg XKS,Extra KEY switchs
trne s,s.keyn ;null key?
errmsg NKI,Null key illegal
trne s,s.keyi ;illegal character in key?
errmsg ICK,Illegal character in key
trne s,s.keyt ;too many characters in key?
errmsg TMC,Too many characters in key
jrst go
;get input file spec
getin:
trne s,s.in ;did alli get called?
skipn sblki+.fxnam ;yes, did user specify input file?
jrst [emsgcr IFR,Input file required
jrst go]
move t1,[xwd sblkl,sblki] ;set up input blocks
movei t2,oblki
move t3,[xwd .rbsiz,lblki]
movei t4,pblki
pushj p,.stopb##
jrst [emsgcr IIF,Illegal input file specification
jrst go]
;get output file spec
trne s,s.out ;did allo get called?
skipn sblko+.fxnam ;yes, did user specify output file?
jrst [move t1,[xwd sblki,sblko] ;no, use input file
blt t1,sblko+sblkl-1
jrst .+1]
move t1,[xwd sblkl,sblko] ;set up output blocks
movei t2,oblko
move t3,[xwd .rbsiz,lblko]
movei t4,pblko
pushj p,.stopb##
jrst [emsgcr IOF,Illegal output file specification
jrst go]
;initialize input file
movei t1,bcbi ;input buffer control block
hrrm t1,oblki+.opbuf
movei t1,.iodmp ;dump mode input
movem t1,oblki+.opmod
open di,oblki ;open device
jrst [emsg IOE,<Input open error for >
jrst inerr]
movei t1,.rbsiz ;last word of lookup block
movem t1,lblki
lookup di,lblki ;lookup file
jrst [emsg ILE,<Input lookup error (>
hrrz t1,lblki+.rbext
pushj p,.toctw##
msg <) for >
jrst inerr]
move t1,lblki+.rbsiz ;number of words in file
movem t1,nwdsr ;number of words remaining for i/o
;get encryption key
trne s,s.key ;was key seen as switch?
jrst compok ;yes, do not request key from user
getkey:
movei t1,[asciz\Encryption key:\]
pushj p,.tstrg##
setzm key1 ;clear key storage
move t1,[xwd key1,key1+1]
blt t1,key1+keyl-1
move b,[point 7,key1] ;point to first key
pushj p,rdkey ;and read it
jrst getkey ;try again if error
;get verification key
pushj p,.tcrlf##
movei t1,[asciz\Verify key:\]
pushj p,.tstrg##
setzm key2 ;clear key storage
move t1,[xwd key2,key2+1]
blt t1,key2+keyl-1
move b,[point 7,key2] ;point to second key
pushj p,rdkey ;and read it
jrst getkey ;try again if error
pushj p,.tcrlf##
;compare keys
movei c,keyl ;number of words to compare
comp:
sojl c,compok ;quit if compare is ok
move t1,key1(c) ;get first key word
came t1,key2(c) ;compare with second key word
jrst [emsgcr KDM,<Keys don't match>
jrst getkey]
jrst comp ;this word is ok, try next
compok:
;initialize output file
movei t1,bcbo ;output buffer control block
hrlm t1,oblko+.opbuf
movei t1,.iodmp ;dump mode output
movem t1,oblko+.opmod
open do,oblko ;open device
jrst [emsg OOE,<Output open error for >
jrst outerr]
movei t1,.rbsiz ;last word of enter block
movem t1,lblko+.rbcnt
enter do,lblko ;enter file
jrst [emsg OEE,<Output enter error (>
hrrz t1,lblko+.rbext
pushj p,.toctw##
msg <) for >
jrst outerr]
;if debugging, tell user what's happening
ifn ftdeb,<
msg <[>
movei t1,oblko
movei t2,lblko
pushj p,.toleb##
msg <=>
movei t1,oblki
movei t2,lblki
pushj p,.toleb##
msg </KEY:>
move b,[point 7,key1]
;type out the key
nxtchr:
ildb t1,b ;get next character in key
jumpe t1,nochr ;quit if find null
cail t1," " ;less than "space" (non-printable)?
jrst typchr ;no, skip special processing
addi t1,"@" ;move to upper case range
push p,t1 ;save this character
movei t1,"^" ;type up-arrow
pushj p,.tchar##
pop p,t1 ;restore actual character
typchr:
pushj p,.tchar## ;type this character
jrst nxtchr ;get next character
nochr:
msgcr <]>
>;end ftdeb
;initialize encryption procedure
movei a,key1 ;location of encryption key
pushj p,crasz.## ;get encryption seed
movem c,seed ;save seed
;main i/o loop
loop:
skipg t2,nwdsr ;number of words remaining to read
jrst iodone ;done if negative or zero
movei t1,bufl ;number of i/o words = size of buffer
caig t2,bufl ;unless less than that remain
move t1,t2 ;if so, use number remaining
sub t2,t1 ;update number of words remaining
movem t2,nwdsr ;and save it
movn t3,t1 ;negative of words to transfer
hrlzs t3 ;put in left half
hrri t3,buf-1 ;i/o list [-n,,buf-1]
movem t3,ilist ;input iowd [xwd -n,buf-1]
movem t3,olist ;output iowd
addi t3,1 ;set up encryption word
movem t3,elist ;and save it
;fill buffer from input file
in di,ilist ;read input
jrst inok ;input is ok
emsg IER,<Input error reading >
jrst inerr
inok:
;encrypt block
move a,elist ;aobjn word of buffer
move b,[1] ;block key
move c,seed ;encryption seed
pushj p,crypt.## ;encrypt buffer
;empty buffer to output file
out do,olist ;write output
jrst loop ;output is ok, try next one
emsg OEW,<Output error writing >
jrst outerr
iodone:
;data transfer is complete
releas di, ;release input
releas do, ;release output
jrst go ;set up to do it all again
;
;allocate space for input file specification
alli:
troe s,s.in ;seen before?
tro s,s.inx ;yes, remember
setzm sblki ;no, clear input scan block
move t1,[xwd sblki,sblki+1]
blt t1,sblki+sblkl-1
movei t1,sblki ;scan block for input file
movei t2,sblkl
popj p,
;
;allocate space for output file specification
allo:
troe s,s.out ;seen before?
tro s,s.outx ;yes, remember
setzm sblko ;no, clear output scan block
move t1,[xwd sblko,sblko+1]
blt t1,sblko+sblkl-1
movei t1,sblko ;no, get scan block for output file
movei t2,sblkl
popj p,
;
;clear all answers
clra:
setom keyflg ;initialize key flag for scan
trz s,s.clr ;clear appropriate status bits
;clear scan blocks for .tscan and .stopb processing
setzm sblki ;clear input scan block
move t1,[xwd sblki,sblki+1]
blt t1,sblki+sblkl-1
setzm sblko ;clear output scan block
move t1,[xwd sblko,sblko+1]
blt t1,sblko+sblkl-1
popj p,
;
;process key switch
keypro:
troe s,s.key ;seen before?
tro s,s.keyx ;yes, remember
setzm key1 ;clear key storage
move t1,[xwd key1,key1+1]
blt t1,key1+keyl-1
pushj p,.ascqw## ;input a string
move t3,[point 7,.nmul##] ;point to character string
move t4,[point 7,key1] ;point to key string
setz t2, ;set character counter
keyp1:
ildb t1,t3 ;get character
jumpe t1,[jumpn t2,.popj1## ;done if null and at least one char
tro s,s.keyn ;null key
jrst .popj1##]
cail t2,keymax ;one too many?
jrst t2,[tro s,s.keyt ;yes
jrst .popj1##]
caile t1,c.spc ;"space" or less?
caile t1,c.zlc ;or greater than lower case "z"?
jrst [tro s,s.keyi ;yes, illegal character
jrst .popj1]
idpb t1,t4 ;looks ok, save character
aoja t2,keyp1 ;get next character
;
;read encryption key
rdkey:
ife ftdeb,< movei t1,io.sup ;no echoing>
ifn ftdeb,< setz t1, ;echoing>
movem t1,oblkt+.opmod
move t1,[sixbit\tty\] ;device tty
movem t1,oblkt+.opdev
movei t1,bcbt ;buffer control block for tty
hrrm t1,oblkt+.opbuf
open tty,oblkt ;open tty for input
jrst [emsg COT,<Cannot open TTY for input>
jrst go]
setz c, ;initialize character counter
next:
pushj p,getchr ;get input character in t1
jrst linok ;end of input
caie t1,c.ret ;return?
cain t1,c.lf ;no, line feed?
jrst linok ;yes, end of line
caie t1,c.esc ;escape?
cain t1,c.ctlz ;no, control-z?
jrst linok ;yes, end of line
caile t1,c.spc ;"space" or less?
caile t1,c.zlc ;or greater than lower case "z"?
jrst [releas tty,
emsgcr ICK,<Illegal character in key>
popj p,]
caige c,keymax ;character count at maximum yet?
idpb t1,b ;no, deposit this character
aoja c,next ;get next character
linok:
releas tty, ;release device and finish input
jumpe c,[emsgcr NKI,<Null key illegal>
popj p,]
caile c,keymax ;more characters than maximum?
jrst [emsgcr TMK,<Too many key characters>
popj p,]
jrst .popj1## ;good return
getchr:
sosge bcbt+.bfctr ;any characters in input buffer?
jrst getbuf ;no, read in next buffer
ildb t1,bcbt+.bfptr ;yes, get character in t1
jrst .popj1## ;and return
getbuf:
in tty, ;set up input buffer
jrst getchr ;and try again
getsts tty,t1 ;input error
trne t1,io.eof ;end of file?
popj p, ;yes, that's ok
emsgcr TIE,<TTY input error>
jrst go
;
;type file error message and restart program
inerr:
movei t1,oblki ;open block for input file
movei t2,lblki ;lookup block for input file
jrst filerr
outerr:
movei t1,oblko ;open block for output file
movei t2,lblko ;lookup block for output file
filerr:
pushj p,.toleb##
pushj p,.tcrlf##
clrbfi
jrst go
;
;set up for scan switch processing
doscan (crysw)
end crypt