[OpenBIOS] [PATCH 2/7] string.fs: add functions to support ROT13 string encoding/decoding

Mark Cave-Ayland mark.cave-ayland at ilande.co.uk
Fri Feb 5 19:09:01 CET 2016


Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
---
 openbios-devel/forth/lib/string.fs |   28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/openbios-devel/forth/lib/string.fs b/openbios-devel/forth/lib/string.fs
index eb64749..97b109c 100644
--- a/openbios-devel/forth/lib/string.fs
+++ b/openbios-devel/forth/lib/string.fs
@@ -125,3 +125,31 @@
 : parse-hex ( str len -- value )
   base @ hex -rot $number if 0 then swap base !
 ;
+
+
+\ -----------------------------------------------------
+\ miscellaneous functions
+\ -----------------------------------------------------
+
+: rot13-c! ( c-addr -- )
+  \ ROT13 the char at the given address
+  dup c@    \ ( c-addr char )
+  dup h# 41 >= over h# 5a <= and if    \ A-Z
+    h# 41 - h# 0d + h# 1a mod h# 41 + swap c!
+  else
+    dup h# 61 >= over h# 7a <= and if    \ a-z
+      h# 61 - h# 0d + h# 1a mod h# 61 + swap c!
+    else
+      2drop
+    then
+  then
+;
+
+: rot13-str ( str len -- newstr len )
+  \ Return a copy of the string encoded ROT13
+  strdup 0 begin
+    2 pick over chars + rot13-c!
+    1+ 2dup = 
+  until
+  drop
+;
-- 
1.7.10.4




More information about the OpenBIOS mailing list