Merge branch 'crypto' into 'master'

Crypto

See merge request stephentoth/fsh-shell!1
This commit is contained in:
Stephen Toth 2018-07-16 02:29:08 +00:00
commit 9a2845dd12
31 changed files with 5433 additions and 9 deletions

View File

@ -70,6 +70,7 @@ FshFlags: .DB %00000000
#include "includes/lib/std/std.inc" #include "includes/lib/std/std.inc"
#include "includes/lib/fsh/fsh.inc" #include "includes/lib/fsh/fsh.inc"
#include "includes/lib/crypto/crypto.inc"
#include "includes/man-db.asm" #include "includes/man-db.asm"
#include "includes/Command.asm" #include "includes/Command.asm"

View File

@ -25,6 +25,7 @@ Download it from the link and then follow the instructions below for different o
* Linux * Linux
1. Clone, make, and install spasm-ng <https://github.com/alberthdev/spasm-ng> 1. Clone, make, and install spasm-ng <https://github.com/alberthdev/spasm-ng>
2. Run the `build` script 2. Run the `build` script
``` ```
./build ./build
``` ```
@ -43,4 +44,4 @@ Please include:
2. What you were doing when the issue occurred. 2. What you were doing when the issue occurred.
3. Possible cause/fixes? (optional) 3. Possible cause/fixes? (optional)
Thank you! Thank you!

Binary file not shown.

4419
bin/FSHa.lst Normal file

File diff suppressed because it is too large Load Diff

2
build
View File

@ -1,3 +1,3 @@
#!/bin/bash #!/bin/bash
date date
spasm -ETA "FSHa.asm" "bin/FSHa.8xp" spasm -E -T "FSHa.asm" "bin/FSHa.8xp"

View File

@ -1 +1,2 @@
SPASM.exe -ETA "FSHa.asm" "bin\FSHa.8xp" SPASM.exe -E -T "FSHa.asm" "bin\FSHa.8xp"
pause

View File

@ -7,6 +7,7 @@
;; Sets (DE) with command op code ;; Sets (DE) with command op code
commanddecode: commanddecode:
call fshcmddecode call fshcmddecode
call cryptocmddecode
;Extention Point ;Extention Point
ret ret
@ -17,6 +18,7 @@ commanddecode:
;; HL: Op code mem loc ;; HL: Op code mem loc
commandroute: commandroute:
call fshcmdroute call fshcmdroute
call cryptocmdroute
;Extention Point ;Extention Point
ld hl, ErrCmdNotFoundo ld hl, ErrCmdNotFoundo
@ -26,3 +28,4 @@ commandroute:
jp Err jp Err
#include "includes/FshCommands/FshCommand.asm" #include "includes/FshCommands/FshCommand.asm"
#include "includes/CryptoCommands/CryptoCommand.asm"

View File

@ -0,0 +1,48 @@
cryptocmddecode:
decodecmdopt(cryptocmdENCRYPT, cryptocmdENCRYPTo)
decodecmdopt(cryptocmdDECRYPT, cryptocmdDECRYPTo)
ret
cryptocmdroute:
pop bc
routeoptjp(cryptocmdENCRYPTo, cryptocmdENCRYPTf)
routeoptjp(cryptocmdDECRYPTo, cryptocmdDECRYPTf)
push bc
ret
cryptocmdmanroute:
pop bc
subroutestrjp(cryptocmdENCRYPT, cryptocmdROT, cryptocmdROTm)
subroutestrjp(cryptocmdDECRYPT, cryptocmdunROT, cryptocmdunROTm)
subroutestrjp(cryptocmdENCRYPT, cryptocmdXOR, cryptocmdXORm)
subroutestrjp(cryptocmdDECRYPT, cryptocmdunXOR, cryptocmdunXORm)
subroutestrjp(cryptocmdENCRYPT, cryptocmdHELP, cryptocmdHELPm)
subroutestrjp(cryptocmdDECRYPT, cryptocmdunHELP, cryptocmdunHELPm)
routestrjp(cryptocmdENCRYPT, cryptocmdENCRYPTm)
routestrjp(cryptocmdDECRYPT, cryptocmdDECRYPTm)
push bc
ret
cryptocmdmanrouteu:
pop bc
subrouteustrjp(cryptocmdENCRYPT, cryptocmdROT, cryptocmdROTu)
subrouteustrjp(cryptocmdDECRYPT, cryptocmdunROT, cryptocmdunROTu)
subrouteustrjp(cryptocmdENCRYPT, cryptocmdXOR, cryptocmdXORu)
subrouteustrjp(cryptocmdDECRYPT, cryptocmdunXOR, cryptocmdunXORu)
subrouteustrjp(cryptocmdENCRYPT, cryptocmdHELP, cryptocmdHELPu)
subrouteustrjp(cryptocmdDECRYPT, cryptocmdunHELP, cryptocmdunHELPu)
routeustrjp(cryptocmdENCRYPT, cryptocmdENCRYPTu)
routeustrjp(cryptocmdDECRYPT, cryptocmdDECRYPTu)
push bc
ret
#include "includes/CryptoCommands/CryptoCommands.inc"

