From a5a57f9386ce54d37c3b7de31db669b0f5236bf0 Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Sat, 17 Oct 2020 17:36:16 +0300 Subject: . --- main.sts | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'main.sts') diff --git a/main.sts b/main.sts index 93a9ed4..c99568c 100644 --- a/main.sts +++ b/main.sts @@ -1,30 +1,37 @@ module ia32/elf/begin.sts module cipher.sts -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 - 31 passwd ! - 32 passwd 1 + ! - 33 passwd 2 + ! + ; read file into stack + 0 do sys_read 0 = until + swap 1 + + od as length + local ciphertext - 0 local bigbadlen - do sys_read 0 = until - over bigbad + ! - 1 + - od + ; -= MAIN LOOP BEGIN =- ; + ; place password ontop of stack + 33 32 31 local password + 3 as passlen - 0 local cipherpos - 0 do dup bigbadlen @ = until - dup bigbad + @ passwd 3 cipherpos cipher - over bigbadres + ! + ; decipher text (length is the same as for ciphertext) + 0 0 do dup length = until + as pos local cipos + pos ciphertext + @ + password + passlen + cipos + cipher + swap pos 1 + od drop drop + local plaintext - 0 do dup bigbadlen @ = until - dup bigbadres + @ sys_write - 1 + od drop drop + ; todo: check deciphering attempt, exit if Ok + ; -= MAIN LOOP END =- ; + + ; output text (todo: and language) + 0 do dup length = until + dup plaintext + @ sys_write + 1 + od sys_exit module ia32/elf/end.sts -- cgit v1.2.3