home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / Assembly / LOCK.ASM < prev    next >
Assembly Source File  |  1979-12-31  |  6KB  |  147 lines

  1.  
  2. COMMENT*  Change ROR -> ROL in the TWO marked places to produce UNLOCK.ASM  *
  3. CODE_SEG        SEGMENT
  4.         ASSUME  CS:CODE_SEG
  5.         ORG     100H
  6. HERE:   JMP     THERE
  7.         COPY_RIGHT      DB       '(C)1985 Steven Holzner'
  8.         PROMPT  DB      'Phrase: $'     ;All the messages & prompts
  9.         DEFAULT DB      'FILE.LOC',0
  10.         NOTSEEN DB      13,10,'File Not Found$'
  11.         FULL:   DB      13,10,'Disk Full$'
  12.         FILETWO DW      0               ;Address of 2nd File name
  13.         FILEND  DW      0               ;End of read-in files in memory
  14. THERE   PROC    NEAR                    ;Our procedure
  15.         MOV     BX,81H                  ;Make the filenames into ASCIIZ
  16. UP:     INC     BX                      ;Scan type-in for space, <cr>
  17.         CMP     BYTE PTR [BX],' '       ;Space?
  18.         JNE     NOSPACE
  19.         MOV     BYTE PTR [BX],0         ;Put the Z in ASCIIZ
  20.         MOV     FILETWO,BX              
  21.         INC     FILETWO                 ;Store filename starting location
  22. NOSPACE:CMP     BYTE PTR [BX],13        ;If not a space, a <cr>?
  23.         JNE     UP
  24.         MOV     BYTE PTR [BX],0         ;If yes, replace with a 0
  25.         CMP     FILETWO,0
  26.         JNZ     OVER
  27.         MOV     FILETWO,OFFSET DEFAULT  ;If no second file given, use default
  28. OVER:   LEA     DX,PROMPT               ;Type out the prompt with string print
  29.         MOV     AH,9
  30.         INT     21H   
  31.         MOV     BX,80H+40H-2            ;Prepare 40H (64) buffer for key phrase
  32.         MOV     BYTE PTR [BX],40H
  33.         PUSH    BX                      ;Set up buffer address
  34.         POP     DX
  35.         MOV     AH,0AH                  ;Buffered input
  36.         INT     21H
  37.         MOV     BX,80H+40H              ;Start of key phrase
  38.         PUSH    BX
  39. JUMP:   CMP     BYTE PTR [BX],13        ;Set up key phrase's ASCII values
  40.         JE      READY                   ;Scan until <cr>
  41.         OR      BYTE PTR [BX],1         ;Make it odd
  42.         AND     BYTE PTR [BX],0FH       ;Use only lower four bits
  43.         INC     BX
  44.         JMP     JUMP                    ;Keep going until <cr>
  45. READY:  POP     BX
  46.         MOV     AX,3D00H                ;Open the file to encrypt
  47.         MOV     DX,82H                  ;Point to its name
  48.         INT     21H
  49.         JNC     OKFILE                  ;Carry Flag --> some problem, assume
  50.         LEA     DX,NOTSEEN              ;  file doesn't exist, say so
  51.         MOV     AH,9
  52.         INT     21H
  53.         JMP     OUT                     ;Exit
  54.                                         
  55. OKFILE: PUSH    BX                      ;Store location in key phrase
  56.         MOV     BX,AX                   ;Put handle into BX
  57.         MOV     CX,62*1024              ;Ask for 62K bytes to be read from file
  58.         LEA     DX,THEBOTTOM            ;And put at end of program
  59.         MOV     AH,3FH                  ;Read
  60.         INT     21H  
  61.         ADD     AX,OFFSET THEBOTTOM     ;Actually read AX bytes
  62.         MOV     FILEND,AX               
  63.         DEC     FILEND                  ;Find how far the file extends in mem.
  64.         MOV     AH,3EH                  ;Close file, thank you very much.
  65.         INT     21H
  66.         POP     BX
  67.         LEA     CX,THEBOTTOM            ;Save current location in file in CX
  68.  
  69. SCRMBLE:MOV     SI,CX                   ;Will scramble from [SI] to [DI]
  70.         CMP     SI,FILEND               ;Past end?
  71.         JAE     DONE                    ;If yes, exit
  72.         MOV     DI,CX
  73.         XOR     AX,AX
  74.         MOV     AL,[BX]                 ;How many to scramble? (from key phrase)
  75.         ADD     DI,AX
  76.         MOV     CX,DI                   
  77.         INC     CX                   ;Store new starting location for next time
  78.  
  79.         INC     BX                   ;Also, get next character for next scramble
  80.         CMP     BYTE PTR [BX],13        ;If at end of key phrase, wrap
  81.         JNE     TWIST
  82.         MOV     BX,80H+40H
  83.  
  84. TWIST:  CMP     DI,FILEND               ;Is DI past end?
  85.         JBE     GRAB
  86.  
  87.         MOV     DI,FILEND               ;If yes, only scramble to file end
  88.         PUSH    DI
  89.         SUB     DI,SI                   ;What about last byte?
  90.         TEST    DI,1
  91.         POP     DI
  92.         JNZ     GRAB                    ;If left over, rotate it once
  93.         ROR     BYTE PTR [DI],1         ;<--- ROL FOR UNLOCK!!!
  94.         DEC     DI
  95.         CMP     SI,DI
  96.         JAE     DONE
  97.  
  98. GRAB:   MOV     DH,[SI]                 ;Get byte 1
  99.         MOV     DL,[DI]                 ;Get byte 2
  100.         PUSH    CX
  101.         MOV     CL,[BX]                 ;Get number of times to rotate
  102.  
  103.         INC     BX                      ;Set up key phrase char for next time
  104.         CMP     BYTE PTR [BX],13
  105.         JNE     TWISTER
  106.         MOV     BX,80H+40H
  107.                                         ;Rotate the hybrid word
  108. TWISTER:ROR     DX,CL                   ;<--- ROL FOR UNLOCK!!!
  109.         POP     CX
  110.         MOV     [SI],DH                 ;And replace the parts
  111.         MOV     [DI],DL
  112.         INC     SI                      ;Point to next part to scramble
  113.         CMP     SI,DI                   ;Have SI and DI met yet?
  114.         JE      SCRMBLE             ;If yes, move on to next part to scramble
  115.         DEC     DI
  116.         JMP     GRAB                    ;Go back until done
  117. DONE:   MOV     AH,3CH                  ;Done
  118.         MOV     CX,0                    ;Prepare to write out scrambled version
  119.         MOV     DX,FILETWO
  120.         INT     21H                     ;Create the file
  121.         JC      ERROR
  122.         MOV     BX,AX
  123.         MOV     AH,40H
  124.         LEA     DX,THEBOTTOM
  125.         MOV     CX,FILEND               ;File size to write
  126.         SUB     CX,OFFSET THEBOTTOM
  127.         INC     CX
  128.         INT     21H                     ;Write it out
  129.         CMP     AX,CX                   ;If error, (returned)AX .NE. (orig.)CX
  130.         JE      CLOSE
  131. ERROR:  LEA     DX,FULL                 ;Assume disk is full, say so, leave
  132.         MOV     AH,9 
  133.         INT     21H 
  134.         JMP     OUT
  135. CLOSE:  MOV     AH,3EH                  ;Otherwise, close the file and exit
  136.         INT     21H   
  137. OUT:    INT     20H
  138. THERE   ENDP
  139. THEBOTTOM:                              ;Read-in file starts here.
  140.         CODE_SEG        ENDS            
  141.         END     HERE
  142.  
  143.  
  144.         
  145.                          
  146.  
  147.