View File

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

View File

@ -0,0 +1,45 @@
cryptocmdDECRYPT: .db "DECRYPT", 0
cryptocmdDECRYPTo: .db $41
cryptocmdDECRYPTm: .db "Decrypts a string using a cypher. see 'DECRYPT HELP' for info on cyphers", 0
cryptocmdDECRYPTu: .db "DECRYPT <Crypt Command> <Crypt Args>", 0
cryptocmdDECRYPTf:
cryptocmdDECRYPTfArg0:
ld hl, FshCmdArgFlags
bit 0, (hl)
jr z, cryptocmdDECRYPTfArg0Get
bit 1, (hl)
jr z, cryptocmdDECRYPTfExe
ld hl, ErrUsageo
call ErrSet
call ErrCatch
cryptocmdDECRYPTfArg0Get:
ld hl, cryptocmdDECRYPTfSCypher
call printprompt
ld hl, FshCmdArg0
ld de, FshCmdInptSize
call inputstr
call _NewLine
cryptocmdDECRYPTfExe:
#macro cryptocmdDECRYPTcmpjp(cmdX, cmdXf)
ld hl, FshCmdArg0
ld de, CmdX
call strcmp
jp z, cmdXf
#endmacro
cryptocmdDECRYPTcmpjp(cryptocmdunROT, cryptocmdunROTf)
cryptocmdDECRYPTcmpjp(cryptocmdunXOR, cryptocmdunXORf)
cryptocmdDECRYPTcmpjp(cryptocmdunHELP, cryptocmdunHELPf)
ld hl, FshCmdArg0
ld de, FshCmd
call strcpy
ld hl, ErrCmdNotFoundo
ld de, FshCmdErrCode
call bytecpy
call ErrSet
jp Err
cryptocmdDECRYPTfSCypher: .db "Cypher= ", 0

View File

@ -0,0 +1,45 @@
cryptocmdENCRYPT: .db "ENCRYPT", 0
cryptocmdENCRYPTo: .db $40
cryptocmdENCRYPTm: .db "Encrypts a string using a cypher. see 'ENCRYPT HELP' for info on cyphers", 0
cryptocmdENCRYPTu: .db "ENCRYPT <Crypt Command> <Crypt Args>", 0
cryptocmdENCRYPTf:
cryptocmdENCRYPTfArg0:
ld hl, FshCmdArgFlags
bit 0, (hl)
jr z, cryptocmdENCRYPTfArg0Get
bit 1, (hl)
jr z, cryptocmdENCRYPTfExe
ld hl, ErrUsageo
call ErrSet
call ErrCatch
cryptocmdENCRYPTfArg0Get:
ld hl, cryptocmdENCRYPTfSCypher
call printprompt
ld hl, FshCmdArg0
ld de, FshCmdInptSize
call inputstr
call _NewLine
cryptocmdENCRYPTfExe:
#macro cryptocmdENCRYPTcmpjp(cmdX, cmdXf)
ld hl, FshCmdArg0
ld de, CmdX
call strcmp
jp z, cmdXf
#endmacro
cryptocmdENCRYPTcmpjp(cryptocmdROT, cryptocmdROTf)
cryptocmdENCRYPTcmpjp(cryptocmdXOR, cryptocmdXORf)
cryptocmdENCRYPTcmpjp(cryptocmdHELP, cryptocmdHELPf)
ld hl, FshCmdArg0
ld de, FshCmd
call strcpy
ld hl, ErrCmdNotFoundo
ld de, FshCmdErrCode
call bytecpy
call ErrSet
jp Err
cryptocmdENCRYPTfSCypher: .db "Cypher= ", 0

