~aleteoryx/uxn

a5d56a84a4e22a94a4971c6a07e3949b47d449db — Aleteoryx 5 days ago a2be187 front
rot13 cipher
2 files changed, 52 insertions(+), 1 deletions(-)

M mkfile
A rot.tal
M mkfile => mkfile +2 -1
@@ 3,7 3,8 @@ roms=\
	nanpa.rom\
	bfc.rom\
	lzw.rom\
	grep.rom
	grep.rom\
	rot.rom

all:VQ: $roms


A rot.tal => rot.tal +50 -0
@@ 0,0 1,50 @@
( usage: uxncli rot.rom [ k ] <message.txt
  by waso amisi )

@on-reset ( -> )
	;on-arg ;on-stdin
	#17 DEI ?{ SWP2 } POP2
	#10 DEO2
	BRK

@on-arg ( -> )
	#17 DEI
	#02 NEQk ?{ POP2 !/one-digit }
	INC EQUk ?usage

	( argend )
	,/offset LDR ;try-rot/offset STA
	;on-stdin #10 DEO2
	BRK
@on-arg/one-digit ( -> )
	#d012 DEI ADD DUP	( subtract "0 )
	#09 GTH ?usage
	[ LIT2 &offset 00 0a ]
	MUL ADD ,/offset STR
	BRK
	
@usage ( -- )
	;/str
	&puts
		LDAk #18 DEO
		INC2 LDAk ?/puts
	#800f DEO BRK
@usage/str "usage: 20 "uxncli 20 "rot.rom 20 "[ 20 "k 20 "] 20 "<message.txt 0a 00

@on-stdin ( -> )
	#12 DEI
	LIT "A try-rot
	LIT "a try-rot
	#18 DEO
	BRK

@try-rot ( c n -- c )
	SUBk #1a			( c n c-n 1a )
	LTHk ?{ POP2 POP JMP2r }
	[ LIT &offset 0d ]
	ROT ADD SWP			( c n rot 1a )
	DIVk MUL SUB			( mod )
	ADD
	#18 DEO
	POP2 BRK