interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / si / rosetta / tasks / vigenere-cipher / vigenere-cipher.om

60 lines · 1312 bytes Raw Blame History
1note Rosetta Code task "Vigenère cipher": https://rosettacode.org/wiki/Vigen%C3%A8re_cipher
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text key "VIGENERECIPHER"
6text msg "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!"
7note emit writes every byte of a to stdout; a short write is retried, an error exits 1
8fn emit a view uchar * to void
9o = ulong 0
10while lt o len a bound 4096
11k = write 1 a o sub len a o
12if le k 0
13exit 1
14end
15o = add o ulong k
16end
17end
18note clean keeps the letters of a, upper-cased, in r and returns how many
19fn clean a view uchar * r edit uchar * to ulong
20n = ulong 0
21for i ulong len a
22c = get a i
23if and ge c 97 le c 122
24c = sub c 32
25end
26if and ge c 65 le c 90
27put r n c
28n = add n 1
29end
30end
31ret n
32end
33note vig adds (dir 0) or subtracts (dir 1) the key letters mod 26, the key repeating
34fn vig a view uchar * r edit uchar * dir ulong to void
35for i ulong len a
36k = sub get key rem i len key 65
37c = sub get a i 65
38if eq dir 0
39c = rem add c k 26
40else
41c = rem sub add c 26 k 26
42end
43put r i add c 65
44end
45end
46fn main to int
47t = new uchar 256 0
48e = new uchar 256 0
49d = new uchar 256 0
50n = clean msg t
51emit part t 0 n
52emit nl
53vig part t 0 n part e 0 n 0
54emit part e 0 n
55emit nl
56vig part e 0 n part d 0 n 1
57emit part d 0 n
58emit nl
59ret 0
60end