View File

@ -0,0 +1,69 @@
cryptocmdHELP: .db "HELP", 0
cryptocmdHELPm: .db "Help for cyphers", 0
cryptocmdHELPu: .db "ENCRYPT HELP", 0
cryptocmdHELPf:
ld hl, FshCmdArgFlags
bit 2, (hl)
jr z, cryptocmdHELPfExe
ld hl, ErrUsageo
call ErrSet
call ErrCatch
cryptocmdHELPfExe:
ld hl, cryptocmdHELPfLine1
call _PutS
call _NewLine
#macro cryptocmdHELPmRow1(cmdXs)
xor a
ld (curCol), a
ld hl, cmdXs
call _PutS
call _NewLine
#endmacro
#macro cryptocmdHELPmRowU(cmdXs, cmdXu)
xor a
ld (curCol), a
ld hl, cmdXs
call _PutS
ld a, ':'
call _PutC
ld a, ' '
call _PutC
ld hl, cmdXu
call _PutS
call _NewLine
#endmacro
#macro cryptocmdHELPmRow2(cmdXs, cmdYs)
xor a
ld (curCol), a
ld hl, cmdXs
call _PutS
ld a, 9
ld (curcol), a
ld hl, cmdYs
call _PutS
call _NewLine
#endmacro
#macro cryptocmdHELPmRow3(cmdXs, cmdYs, cmdZs)
xor a
ld (curCol), a
ld hl, cmdXs
call _PutS
ld a, 9
ld (curcol), a
ld hl, cmdYs
call _PutS
ld a, 19
ld (curcol), a
ld hl, cmdZs
call _PutS
call _NewLine
#endmacro
cryptocmdHELPmRowU(cryptocmdROT, cryptocmdROTu)
cryptocmdHELPmRowU(cryptocmdXOR, cryptocmdXORu)
call _NewLine
jp Fin
cryptocmdHELPfLine1: .db "Available Cryptos:", 0

View File

