This commit is contained in:
Stephen Toth 2018-07-11 16:45:33 -04:00
parent 74437f19f9
commit d42c9facf5
17 changed files with 3654 additions and 3015 deletions

View File

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

Binary file not shown.

File diff suppressed because it is too large Load Diff

2
build
View File

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

View File

@ -12,15 +12,30 @@ cryptocmdroute:
cryptocmdmanroute:
pop bc
subroutestrjp(cryptocmdENCRYPT, cryptocmdROT, cryptocmdROTm)
subroutestrjp(cryptocmdDECRYPT, cryptocmdunROT, cryptocmdunROTm)
subroutestrjp(cryptocmdENCRYPT, cryptocmdHELP, cryptocmdHELPm)
subroutestrjp(cryptocmdDECRYPT, cryptocmdHELP, cryptocmdHELPm)
routestrjp(cryptocmdENCRYPT, cryptocmdENCRYPTm)
routeoptjp(cryptocmdDECRYPTo, cryptocmdDECRYPTf)
routestrjp(cryptocmdDECRYPT, cryptocmdDECRYPTm)
push bc
ret
cryptocmdmanrouteu:
pop bc
subrouteustrjp(cryptocmdENCRYPT, cryptocmdROT, cryptocmdROTu)
subrouteustrjp(cryptocmdDECRYPT, cryptocmdunROT, cryptocmdunROTu)
subrouteustrjp(cryptocmdENCRYPT, cryptocmdHELP, cryptocmdHELPu)
subrouteustrjp(cryptocmdDECRYPT, cryptocmdHELP, cryptocmdHELPu)
routeustrjp(cryptocmdENCRYPT, cryptocmdENCRYPTu)
routeustrjp(cryptocmdDECRYPTo, cryptocmdDECRYPTf)
routeustrjp(cryptocmdDECRYPT, cryptocmdDECRYPTu)
push bc
ret

View File

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

View File

@ -20,10 +20,16 @@ cryptocmdDECRYPTfArg0Get:
call inputstr
call _NewLine
cryptocmdDECRYPTfExe:
#macro cryptocmdDECRYPTcmpjp(cmdX, cmdXf)
ld hl, FshCmdArg0
ld de, cryptocmdunROT
ld de, CmdX
call strcmp
jp z, cryptocmdunROTf
jp z, cmdXf
#endmacro
cryptocmdDECRYPTcmpjp(cryptocmdunROT, cryptocmdunROTf)
cryptocmdDECRYPTcmpjp(cryptocmdHELP, cryptocmdHELPf)
ld hl, FshCmdArg0
ld de, FshCmd

View File

@ -1,7 +1,7 @@
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>", 0
cryptocmdENCRYPTu: .db "ENCRYPT <Crypt Command> <Crypt Args>", 0
cryptocmdENCRYPTf:
cryptocmdENCRYPTfArg0:
ld hl, FshCmdArgFlags
@ -20,10 +20,16 @@ cryptocmdENCRYPTfArg0Get:
call inputstr
call _NewLine
cryptocmdENCRYPTfExe:
#macro cryptocmdENCRYPTcmpjp(cmdX, cmdXf)
ld hl, FshCmdArg0
ld de, cryptocmdROT
ld de, CmdX
call strcmp
jp z, cryptocmdROTf
jp z, cmdXf
#endmacro
cryptocmdENCRYPTcmpjp(cryptocmdROT, cryptocmdROTf)
cryptocmdENCRYPTcmpjp(cryptocmdHELP, cryptocmdHELPf)
ld hl, FshCmdArg0
ld de, FshCmd

View File

@ -0,0 +1,68 @@
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)
call _NewLine
jp Fin
cryptocmdHELPfLine1: .db "Available Cryptos:", 0

View File

@ -1,6 +1,6 @@
cryptocmdROT: .db "ROT", 0
cryptocmdROTm: .db "ROT Cypher, rotates the alphabet and encodes a string", 0
cryptocmdROTu: .db "ROT <shift#>", 0
cryptocmdROTm: .db "ROT: Cypher, rotates the alphabet and encodes a string", 0
cryptocmdROTu: .db "ENCRYPT ROT <shift#>", 0
cryptocmdROTf:
cryptocmdROTfArg1:
ld hl, FshCmdArgFlags
@ -23,15 +23,14 @@ cryptocmdROTfArg1Get:
ld (hl), e
call _NewLine
cryptocmdROTfArg2:
jr cryptocmdROTfArg2Get
ld hl, FshCmdArg2
ld de, FshScratch
call strcpy
ld hl, FshCmdArgFlags
bit 5, (hl)
jr z, cryptocmdROTfExe
bit 4, (hl)
jr z, cryptocmdROTfArg2Get
bit 5, (hl)
jr z, cryptocmdROTfExe
ld hl, ErrUsageo
call ErrSet
call ErrCatch

View File

@ -1,6 +1,6 @@
cryptocmdunROT: .db "ROT", 0
cryptocmdunROTm: .db "ROT Cypher, rotates the alphabet and Decodes a string", 0
cryptocmdunROTu: .db "ROT <shift#>", 0
cryptocmdunROTm: .db "ROT: Cypher, rotates the alphabet and Decodes a string", 0
cryptocmdunROTu: .db "DECRYPT ROT <shift#>", 0
cryptocmdunROTf:
cryptocmdunROTfArg1:
ld hl, FshCmdArgFlags
@ -23,15 +23,14 @@ cryptocmdunROTfArg1Get:
ld (hl), e
call _NewLine
cryptocmdunROTfArg2:
jr cryptocmdunROTfArg2Get
ld hl, FshCmdArg2
ld de, FshScratch
call strcpy
ld hl, FshCmdArgFlags
bit 5, (hl)
jr z, cryptocmdunROTfExe
bit 4, (hl)
jr z, cryptocmdunROTfArg2Get
bit 5, (hl)
jr z, cryptocmdunROTfExe
ld hl, ErrUsageo
call ErrSet
call ErrCatch

View File

@ -0,0 +1,52 @@
;;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

View File

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

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,32 @@ strtowExit:
pop bc
ret
;;strxor
;;xor 2 strings together
;;Inputs:
;; HL: string 1
;; DE: string 2
;;Outputs:
;; HL: Xor String Pointer
strxor:
push de
push hl
ex de, hl
strxorLoop:
ld a, (de)
or a, a
jr z, strxorEnd
xor (hl)
ld (de), a
inc de
inc hl
jr strxorLoop
strxorEnd:
pop hl
pop de
ret
;;toLower [Strings]
;;Converts every alpha character of a string to lowercase.
;;Inputs:

View File

@ -1,4 +1,5 @@
#include "includes/lib/std/Math.asm"
#include "includes/lib/std/Random.asm"
#include "includes/lib/std/Byte.asm"
#include "includes/lib/std/Mem.asm"
#include "includes/lib/std/Char.asm"

View File

@ -14,6 +14,21 @@ manroute:
jp z, manrouteReturn
#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 cryptocmdmanroute
;Extention Point
@ -41,6 +56,21 @@ manrouteu:
jp z, manrouteuReturn
#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 cryptocmdmanrouteu
;Extention Point