aboutsummaryrefslogtreecommitdiff
path: root/main.sts
blob: 906cbbbd4a5184a3f0be819b5da35e4b6118b504 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module ia32/elf/begin.sts
module cipher.sts

defword checktext
    1
exit

defword keygen
    drop 31 32 33 3
exit

set_entry
    ; read file into stack
    0 do sys_read 0 = until
        swap 1 +
    od drop as length
    local ciphertext

    0 ; initial key is empty
    do
        ; generate next key to try
        keygen as keylen local key

        ; decipher text (length is the same as for ciphertext)
        keylen 1 - length do 1 -
            as textpos local pos
                textpos word_size mul ciphertext + @
                key
                keylen
                pos
            cipher
            swap textpos
        dup 0 = untilod drop drop
        local plaintext

        ; check deciphering attempt, exit if Ok
    length checktext until
        ; else remove the text from stack and place keylen back
        0 do dup length = until
            swap drop 1 +
        od drop keylen
    od

    ; output text (todo: and language)
    length do 1 -
        dup word_size mul plaintext + @ sys_write
    dup 0 = untilod
sys_exit

module ia32/elf/end.sts