[OpenBIOS] [PATCHv2 1/6] string.fs: add functions to support ROT13 string encoding/decoding
Mark Cave-Ayland
mark.cave-ayland at ilande.co.uk
Sat Feb 13 17:10:57 CET 2016
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
---
openbios-devel/forth/lib/string.fs | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/openbios-devel/forth/lib/string.fs b/openbios-devel/forth/lib/string.fs
index eb64749..43eca1c 100644
--- a/openbios-devel/forth/lib/string.fs
+++ b/openbios-devel/forth/lib/string.fs
@@ -125,3 +125,22 @@
: parse-hex ( str len -- value )
base @ hex -rot $number if 0 then swap base !
;
+
+
+\ -----------------------------------------------------
+\ miscellaneous functions
+\ -----------------------------------------------------
+
+: rot13 ( c - c )
+ dup upc [char] A [char] M between if d# 13 + exit then
+ dup upc [char] N [char] Z between if d# 13 - then
+;
+
+: $rot13 ( str len -- )
+ bounds ?do i c@ rot13 i c! loop
+;
+
+: rot13-str ( str len -- newstr len )
+ \ Encode copy of input string
+ strdup 2dup $rot13
+;
--
1.7.10.4
More information about the OpenBIOS
mailing list