@ -0,0 +1,59 @@
cryptocmdROT: .db "ROT", 0
cryptocmdROTm: .db "ROT: Cypher, rotates the alphabet and encodes a string", 0
cryptocmdROTu: .db "ENCRYPT ROT <shift#> <message>", 0
cryptocmdROTf:
cryptocmdROTfArg1:
ld hl, FshCmdArgFlags
bit 3, (hl)
jr nz, cryptocmdROTfArg2
bit 2, (hl)
jr z, cryptocmdROTfArg1Get
ld hl, ErrUsageo
call ErrSet
call ErrCatch
cryptocmdROTfArg1Get:
ld hl, cryptocmdROTfDShift
call printprompt
ld hl, FshCmdArg1
ld de, 3
call inputnumstr
call strtow
ld de, FshCmdArg1
ex de, hl
ld (hl), e
call _NewLine
cryptocmdROTfArg2:
ld hl, FshCmdArg2
ld de, FshScratch
call strcpy
ld hl, FshCmdArgFlags
bit 4, (hl)
jr z, cryptocmdROTfArg2Get
bit 5, (hl)
jr z, cryptocmdROTfExe
ld hl, ErrUsageo
call ErrSet
call ErrCatch
cryptocmdROTfArg2Get:
ld hl, cryptocmdROTfDMessage
call printprompt
ld hl, FshScratch
ld de, FshScratchSize - 4
call inputcharstr
call _NewLine
cryptocmdROTfExe:
ld hl, FshCmdArg1
ld a, (hl)
ld hl, FshScratch
call rotletencrypt
push hl
ld hl, cryptocmdROTfDResult
call _PutS
pop hl
call _PutS
call _NewLine
jp Fin
cryptocmdROTfDShift: .db "Shift= ", 0
cryptocmdROTfDMessage: .db "Message= ", 0
cryptocmdROTfDResult: .db "Result: ", 0

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 - 1 / 2
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,69 @@
cryptocmdunHELP: .db "HELP", 0
cryptocmdunHELPm: .db "Help for cyphers", 0
cryptocmdunHELPu: .db "DECRYPT HELP", 0
cryptocmdunHELPf:
ld hl, FshCmdArgFlags
bit 2, (hl)
jr z, cryptocmdunHELPfExe
ld hl, ErrUsageo
call ErrSet
call ErrCatch
cryptocmdunHELPfExe:
ld hl, cryptocmdunHELPfLine1
call _PutS
call _NewLine
#macro cryptocmdunHELPmRow1(cmdXs)
xor a
ld (curCol), a
ld hl, cmdXs
call _PutS
call _NewLine
#endmacro
#macro cryptocmdunHELPmRowU(cmdXs, cmdXu)
xor a
ld (curCol), a
ld hl, cmdXs
call _PutS
ld a, ':'
call _PutC
ld a, ' '
call _PutC
ld hl, cmdXu
call _PutS
call _NewLine
#endmacro
#macro cryptocmdunHELPmRow2(cmdXs, cmdYs)
xor a
ld (curCol), a
ld hl, cmdXs
call _PutS
ld a, 9
ld (curcol), a
ld hl, cmdYs
call _PutS
call _NewLine
#endmacro
#macro cryptocmdunHELPmRow3(cmdXs, cmdYs, cmdZs)
xor a
ld (curCol), a
ld hl, cmdXs
call _PutS
ld a, 9
ld (curcol), a
ld hl, cmdYs
call _PutS
ld a, 19
ld (curcol), a
ld hl, cmdZs
call _PutS
call _NewLine
#endmacro
cryptocmdunHELPmRowU(cryptocmdunROT, cryptocmdunROTu)
cryptocmdunHELPmRowU(cryptocmdunXOR, cryptocmdunXORu)
call _NewLine
jp Fin
cryptocmdunHELPfLine1: .db "Available Cryptos:", 0

View File

@ -0,0 +1,59 @@
cryptocmdunROT: .db "ROT", 0
cryptocmdunROTm: .db "ROT: Cypher, rotates the alphabet and Decodes a string", 0
cryptocmdunROTu: .db "DECRYPT ROT <shift#>", 0
cryptocmdunROTf:
cryptocmdunROTfArg1:
ld hl, FshCmdArgFlags
bit 3, (hl)
jr nz, cryptocmdunROTfArg2
bit 2, (hl)
jr z, cryptocmdunROTfArg1Get
ld hl, ErrUsageo
call ErrSet
call ErrCatch
cryptocmdunROTfArg1Get:
ld hl, cryptocmdunROTfDShift
call printprompt
ld hl, FshCmdArg1
ld de, 3
call inputnumstr
call strtow
ld de, FshCmdArg1
ex de, hl
ld (hl), e
call _NewLine
cryptocmdunROTfArg2:
ld hl, FshCmdArg2
ld de, FshScratch
call strcpy
ld hl, FshCmdArgFlags
bit 4, (hl)
jr z, cryptocmdunROTfArg2Get
bit 5, (hl)
jr z, cryptocmdunROTfExe
ld hl, ErrUsageo
call ErrSet
call ErrCatch
cryptocmdunROTfArg2Get:
ld hl, cryptocmdunROTfDMessage
call printprompt
ld hl, FshScratch
ld de, FshScratchSize - 4
call inputcharstr
call _NewLine
cryptocmdunROTfExe:
ld hl, FshCmdArg1
ld a, (hl)
ld hl, FshScratch
call rotletdecrypt
push hl
ld hl, cryptocmdunROTfDResult
call _PutS
pop hl
call _PutS
call _NewLine
jp Fin
cryptocmdunROTfDShift: .db "Shift= ", 0
cryptocmdunROTfDMessage: .db "CypherText= ", 0
cryptocmdunROTfDResult: .db "Result: ", 0

View File

@ -0,0 +1,72 @@
cryptocmdunXOR: .db "XOR", 0
cryptocmdunXORm: .db "XOR: Cypher, and decodes a string", 0
cryptocmdunXORu: .db "DECRYPT XOR <key>", 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

