Added Xor cypher, added decode

This commit is contained in:
Stephen Toth 2018-07-13 10:14:41 -04:00
parent d42c9facf5
commit fec671d114
14 changed files with 3940 additions and 3328 deletions

View File

@ -18,11 +18,6 @@ Setup:
CALL fshvarreset CALL fshvarreset
CALL printmotd CALL printmotd
ld hl, teststr
ld de, testkey
call xorcrypt
call _PutS
Input: Input:
;; TODO: Update status bar sometimes ;; TODO: Update status bar sometimes
@ -30,7 +25,7 @@ Input:
CALL commandfill CALL commandfill
LD HL, PS1 LD HL, PS1
;CALL printprompt CALL printprompt
LD HL, FshCmd LD HL, FshCmd
LD DE, FshCmdInptSize LD DE, FshCmdInptSize
@ -80,7 +75,4 @@ FshFlags: .DB %00000000
#include "includes/man-db.asm" #include "includes/man-db.asm"
#include "includes/Command.asm" #include "includes/Command.asm"
teststr: .db "BADww", 0
testkey: .db "OT", 0
.end .end

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,9 @@ cryptocmdmanroute:
subroutestrjp(cryptocmdENCRYPT, cryptocmdROT, cryptocmdROTm) subroutestrjp(cryptocmdENCRYPT, cryptocmdROT, cryptocmdROTm)
subroutestrjp(cryptocmdDECRYPT, cryptocmdunROT, cryptocmdunROTm) subroutestrjp(cryptocmdDECRYPT, cryptocmdunROT, cryptocmdunROTm)
subroutestrjp(cryptocmdENCRYPT, cryptocmdXOR, cryptocmdXORm)
subroutestrjp(cryptocmdDECRYPT, cryptocmdunXOR, cryptocmdunXORm)
subroutestrjp(cryptocmdENCRYPT, cryptocmdHELP, cryptocmdHELPm) subroutestrjp(cryptocmdENCRYPT, cryptocmdHELP, cryptocmdHELPm)
subroutestrjp(cryptocmdDECRYPT, cryptocmdHELP, cryptocmdHELPm) subroutestrjp(cryptocmdDECRYPT, cryptocmdHELP, cryptocmdHELPm)
@ -29,6 +32,9 @@ cryptocmdmanrouteu:
pop bc pop bc
subrouteustrjp(cryptocmdENCRYPT, cryptocmdROT, cryptocmdROTu) subrouteustrjp(cryptocmdENCRYPT, cryptocmdROT, cryptocmdROTu)
subrouteustrjp(cryptocmdDECRYPT, cryptocmdunROT, cryptocmdunROTu) subrouteustrjp(cryptocmdDECRYPT, cryptocmdunROT, cryptocmdunROTu)
subrouteustrjp(cryptocmdENCRYPT, cryptocmdXOR, cryptocmdXORu)
subrouteustrjp(cryptocmdDECRYPT, cryptocmdunXOR, cryptocmdunXORu)
subrouteustrjp(cryptocmdENCRYPT, cryptocmdHELP, cryptocmdHELPu) subrouteustrjp(cryptocmdENCRYPT, cryptocmdHELP, cryptocmdHELPu)
subrouteustrjp(cryptocmdDECRYPT, cryptocmdHELP, cryptocmdHELPu) subrouteustrjp(cryptocmdDECRYPT, cryptocmdHELP, cryptocmdHELPu)

View File

@ -1,7 +1,9 @@
#include "includes/CryptoCommands/ENCRYPT.asm" #include "includes/CryptoCommands/ENCRYPT.asm"
#include "includes/CryptoCommands/ROT.asm" #include "includes/CryptoCommands/ROT.asm"
#include "includes/CryptoCommands/XOR.asm"
#include "includes/CryptoCommands/HELP.asm" #include "includes/CryptoCommands/HELP.asm"
#include "includes/CryptoCommands/DECRYPT.asm" #include "includes/CryptoCommands/DECRYPT.asm"
#include "includes/CryptoCommands/unROT.asm" #include "includes/CryptoCommands/unROT.asm"
#include "includes/CryptoCommands/unXOR.asm"

View File

@ -29,6 +29,7 @@ cryptocmdDECRYPTfExe:
#endmacro #endmacro
cryptocmdDECRYPTcmpjp(cryptocmdunROT, cryptocmdunROTf) cryptocmdDECRYPTcmpjp(cryptocmdunROT, cryptocmdunROTf)
cryptocmdDECRYPTcmpjp(cryptocmdunXOR, cryptocmdunXORf)
cryptocmdDECRYPTcmpjp(cryptocmdHELP, cryptocmdHELPf) cryptocmdDECRYPTcmpjp(cryptocmdHELP, cryptocmdHELPf)
ld hl, FshCmdArg0 ld hl, FshCmdArg0

View File

