aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--cipher.sts24
-rw-r--r--encrypt.sts21
-rw-r--r--ia32/macro.sts20
-rw-r--r--ia32/math.sts16
-rw-r--r--main.sts27
6 files changed, 68 insertions, 42 deletions
diff --git a/Makefile b/Makefile
index 56947b1..a242d89 100644
--- a/Makefile
+++ b/Makefile
@@ -20,4 +20,4 @@ strans: strans.c
gcc $< -o $@
clean:
- rm -f smack strans cryptrobber encrypt
+ rm -f smack strans cryptrobber encrypt test
diff --git a/cipher.sts b/cipher.sts
index 72d941e..d351397 100644
--- a/cipher.sts
+++ b/cipher.sts
@@ -1,18 +1,10 @@
-; cipher is password string (pointer to start and length) and position in it
-
-defword ciphernew
- 0
-exit
-
-defword mod
- swap / drop
-exit
-
-defword cipher ; ... passwd plen ppos key
- 3 get 2 get + @ xor ; key = key ^ passwd[ppos]
- over 1 + 3 get mod 2 set ; ppos = (ppos + 1) % plen
-exit
-
-defword cipherdel
+defword cipher
+ 3 ref as byte
+ 2 get as password
+ 1 get as plen
+ 0 get as pos
+ pos @ password + @ byte @ xor byte !
+ pos @ 1 + pos !
+ pos @ plen = if 0 pos ! fi
drop drop drop
exit
diff --git a/encrypt.sts b/encrypt.sts
index 29424a2..a472e57 100644
--- a/encrypt.sts
+++ b/encrypt.sts
@@ -1,29 +1,20 @@
module ia32/elf/begin.sts
module cipher.sts
-defword encbyte
- sys_read dup if
- drop
- cipher sys_write
- 1 1
- fi 0 = if
- drop 0
- fi
-exit
+defarr passwd 3
defword encrypt
- encbyte if encrypt fi
+ top as pos
+ do sys_read 0 = until
+ passwd 3 pos cipher sys_write
+ od drop
exit
-defarr passwd 3
-
set_entry
31 passwd !
32 passwd 1 + !
33 passwd 2 + !
- passwd 3 ciphernew
- encrypt
- cipherdel
+ 0 encrypt drop
sys_exit
module ia32/elf/end.sts
diff --git a/ia32/macro.sts b/ia32/macro.sts
index 5aa3b35..34c3a9d 100644
--- a/ia32/macro.sts
+++ b/ia32/macro.sts
@@ -40,13 +40,21 @@
[ as 1
_data_segment ?choose
- defword %1%
- lit ?$ # 0 ?.
- exit
+ defword %1%
+ lit ?$ # 0 ?.
+ exit
_code_segment ?choose
lit ?. !
]
+[ local 1
+ top as %1%
+]
+
+[ ref 0
+ top + 1 +
+]
+
[ literal 0
lit # %1% ?.
]
@@ -84,3 +92,9 @@
branch ?swap ?.
?$ ?swap ?!
]
+
+[ change 0
+ dup get
+ swap 2 get swap 2 + set
+ swap drop
+]
diff --git a/ia32/math.sts b/ia32/math.sts
index 1864a93..95ca5f7 100644
--- a/ia32/math.sts
+++ b/ia32/math.sts
@@ -17,6 +17,22 @@ defasm /
# 50 ?' ; push eax
next
+defasm mod
+ # 5b ?' ; pop ebx
+ # 58 ?' ; pop eax
+ # 31 ?' # d2 ?' ; xor edx, edx
+ # f7 ?' # f3 ?' ; div ebx
+ # 52 ?' ; push edx
+next
+
+defasm div
+ # 5b ?' ; pop ebx
+ # 58 ?' ; pop eax
+ # 31 ?' # d2 ?' ; xor edx, edx
+ # f7 ?' # f3 ?' ; div ebx
+ # 50 ?' ; push eax
+next
+
defasm =
# 5b ?' ; pop ebx
# 58 ?' ; pop eax
diff --git a/main.sts b/main.sts
index bf0c267..93a9ed4 100644
--- a/main.sts
+++ b/main.sts
@@ -1,17 +1,30 @@
module ia32/elf/begin.sts
+module cipher.sts
-defarr bigbad 65536 ; max size of input is 64KB
+defarr bigbad 64000 ; max size of input is 64 000 chars
+defarr bigbadres 64000 ; max size of output is 64 000 chars
+defarr passwd 3
-set_entry ; reversed echo
- 0 ; bigbad index
+set_entry
+ 31 passwd !
+ 32 passwd 1 + !
+ 33 passwd 2 + !
+
+ 0 local bigbadlen
do sys_read 0 = until
over bigbad + !
1 +
- od ; bigbad length will be on top of stack
+ od
+
+ 0 local cipherpos
+ 0 do dup bigbadlen @ = until
+ dup bigbad + @ passwd 3 cipherpos cipher
+ over bigbadres + !
+ 1 + od drop drop
- do
- 1 - dup bigbad + @ sys_write
- dup 0 = untilod drop
+ 0 do dup bigbadlen @ = until
+ dup bigbadres + @ sys_write
+ 1 + od drop drop
sys_exit
module ia32/elf/end.sts