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