;============================================================================= ; Crypt_02.asm ; This program will change the ciphertext in the file and output to another ; file! ; Algorithm ; C1: Open the ciphertext file ; C2: Read the words into buffer ; C3: Output the buffer, with one space between words ; C4: Read a letter and check if it is Esc. If true => exit ; C5: Get what a letter must be changed to! ; C6: Save all ; C7: Change the specified letter in all the words ; C8: Show new => C3 ;(C)I don't take any responsibility for the use of this program ; Zedr0n -- connection closed ;============================================================================= ;============================================================================= ; .Com declaration ;============================================================================= .MODEL TINY ; LOCALS @@ ;============================================================================= ; Data definition/declaration ;============================================================================= .DATA ; ;----------------------------------------------------------------------------- ; Equals ;----------------------------------------------------------------------------- LENG EQU 16 ; Number of max letters in a word LENGW EQU 50 ; Max number of words in cipher text ;----------------------------------------------------------------------------- ; Structures ;----------------------------------------------------------------------------- WORDS STRUC ; ELEM DB LENG DUP(?) WORDS ENDS ;----------------------------------------------------------------------------- ; Constants ;----------------------------------------------------------------------------- FILENAME DB "CIPHER.TXT",0 CRLF DB 0DH,0AH,'$' ;----------------------------------------------------------------------------- ; File variables ;----------------------------------------------------------------------------- BUFFER WORDS LENGW DUP (?) ; HFILE DW ? ;----------------------------------------------------------------------------- ; Stack variables ;----------------------------------------------------------------------------- .CODE .386 ORG 100H ;============================================================================= ; Code segment ;============================================================================= START: ; CUR_BYTE EQU [BP-1] SOURCE EQU [BP-2] ; DEST EQU [BP-3] C1: ; ENTER 3,0 MOV AH,3DH ; MOV DX,OFFSET FILENAME XOR AL,AL ; Read-only mode INT 21H ; MOV HFILE,AX XOR BX,BX ; XOR DI,DI C2: CALL FIND_WORD ; MOV BX,DI PUSH BX CALL GET_WORD INC DI MOV AH,3FH MOV BX,HFILE ; MOV CX,1 ; LEA DX,CUR_BYTE INT 21H ; MOV AH,CUR_BYTE CMP AH,'@' JNZ C2 C3: ; CALL SHOW_BUFFER C4: ; XOR AH,AH ; INT 16H ; CMP AH,1H ; JZ EXIT ; AND AL,5FH CMP AL,'A' JL C4 ; CMP AL,'Z' ; JG C4 ; MOV SOURCE,AL C6: XOR AH,AH ; INT 16H CMP AH,1H ; JZ EXIT ; AND AL,5FH CMP AL,'A' ; JL C6 ; CMP AL,'Z' ; JG C6 MOV DEST,AL ; C7: ; PUSH DEST ; PUSH SOURCE ; CALL CHANGE_SYM MOV AH,09H ; MOV DX,OFFSET CRLF ; INT 21H INT 21H ; INT 21H JMP C3 EXIT: LEAVE RET ;============================================================================= ; Procedures ;============================================================================= INCLUDE ..\LIB\FILE.INC ;----------------------------------------------------------------------------- ; Get_Word ; Puts the word into the buffer with index specified by BX ; Algorithm ; G1: Get absolute index ; G2: Get char, if not space, new line or non-letter => put into buffer ; G3: Exit ; ; ;----------------------------------------------------------------------------- GET_WORD PROC ; @@CUR_BYTE EQU [BP-1] ENTER 1,0 ; PUSHA G1: ; IMUL BX,LENG ; XOR DI,DI MOV AH,3FH ; MOV CX,1 ; LEA DX,@@CUR_BYTE PUSH BX G2: ; POP BX ; PUSH BX MOV BX,HFILE MOV AH,3FH INT 21H ; MOV AH,@@CUR_BYTE ; CMP AH,20H ; JZ G3 ; CMP AH,0DH ; JZ G2 ; CMP AH,0AH ; JZ G2 CMP AH,'A' ; JL G2 ; CMP AH,'Z' JG G2 ; POP BX PUSH BX LEA BX,BUFFER[BX] MOV [BX][DI],AH ; INC DI JMP G2 G3: ; POP BX LEA BX,BUFFER[BX] ; MOV [BX][DI],'$' POPA LEAVE RET GET_WORD ENDP ;----------------------------------------------------------------------------- ; Show_buffer ; Outputs all the buffer with one space between words ; S1: Initialize counters ; S2: Show current word. Increase counter ; S3: Is it the last word? If not => S2 ;----------------------------------------------------------------------------- SHOW_BUFFER PROC ; PUSHA S1: ; PUSH -1 S2: POP BX INC BX PUSH BX IMUL BX,16 LEA DX,BUFFER[BX] MOV AH,09H ; INT 21H ; MOV DX,OFFSET CRLF ; INT 21H S3: DEC DI JNZ S2 @@EXIT: POP BX POPA RET SHOW_BUFFER ENDP ;----------------------------------------------------------------------------- ; Change_sym ; Change all the source chars to dest in the buffer ; H1: Initialize counters ; Ç2: Get word's offset ; H3: ;----------------------------------------------------------------------------- CHANGE_SYM PROC ; @@DEST EQU [BP+6] ; @@SOURCE EQU [BP+4] PUSH BP ; MOV BP,SP PUSHA H1: ; PUSH -1 H2: ; MOV DI,-1 POP BX ; INC BX ; PUSH BX CMP BX,SI ; JG @@EXIT IMUL BX,16 ; LEA BX,BUFFER[BX] ; MOV AL,@@SOURCE MOV AH,@@DEST H3: INC DI CMP [BX+DI],'$' ; JZ H2 CMP [BX+DI],AL JNZ H3 ; MOV [BX+DI],AH JMP H3 @@EXIT: POP BX POPA ; POP BP RET CHANGE_SYM ENDP END START