@ -29,6 +29,7 @@ cryptocmdENCRYPTfExe:
#endmacro #endmacro
cryptocmdENCRYPTcmpjp(cryptocmdROT, cryptocmdROTf) cryptocmdENCRYPTcmpjp(cryptocmdROT, cryptocmdROTf)
cryptocmdENCRYPTcmpjp(cryptocmdXOR, cryptocmdXORf)
cryptocmdENCRYPTcmpjp(cryptocmdHELP, cryptocmdHELPf) cryptocmdENCRYPTcmpjp(cryptocmdHELP, cryptocmdHELPf)
ld hl, FshCmdArg0 ld hl, FshCmdArg0

View File

@ -0,0 +1,67 @@
cryptocmdXOR: .db "XOR", 0
cryptocmdXORm: .db "XOR: Cypher, and encodes a string", 0
cryptocmdXORu: .db "ENCRYPT XOR <Key> <Message>", 0
cryptocmdXORf:
cryptocmdXORfArg1:
ld hl, FshCmdArgFlags
bit 2, (hl)
jr z, cryptocmdXORfArg1Get
bit 3, (hl)
jr z, cryptocmdXORfArg2
ld hl, ErrUsageo
call ErrSet
call ErrCatch
cryptocmdXORfArg1Get:
ld hl, cryptocmdXORfDKey
call printprompt
ld hl, FshCmdArg1
ld de, FshCmdCmdSize
call inputstr
call _NewLine
cryptocmdXORfArg2:
ld hl, FshCmdArg2
ld de, FshScratch
call strcpy
ld hl, FshCmdArgFlags
bit 4, (hl)
jr z, cryptocmdXORfArg2Get
bit 5, (hl)
jr z, cryptocmdXORfExe
ld hl, ErrUsageo
call ErrSet
call ErrCatch
cryptocmdXORfArg2Get:
ld hl, cryptocmdXORfDMessage
call printprompt
ld hl, FshScratch
ld de, FshScratchSize - 4
call inputcharstr
call _NewLine
cryptocmdXORfExe:
ld hl, FshScratch
ld de, FshCmdArg1
call xorcrypt
ld hl, cryptocmdXORfDResult
call _PutS
ld hl, FshScratch
cryptocmdXORfPrint:
ld a, (hl)
or a, a
jr z, cryptocmdXORfPrintEnd
push hl
call bytetohexstr
ld a, (hl)
call _PutC
inc hl
ld a, (hl)
call _PutC
pop hl
inc hl
jr cryptocmdXORfPrint
cryptocmdXORfPrintEnd:
call _NewLine
jp Fin
cryptocmdXORfDKey: .db "Key= ", 0
cryptocmdXORfDMessage: .db "Message= ", 0
cryptocmdXORfDResult: .db "Result: ", 0

View File

@ -0,0 +1,73 @@
cryptocmdunXOR: .db "XOR", 0
cryptocmdunXORm: .db "XOR: Cypher, and decodes a string", 0
cryptocmdunXORu: .db "DECRYPT XOR", 0
cryptocmdunXORf:
cryptocmdunXORfArg1:
ld hl, FshCmdArgFlags
bit 2, (hl)
jr z, cryptocmdunXORfArg1Get
bit 3, (hl)
jr z, cryptocmdunXORfArg2
ld hl, ErrUsageo
call ErrSet
call ErrCatch
cryptocmdunXORfArg1Get:
ld hl, cryptocmdunXORfDKey
call printprompt
ld hl, FshCmdArg1
ld de, FshCmdCmdSize
call inputstr
call _NewLine
cryptocmdunXORfArg2:
ld hl, FshCmdArg2
ld de, FshScratch
call strcpy
ld hl, FshCmdArgFlags
bit 4, (hl)
jr nz, cryptocmdunXORfExe
cryptocmdunXORfArg2Get:
ld hl, cryptocmdunXORfStringPBuffer
ld b, $0F
ld a, $00
call memset
ld hl, cryptocmdunXORfDMessage
call printprompt
ld hl, FshScratch
ld de, FshScratchSize - 4
call inputstr
ld bc, cryptocmdunXORfStringPBuffer
cryptocmdunXORfArg2GetLoop:
ld a, (hl)
or a, a
jr z, cryptocmdunXORfArg2GetLoopEnd
ld (cryptocmdunXORfStringBuffer), a
inc hl
ld a, (hl)
ld (cryptocmdunXORfStringBuffer + 1), a
push hl
ld hl, cryptocmdunXORfStringBuffer
call hexToA
pop hl
ld (bc), a
inc hl
inc bc
jr cryptocmdunXORfArg2GetLoop
cryptocmdunXORfArg2GetLoopEnd:
call _NewLine
cryptocmdunXORfExe:
ld hl, cryptocmdunXORfStringPBuffer
ld de, FshCmdArg1
call xorcrypt
ld hl, cryptocmdunXORfDResult
call _PutS
ld hl, cryptocmdunXORfStringPBuffer
call _PutS
call _NewLine
jp Fin
cryptocmdunXORfDKey: .db "Key= ", 0
cryptocmdunXORfDMessage: .db "CypherText= ", 0
cryptocmdunXORfDResult: .db "Result: ", 0
cryptocmdunXORfStringBuffer: .db $00, $00, $00, $00
cryptocmdunXORfStringPBuffer: .db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00