@ -52,6 +52,7 @@ fshcmdHELPfExe:
fshcmdHELPmRow3(fshcmdMOVE, fshcmdCLS, fshcmdVAR) fshcmdHELPmRow3(fshcmdMOVE, fshcmdCLS, fshcmdVAR)
fshcmdHELPmRow3(fshcmdVARS, fshcmdSLEEP, fshcmdINFO) fshcmdHELPmRow3(fshcmdVARS, fshcmdSLEEP, fshcmdINFO)
fshcmdHELPmRow2(fshcmdHELP, fshcmdMAN) fshcmdHELPmRow2(fshcmdHELP, fshcmdMAN)
fshcmdHELPmRow2(cryptocmdENCRYPT, cryptocmdDECRYPT)
; Extention Point ; Extention Point
call _NewLine call _NewLine

View File

@ -7,7 +7,7 @@ FshVVars: .db "64w", 0
FshVMajor: .db "0", 0 FshVMajor: .db "0", 0
FshVMinor: .db "1", 0 FshVMinor: .db "1", 0
FshVPatch: .db "0", 0 FshVPatch: .db "0", 0
FshVBuild: .db "205", 0 FshVBuild: .db "490", 0
FshVSeparator: .db ".", 0 FshVSeparator: .db ".", 0
FshMotd2nd: .db "Press 2nd for numbers", 0 FshMotd2nd: .db "Press 2nd for numbers", 0
FshMotdHelp: .db "Type 'HELP' for help", 0 FshMotdHelp: .db "Type 'HELP' for help", 0

146
includes/lib/crypto/Rot.asm Normal file
View File

@ -0,0 +1,146 @@
;;rotletencrypt
;;Encrypts a string in rot-n (uses $41 to $5B)
;;Inputs:
;; HL: string pointer
;; A: rot-n
;;Notes:
;; Changes string in place.
rotletencrypt:
push hl
push bc
rotletencryptMod:
push hl
ld h, a
ld l, 'Z' + 1 - 'A' - 1
call modHL
ld b, h
pop hl
rotletencryptLoop:
ld a, (hl)
cp a, $00
jr z, rotletencryptEnd
cp a, ' '
jr z, rotletencryptLD
add a, b
cp a, 'Z' + 2
jr c , rotletencryptLD
sub a, 'Z' + 2 - 'A'
rotletencryptLD:
ld (hl), a
inc hl
jr rotletencryptLoop
rotletencryptEnd:
ld (hl), $00
pop bc
pop hl
ret
;;rotletdecrypt
;;Decrypts a string in rot-n (uses $41 to $5B)
;;Inputs:
;; HL: string pointer
;; A: rot-n
;;Notes:
;; Changes string in place.
rotletdecrypt:
push hl
push bc
rotletdecryptMod:
push hl
ld h, a
ld l, 'Z' + 1 - 'A' - 1
call modHL
ld b, h
pop hl
rotletdecryptLoop:
ld a, (hl)
cp a, $00
jr z, rotletdecryptEnd
cp a, ' '
jr z, rotletdecryptLD
sub a, b
cp a, 'A'
jr nc , rotletdecryptLD
add a, 'Z' + 2 - 'A'
rotletdecryptLD:
ld (hl), a
inc hl
jr rotletdecryptLoop
rotletdecryptEnd:
ld (hl), $00
pop bc
pop hl
ret
;;rotasciiencrypt
;;Encrypts a string in rot-x (uses $00 to $EF)
;;Inputs:
;; HL: string pointer
;; A: x
;;Notes:
;; Changes string in place.
rotasciiencrypt:
push hl
push bc
ld c, 0
ld c, a
rotasciiencryptLoop:
ld a, (hl)
cp 0
jr z, rotasciiencryptEnd
add a, c
cp 0
jr nz, rotasciiencryptLd
inc a
rotasciiencryptLd:
ld (hl), a
inc hl
cp a, $EF
jr c, rotasciiencryptLoop
dec hl
sub a, $0F
ld (hl), a
inc hl
jr rotasciiencryptLoop
rotasciiencryptEnd:
ld (hl), $00
pop bc
pop hl
ret
;;rotasciidecrypt
;;Encrypts a string in rot-x (uses $00 to $EF)
;;Inputs:
;; HL: string pointer
;; A: x
;;Notes:
;; Changes string in place.
rotasciidecrypt:
push hl
push bc
ld c, 0
ld c, a
rotasciidecryptLoop:
ld a, (hl)
cp 0
jr z, rotasciidecryptEnd
sub a, c
cp 0
jr nz, rotasciidecryptLd
dec a
rotasciidecryptLd:
ld (hl), a
inc hl
cp a, $EF
jr c, rotasciidecryptLoop
dec hl
add a, $0F
ld (hl), a
inc hl
jr rotasciidecryptLoop
rotasciidecryptEnd:
ld (hl), $00
pop bc
pop hl
ret

