interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / substitution-cipher.wiki

65 lines · 1549 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7note key: plain letter a..z maps to the letter at the same place here
8text key "phqgiumeaylnofdxjkrcvstzwb"
9text msg "the quick brown fox jumps over the lazy dog, 42 times"
10note emit writes every byte of a to stdout; a short write is retried, an error exits 1
11fn emit a view uchar * to void
12o = ulong 0
13while lt o len a bound 4096
14k = write 1 a o sub len a o
15if le k 0
16exit 1
17end
18o = add o ulong k
19end
20end
21note enc maps each lower-case letter through key; other bytes are copied
22fn enc a view uchar * r edit uchar * to void
23for i ulong len a
24c = get a i
25if and ge c 97 le c 122
26c = get key sub c 97
27end
28put r i c
29end
30end
31note dec builds the inverse table first, then maps through it
32fn dec a view uchar * r edit uchar * to void
33inv = new uchar 26 0
34for j ulong 26
35put inv sub get key j 97 add uchar j 97
36end
37for i ulong len a
38c = get a i
39if and ge c 97 le c 122
40c = get inv sub c 97
41end
42put r i c
43end
44end
45fn main to int
46n = len msg
47e = new uchar 256 0
48d = new uchar 256 0
49emit msg
50emit nl
51enc msg part e 0 n
52emit part e 0 n
53emit nl
54dec part e 0 n part d 0 n
55emit part d 0 n
56emit nl
57ret 0
58end
59</syntaxhighlight>
60{{out}}
61<pre>
62the quick brown fox jumps over the lazy dog, 42 times
63cei jvaql hkdtf udz yvoxr dsik cei npbw gdm, 42 caoir
64the quick brown fox jumps over the lazy dog, 42 times
65</pre>