52 lines
793 B
NASM
52 lines
793 B
NASM
;;xorcrypt
|
|
;;<en><de>crypts a string using xor
|
|
;;Inputs:
|
|
;; HL: string pointer
|
|
;; DE: seed pointer (shorter)
|
|
;;Notes:
|
|
;; Changes string in place.
|
|
xorcrypt:
|
|
push hl
|
|
push de
|
|
call strlen
|
|
push hl
|
|
ld hl, 0
|
|
ld h, b
|
|
ld l, c
|
|
ex de, hl
|
|
call strlen
|
|
ex de, hl
|
|
ld a, l ;BC = len(seed) hl=len(string)
|
|
sub c
|
|
jr nc, xorcryptSmaller
|
|
ld a, 0
|
|
xorcryptSmaller:
|
|
ld bc, 0
|
|
ld b, a
|
|
ld c, l ;b=len(seed) c=len(string)
|
|
pop hl
|
|
or a, a
|
|
jr z, strxorPadLoopEnd
|
|
ex de, hl; hl=seed
|
|
push bc
|
|
ld c, 0
|
|
add hl, bc
|
|
pop bc
|
|
inc b
|
|
ld (hl), %10000000
|
|
push bc
|
|
strxorPadLoop:
|
|
inc hl
|
|
ld (hl), $00
|
|
djnz strxorPadLoop
|
|
pop bc
|
|
strxorPadLoopEnd:
|
|
dec hl
|
|
ld (hl), b
|
|
inc hl
|
|
ld (hl), $00
|
|
pop de
|
|
pop hl
|
|
call strxor
|
|
ret
|
|
|