omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / drafts / rosettacode / caesar-cipher.wiki
| 1 | =={{header|Omegese}}== |
| 2 | {{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}} |
| 3 | Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program. |
| 4 | <syntaxhighlight lang="text"> |
| 5 | om2 |
| 6 | text nl "\n" |
| 7 | text msg "The quick brown fox Jumped over the lazy Dog" |
| 8 | note emit writes every byte of a to stdout; a short write is retried, an error exits 1 |
| 9 | fn emit a view uchar * to void |
| 10 | o = ulong 0 |
| 11 | while lt o len a bound 4096 |
| 12 | k = write 1 a o sub len a o |
| 13 | if le k 0 |
| 14 | exit 1 |
| 15 | end |
| 16 | o = add o ulong k |
| 17 | end |
| 18 | end |
| 19 | note shift rotates ASCII letters by k places (0..25) into r; other bytes are copied |
| 20 | fn shift a view uchar * r edit uchar * k uchar to void |
| 21 | for i ulong len a |
| 22 | c = get a i |
| 23 | if and ge c 65 le c 90 |
| 24 | c = add rem add sub c 65 k 26 65 |
| 25 | else |
| 26 | if and ge c 97 le c 122 |
| 27 | c = add rem add sub c 97 k 26 97 |
| 28 | end |
| 29 | end |
| 30 | put r i c |
| 31 | end |
| 32 | end |
| 33 | fn main to int |
| 34 | n = len msg |
| 35 | e = new uchar 256 0 |
| 36 | d = new uchar 256 0 |
| 37 | shift msg part e 0 n 11 |
| 38 | emit part e 0 n |
| 39 | emit nl |
| 40 | note decoding is a shift by 26 - 11 |
| 41 | shift part e 0 n part d 0 n 15 |
| 42 | emit part d 0 n |
| 43 | emit nl |
| 44 | ret 0 |
| 45 | end |
| 46 | </syntaxhighlight> |
| 47 | {{out}} |
| 48 | <pre> |
| 49 | Esp bftnv mczhy qzi Ufxapo zgpc esp wlkj Ozr |
| 50 | The quick brown fox Jumped over the lazy Dog |
| 51 | </pre> |