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 / caesar-cipher / caesar-cipher.om

43 lines · 979 bytes Raw Blame History
1note Rosetta Code task "Caesar cipher": https://rosettacode.org/wiki/Caesar_cipher
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text msg "The quick brown fox Jumped over the lazy Dog"
6note emit writes every byte of a to stdout; a short write is retried, an error exits 1
7fn emit a view uchar * to void
8o = ulong 0
9while lt o len a bound 4096
10k = write 1 a o sub len a o
11if le k 0
12exit 1
13end
14o = add o ulong k
15end
16end
17note shift rotates ASCII letters by k places (0..25) into r; other bytes are copied
18fn shift a view uchar * r edit uchar * k uchar to void
19for i ulong len a
20c = get a i
21if and ge c 65 le c 90
22c = add rem add sub c 65 k 26 65
23else
24if and ge c 97 le c 122
25c = add rem add sub c 97 k 26 97
26end
27end
28put r i c
29end
30end
31fn main to int
32n = len msg
33e = new uchar 256 0
34d = new uchar 256 0
35shift msg part e 0 n 11
36emit part e 0 n
37emit nl
38note decoding is a shift by 26 - 11
39shift part e 0 n part d 0 n 15
40emit part d 0 n
41emit nl
42ret 0
43end