View File

@ -8,45 +8,80 @@
xorcrypt: xorcrypt:
push hl push hl
push de 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 push bc
ld c, 0 call strlen
add hl, bc push de
pop bc push hl
inc b ld hl, 0
ld (hl), %10000000 ld h, b
push bc ld l, c
strxorPadLoop: ex de, hl
call strlen
ex de, hl
ld a, l ;C = len(seed) l=len(string)
sub a,c
jp nc, xorcryptNSmaller
ld c, $01
ld a, 0
ld l, 0
xorcryptNSmaller:
dec c
jp nc, xorcryptNSmaller2
ld c, 0
xorcryptNSmaller2:
ld b, c
ld c, l ;b=len(seed) c=len(string)
pop hl
or a, a
pop de
jr z, xorcryptEnd
push de
ex de, hl; hl=seed
pop hl
push bc
push de
ld de, 0
ld e, b
ld bc, 0
ld c, e
add hl, bc
pop de
pop bc
inc hl
ld (hl), %10000000
push bc
dec b
ld a, $FF
cp a, b
jr z, xorcryptPadLoopEnd
ld a, $00
cp a, b
jr nz, xorcryptPadLoop
inc b
xorcryptPadLoop:
inc hl
ld (hl), $11
djnz xorcryptPadLoop
xorcryptPadLoopEnd:
pop bc
ld (hl), b
inc hl inc hl
ld (hl), $00 ld (hl), $00
djnz strxorPadLoop xorcryptEnd:
pop bc pop bc
strxorPadLoopEnd:
dec hl
ld (hl), b
inc hl
ld (hl), $00
pop de pop de
pop hl pop hl
;push hl
;xorcryptRandLoop:
;ld a, (hl)
;or a, a
;jr z, xorcryptRandLoopEnd
;call randomint
;ld (hl), a
;inc hl
;jr xorcryptRandLoop
;xorcryptRandLoopEnd:
;pop hl
call strxor call strxor
ret ret

83
includes/lib/std/Hex.asm Normal file
View File

@ -0,0 +1,83 @@
;;bytetohexstr
;;converts byte to hex string
;;Inputs:
;; A: input byte
;;Outputs:
;; hl: output string location
bytetohexstr:
push hl
push bc
ld bc, 0
ld c, a
ld b, $0F
and a, b
ld b, a
ld a, c
ld c, b
ld b, 0
ld hl, hexLUT
add hl, bc
ld b, (hl)
ld hl, bytetohexstrBuf + 1
ld (hl), b
pop bc
push bc
ld bc, 0
srl a
srl a
srl a
srl a
ld b, a
ld a, c
ld c, b
ld b, 0
ld hl, hexLUT
add hl, bc
ld b, (hl)
ld hl, bytetohexstrBuf
ld (hl), b
pop bc
ld hl, bytetohexstrBuf + 2
ld (hl), $00
pop hl
ld hl, bytetohexstrBuf
ret
bytetohexstrBuf: .db $00, $00, $00, $00
#include "includes/tables/hexLUT.asm"
;;hexToA
;;Converts a hexadecimal string to a number.
;;Inputs:
;; HL: String pointer
;;Outputs:
;; A: Value
hexToA:
push bc
push hl
ld b, 0
_: ld a, (hl)
or a
jr z, hexToA_ret
rl b \ rl b \ rl b \ rl b
call hexToA_doConvert
or b
ld b, a
inc hl
jr -_
hexToA_ret:
ld a, b
pop hl
pop bc
ret
hexToA_doConvert:
cp 'a' ; Convert to lowercase
jr c, _
sub 'a' - 'A'
_: cp 'A' ; Close gap between numbers and letter
jr c, _
sub 'A'-('9'+1)
_: sub '0' ; To number
ret

View File

@ -266,9 +266,9 @@ strtowExit:
;;Outputs: ;;Outputs:
;; HL: Xor String Pointer ;; HL: Xor String Pointer
strxor: strxor:
push de push hl
push hl push de
ex de, hl ex de, hl
strxorLoop: strxorLoop:
ld a, (de) ld a, (de)
or a, a or a, a
@ -279,8 +279,8 @@ strxorLoop:
inc hl inc hl
jr strxorLoop jr strxorLoop
strxorEnd: strxorEnd:
pop hl pop de
pop de pop hl
ret ret

View File

@ -7,6 +7,7 @@
#include "includes/lib/std/Print.asm" #include "includes/lib/std/Print.asm"
#include "includes/lib/std/Draw.asm" #include "includes/lib/std/Draw.asm"
#include "includes/lib/std/Array.asm" #include "includes/lib/std/Array.asm"
#include "includes/lib/std/Hex.asm"
#include "includes/lib/std/String.asm" #include "includes/lib/std/String.asm"

View File

@ -0,0 +1 @@
hexLUT: .db "0123456789ABCDEF", 0