L1VM - CipherSaber

I did write a CipherSaber version 2 encrypt/decrypt library. CipherSaber is a simple encryption algorithm, which can be implemented easy in any language. Here is the L1VM Brackets demo included in my GitHub L1VM repo: (lib/ciphersaber-lib.l1com)

// ciphersaber-lib.l1com
//
// encrypt/decrypt demo
//
#include <intr.l1h>
(main func)
    (set int64 1 zero 0)
    (set int64 1 one 1)
    (set byte 1 zerob 0)
    (set byte 1 oneb 1)
    (set byte 256 inarray)
    (set byte 266 outarray)
    (set byte 266 decryptarray)
    (set byte 1 i 0)
    (set int64 1 size 256)
    (set int64 1 mode 0)
    (set int64 1 f 0)
    (set byte 1 c 0)
    (set const-int64 1 Pinarray 0)
    (set const-int64 1 Poutarray 0)
    (set const-int64 1 Pkeystr 0)
    (set const-int64 1 Pdecryptarray)
    (set string 256 keystr "swordfish")
    (set string s okstr "ciphersaber decrypt/encrypt ok!")
    (set string s errstr "ciphersaber decrypt/encrypt ERROR!")
    (inarray Pinarray pointer)
    (outarray Poutarray pointer)
    (keystr Pkeystr pointer)
    (decryptarray Pdecryptarray pointer)
    (zero :ciphersaber_init !)
    (for-loop)
    (((i size <) f =) f for)
        (i inarray [ i ] =)
        ((i oneb +) i =)
    (next)
    // encrypt
    (Pinarray Poutarray Pkeystr size mode :ciphersaber !)
    // decrypt
    (one mode =)
    (Poutarray Pdecryptarray Pkeystr size mode :ciphersaber !)
    // check array
    (zerob i =)
    (for-loop)
    (((i size <) f =) f for)
        (decryptarray [ i ] c =)
        (((c i !=) f =) f if)
            print_s (errstr)
            print_n
            exit (one)
        (endif)
        ((i oneb +) i =)
    (next)
    print_s (okstr)
    print_n
    exit (zero)
(funcend)
#include <ciphersaber.l1h>

As you can see, it is very simple to use. The mode variable switches from encrypt (0) to decyrpt (1) value. So the same library function is used. The program uses the new “pointer” functions variables for the “ciphersaber” function calls.