;============================================================================= ; crypt01.asm ; This program takes ciphertext from crypt.txt and then calculates the ; frequencies of the letters and outputs on screen. ; Algorithm ; C1: Open file ; C2: Find next word ; C3: Read symbols in word and put number into buffer ; C4: Show the buffer ; C5: Show total number of characters ;(C)I don't take any responsibility for the use of this program ; Zedr0n -- connection closed ;============================================================================= ;============================================================================= ; .Com declaration ;============================================================================= .MODEL TINY ;============================================================================= ; Data definition/declaration ;============================================================================= .DATA ;----------------------------------------------------------------------------- ; Equals ;----------------------------------------------------------------------------- SPACE EQU 20H ; ;----------------------------------------------------------------------------- ; Constants ;----------------------------------------------------------------------------- CRLF DB 0DH,0AH,'$' A_STR DB "A - ",'$' FILENAME: DB "CIPHER.TXT",0 TOTAL DB "Total number of chars - ",'$' ;----------------------------------------------------------------------------- ; File variables ;----------------------------------------------------------------------------- BUFFER DB 26 DUP(?) HFILE DW ? TOT DB ? ;----------------------------------------------------------------------------- ; Stack variables ;----------------------------------------------------------------------------- .CODE .386 ORG 100H ;============================================================================= ; Code segment ;============================================================================= CUR_BYT1 EQU [BP-1] START: ENTER 1,0 ; Allocate space for filename DEC DI ; DI is assumed to be 0 C1: MOV AH,3DH ; XOR AL,AL ; Set the read only mode XOR CL,CL ; LEA DX, FILENAME INT 21H OR AX,AX ; JZ EXIT MOV HFILE,AX CALL CLEAR C2: ; CALL FINDWORD ; C3: ; CALL GETSYM ; MOV AH,3FH ; MOV BX,HFILE ; MOV CX,1 ; LEA DX,CUR_BYT1 INT 21H ; MOV AH,BYTE PTR CUR_BYT1; CMP AH,'@' ; JZ C4 ; JMP C2 C4: ; CALL CALC_TOTAL ; MOV TOT,AL MOV BX,-1 C41: inc bx cmp bx,26 jz C5 cmp BUFFER[bx],0 jz C41 mov ah,09h mov dx,offset CRLF int 21h push bx add bl,41h mov A_str[0],bl pop bx mov dx,offset A_str int 21h mov al,BUFFER[bx] xor ah,ah CALL HEXDEC jmp C41 C5: ; MOV AH,09H MOV DX,OFFSET CRLF ; INT 21H ; MOV DX,OFFSET TOTAL ; INT 21H MOV AL,TOT CALL HEXDEC EXIT: LEAVE RET ;=============================================================================== ; Procedures ;=============================================================================== ;----------------------------------------------------------------------------- ; FindWord ; Find the next word in the file ; Algorithm ; ; F1: Read the byte. ; F2: Check if it is space, or end of line, if it isn't then it was the ; beginning of the new word ; F3: Decrease pointer ;----------------------------------------------------------------------------- FindWord proc cur_byte equ [bp-1] enter 1,0 pusha F1: mov ah,3Fh mov bx,HFILE mov cx,1 lea dx,cur_byte int 21h F2: mov ah,cur_byte cmp ah,SPACE jz F1 cmp ah,0Dh jz F1 cmp ah,0Ah jz F1 F3: mov ah,42h mov al,1 xor cx,cx xor dx,dx int 21h mov dx,ax mov ah,42h xor al,al xor cx,cx dec dx int 21h popa leave ret FindWord endp ;----------------------------------------------------------------------------- ; GetSym ; G1: Read char ; G2: Is it space, or new line? If not read another! ;----------------------------------------------------------------------------- GETSYM PROC ; CUR_BYT EQU [BP-1] ; ENTER 1,0 ; PUSHA G1: ; MOV AH,3FH ; MOV CX,1 MOV BX,HFILE ; LEA DX,CUR_BYT ; INT 21H MOVZX BX,BYTE PTR CUR_BYT G2: ; CMP BX,SPACE ; JZ G3 CMP BX,0DH ; JZ G3 ; CMP BX,0AH ; JZ G3 AND BX,5FH ; CMP BX,'A' ; JL G1 ; CMP BX,'Z' ; JG G1 SUB BX,'A' ; INC BUFFER[BX] JMP G1 G3: POPA LEAVE RET GETSYM ENDP ;----------------------------------------------------------------------------- ; CLEAR ; Clear the buffer ; Algorithm ; L1: ; L2: ;----------------------------------------------------------------------------- CLEAR PROC ; PUSHA MOV BX,26 ; L1: MOV BUFFER[BX-1],00 ; DEC BX ; JNZ L1 ; ; POPA RET CLEAR ENDP ;-------------------------------------------------------------------------------------------------------------------------------------------- ; HEXDEC ; Convert the hexadecimal value in al to ascii and output it. Show a colon also... ; H1: Get the number of 10's ; H2: Show the digit ; H3: Is it seconds? If not go H7 ; H4: Show colon! ; H5: exits ;-------------------------------------------------------------------------------------------------------------------------------------------- HEXDEC proc mov dl,30h H1: push dx H2: cmp al,10 JL H3 ;jl H3. Otherwise 2 nop's are inserted sub al,10 inc dx ; shorter than inc dl, but in this case does just the same jmp H2 H3: mov ah,02h push ax int 21h pop ax pop dx add dl,al int 21h H4: ret HEXDEC endp ;----------------------------------------------------------------------------- ; CALC_TOTAL ; Calculate total number of chars ;----------------------------------------------------------------------------- CALC_TOTAL PROC ; MOV BX,26 ; XOR AL,AL T1: ADD AL,BUFFER[BX-1] DEC BX ; JNZ T1 RET ; CALC_TOTAL ENDP END START