home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / LOCK.ASM < prev    next >
Assembly Source File  |  1986-02-05  |  6KB  |  146 lines

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