View File

@ -0,0 +1,91 @@
;;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
push bc
call strlen
push de
push hl
ld hl, 0
ld h, b
ld l, c
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), 'e'
djnz xorcryptPadLoop
xorcryptPadLoopEnd:
pop bc
ld (hl), b
inc hl
ld (hl), $00
xorcryptEnd:
pop bc
pop de
pop hl
;push hl
;xorcryptRandLoop:
;ld a, (hl)
;or a, a
;jr z, xorcryptRandLoopEnd
;call randomint
;or a, a
;jr nz, xorcryptRandLoopLD
;ld a, '/'
;xorcryptRandLoopLD:
;ld (hl), a
;inc hl
;jr xorcryptRandLoop
;xorcryptRandLoopEnd:
;pop hl
call strxor
ret

View File

@ -0,0 +1,2 @@
#include "includes/lib/crypto/Rot.asm"
#include "includes/lib/crypto/Xor.asm"

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

@ -181,14 +181,14 @@ inputstrCurRowBuf: .db $00
inputcharstr: inputcharstr:
push de push de
push hl push hl
ld (inputstrSizeBuf), de ld (inputcharstrSizeBuf), de
push hl push hl
push de push de
ld hl, CurCol ld hl, CurCol
ld de, inputstrCurColBuf ld de, inputcharstrCurColBuf
call bytecpy call bytecpy
ld hl, CurRow ld hl, CurRow
ld de, inputstrCurRowBuf ld de, inputcharstrCurRowBuf
call bytecpy call bytecpy
pop de pop de
pop hl pop hl

View File

@ -71,7 +71,28 @@ mulAbyHLEnd:
pop bc pop bc
ret ret
;;modHL
;;H % L => H
;;Inputs:
;; H:
;; L:
modHL:
push bc
ld b, h
ld a, 0
modHLLoop:
inc a
cp a, l
jr nz, modHLLoopEnd
ld a, 0
modHLLoopEnd:
djnz modHLLoop
ld h, a
pop bc
ret
;;mul32By8 ;;mul32By8
;;Performs an unsigned multiplication of DEHL and A. ;;Performs an unsigned multiplication of DEHL and A.
;;Outputs: ;;Outputs:

View File

@ -0,0 +1,44 @@
;;randomint
;;Gets an 8-bit random number.
;;Inputs:
;; A: Seed
;;Outputs:
;; A: Random number (0-255)
;;Notes:
;; This is not cryptographically random.
randomint:
ld (randomintSeed), a
push hl
push de
push bc
ld hl, (randomintSeed)
ld de, (randomintSeed+2)
ld b, h
ld c, l
add hl, hl \ rl e \ rl d
add hl, hl \ rl e \ rl d
inc l
add hl, bc
ld (randomintSeed), hl
ld hl, (randomintSeed+2)
adc hl, de
ld (randomintSeed+3), hl
ex de, hl
ld hl, (randomintSeed)
ld de, (randomintSeed+4)
ld bc, 63838
add hl, hl \ rl c \ rl b
ld (randomintSeed+6), bc
sbc a, a
and %11110001
xor l
ld l, a
ld (randomintSeed+7), hl
ld a, d
add a, b
pop bc
pop de
pop hl
ret
;Actual random bytes
randomintSeed: .db $28, $BE, $B3, $BB, $a3, $f1, $97, $af, $87, $50, $26, $91, $46, $cc, $5f, $c7

View File

