Fravia's TOOLS OF OUR TRADE Messageboard ~ Moderated
Re: Re: SICE Key Generator code (in ASM)
Thursday, 25-Feb-99 03:14:34
Hi!
For those of you preferring ASM for coding purposes: Here is my version (quite old but still working :) for TASM. No problems with angled brackets surrounding #include statements!
Generated code is 625 bytes long.
(-)Don_Quijote
################################################
.model tiny
.386
.code
org 100h
start proc near
mov ax,cs
mov ds,ax
mov es,ax
cld
mov si,offset Txt1
mov di,offset Def1
movsw
movsb
mov di,offset Def2
movsw
movsw
movsb
call IO
jc startFail
call GetCRC
call Copy2Clipboard
mov dx,offset Result
mov ah,9
int 21h
mov Looping,1
xor ax,ax
mov ds,ax
mov al,byte ptr ds:417h
test al,10h ; test if Scroll lock is pressed
jnz start
;mov ah,0
;int 16h
mov ax,4c00h
int 21h
startFail:
mov dx,offset Abort
mov ah,9
int 21h
mov ax,4c00h
int 21h
start endp
IO proc near
mov ah,9
mov dx,offset Welcome
mov al,ds:Looping
or al,al
jz IO01
mov dx,offset Prompt1
IO01:
int 21h
mov cl,3 ; Length = 3
mov si,offset Def1
mov di,offset Txt1
call GetText
jc IO99
mov ah,9
mov dx,offset Prompt2
int 21h
mov cl,5 ; Length = 5
mov si,offset Def2
mov di,offset Txt2
call GetText
IO99:
ret
IO endp
GetText proc near
; di = buffer
; si = default
; cl = length
xor bx,bx ; counter
mov ch,1 ; error flag
Get0:
mov ah,00h
int 16h ; Get Keypress
cmp al,8
je Get1
cmp al,13
je Get2
cmp al,27
je Get3
cmp al,'0'
jb Get0
cmp al,'9'
ja Get0
mov byte ptr ds:[di+bx],al
mov ah,2
mov dl,al
int 21h ; output char
inc bx
cmp bl,cl
jb Get0 ; get another char
jmp Get99
Get1: ; Backspace
or bx,bx
jz Get0 ; no chars entered yet
mov dl,8
mov ah,2
int 21h
mov dl,'.'
int 21h
mov dl,8
int 21h
dec bx
jmp Get0
Get2: ; Enter
mov ah,2
mov dl,8
Get21:
or bx,bx
jz Get22
dec bx
int 21h
jmp Get21
Get22:
lodsb
stosb
mov dl,al
int 21h
dec cl
jnz Get22
jmp Get99
Get3: ; ESC
xor ch,ch
Get99:
mov dl,13
mov ah,2
int 21h
mov dl,10
int 21h
sub ch,1
ret
GetText endp
Copy2Clipboard proc near
mov ax,1700h
int 2fh ; Is WinOldAp present?
cmp ax,1700h
je NoWin
mov ax,1701h
int 2fh ; Open Clipboard
mov ax,1703h
mov dx,0001h
push cs
pop es
mov bx,offset String
xor si,si
mov cx,15
int 2fh ; Set Data (for text)
mov ax,1708h
int 2fh ; Close Clipboard
NoWin:
ret
Copy2Clipboard endp
GetCRC proc near
mov si,offset Txt1
mov di,offset Work
mov bx,offset Matrix
mov cx,8
Crc1:
lodsb
and al,0fh
xlat
stosb
add bx,10
loop Crc1
; copied everything to Work (encrypted)
mov di,si ; di points to end of Txt1
mov si,offset Work
mov cx,4
Crc2:
lodsb
xor al,ds:[si+3]
or al,ds:[offset Work+7]
add al,'0'
cmp al,'9'
jbe NoFix
add al,'A'-'9'-1
NoFix:
stosb
loop Crc2
mov si,offset Txt1
mov di,offset String
mov al,'-'
movsd
stosb
movsd
movsw
stosb
movsw
ret
GetCRC endp
.data
Matrix db 15, 01, 11, 03, 08, 04
db 13, 07, 12, 06
db 10, 12, 01, 08, 02, 00
db 09, 15, 05, 11
db 09, 05, 12, 02, 07, 06
db 15, 04, 14, 10
db 03, 04, 12, 11, 01, 10
db 13, 08, 00, 14
db 13, 01, 06, 11, 08, 10
db 14, 04, 03, 12
db 07, 11, 06, 10, 05, 09
db 04, 08, 00, 03
db 00, 13, 03, 15, 10, 08
db 02, 12, 04, 06
db 09, 05, 13, 01, 03, 11
db 12, 04, 02, 08
Welcome db "Welcome to Numega (keep looping with Scroll-Lock)",13,10
Prompt1 db "Enter program identifier ["
Def1 db "???]: ...",8,8,8,"$"
Prompt2 db "Enter any 5 digit number ["
Def2 db "?????]: .....",8,8,8,8,8,"$"
Result db "The generated number is "
String db "1900-0000DD-BD",0
db 13,10,10,"$"
Abort db "Program aborted by user",13,10,"$"
Looping db 0
Txt1 db "151"
Txt2 db "00005"
db 4 dup (?) ; for the checksum
Work db 8 dup (?)
end start
Don Quijote