@ -258,6 +258,36 @@ strtowExit:
pop bc pop bc
ret ret
;;strxor
;;xor 2 strings together
;;Inputs:
;; HL: string 1
;; DE: string 2
;;Outputs:
;; HL: Xor String Pointer
strxor:
push hl
push de
ex de, hl
strxorLoop:
ld a, (de)
or a, a
jr z, strxorEnd
xor (hl)
or a, a
jr nz, strxorLoopLD
ld a, (hl)
strxorLoopLD:
ld (de), a
inc de
inc hl
jr strxorLoop
strxorEnd:
pop de
pop hl
ret
;;toLower [Strings] ;;toLower [Strings]
;;Converts every alpha character of a string to lowercase. ;;Converts every alpha character of a string to lowercase.
;;Inputs: ;;Inputs:

View File

@ -1,4 +1,5 @@
#include "includes/lib/std/Math.asm" #include "includes/lib/std/Math.asm"
#include "includes/lib/std/Random.asm"
#include "includes/lib/std/Byte.asm" #include "includes/lib/std/Byte.asm"
#include "includes/lib/std/Mem.asm" #include "includes/lib/std/Mem.asm"
#include "includes/lib/std/Char.asm" #include "includes/lib/std/Char.asm"
@ -6,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

@ -14,7 +14,23 @@ manroute:
jp z, manrouteReturn jp z, manrouteReturn
#endmacro #endmacro
#macro subroutestrjp(cmdXs, cmdYs, cmdYm)
push hl
ld de, cmdXs
call strcmp
ld hl, 0
jr nz, +_
ld hl, FshCmdArg1
_:
ld de, cmdYs
call strcmp
pop hl
ld de, cmdYm
jp z, manrouteReturn
#endmacro
call fshcmdmanroute call fshcmdmanroute
call cryptocmdmanroute
;Extention Point ;Extention Point
ld hl, FshCmdErrCode ld hl, FshCmdErrCode
@ -40,7 +56,23 @@ manrouteu:
jp z, manrouteuReturn jp z, manrouteuReturn
#endmacro #endmacro
#macro subrouteustrjp(cmdXs, cmdYs, cmdYu)
push hl
ld de, cmdXs
call strcmp
ld hl, 0
jr nz, +_
ld hl, FshCmdArg1
_:
ld de, cmdYs
call strcmp
pop hl
ld de, cmdYu
jp z, manrouteuReturn
#endmacro
call fshcmdmanrouteu call fshcmdmanrouteu
call cryptocmdmanrouteu
;Extention Point ;Extention Point
ld hl, FshCmdErrCode ld hl, FshCmdErrCode

View File

@ -1,5 +1,4 @@
.nolist .nolist
; Included for Assembler Compatibility ; Included for Assembler Compatibility
;------------------------------------ ;------------------------------------
#define equ .equ #define equ .equ
@ -11,6 +10,7 @@
#define FshCmdSize 64 ;64 bytes | 44 chars , 5 qwords (CMD + args) , + 4 0's| 1 byte null | 2 byte optcode | 1 byte arg flags |1 byte (err code) | 6 unused #define FshCmdSize 64 ;64 bytes | 44 chars , 5 qwords (CMD + args) , + 4 0's| 1 byte null | 2 byte optcode | 1 byte arg flags |1 byte (err code) | 6 unused
#define FshCmdInptSize 44 #define FshCmdInptSize 44
#define FshCmdCmdSize 8 #define FshCmdCmdSize 8
#define FshScratchSize FshCmdSize - FshCmdInptSize
#define FshPrgmSize 1024 #define FshPrgmSize 1024
RamVars equ 0D0EA1Fh ;saveSScreen | 21945 bytes RamVars equ 0D0EA1Fh ;saveSScreen | 21945 bytes
@ -26,3 +26,7 @@ FshCmdArg2 equ FshCmdArg1 + 9
FshCmdArg3 equ FshCmdArg2 + 9 FshCmdArg3 equ FshCmdArg2 + 9
FshCmdArgFlags equ FshCmdArg3 + 10 FshCmdArgFlags equ FshCmdArg3 + 10
FshCmdErrCode equ FshCmdArgFlags + 1 FshCmdErrCode equ FshCmdArgFlags + 1
FshScratch equ FshCmdErrCode + 1
.list

View File

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