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 / vigenere-cipher.wiki

69 lines · 1607 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"
7text key "VIGENERECIPHER"
8text msg "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!"
9note emit writes every byte of a to stdout; a short write is retried, an error exits 1
10fn emit a view uchar * to void
11o = ulong 0
12while lt o len a bound 4096
13k = write 1 a o sub len a o
14if le k 0
15exit 1
16end
17o = add o ulong k
18end
19end
20note clean keeps the letters of a, upper-cased, in r and returns how many
21fn clean a view uchar * r edit uchar * to ulong
22n = ulong 0
23for i ulong len a
24c = get a i
25if and ge c 97 le c 122
26c = sub c 32
27end
28if and ge c 65 le c 90
29put r n c
30n = add n 1
31end
32end
33ret n
34end
35note vig adds (dir 0) or subtracts (dir 1) the key letters mod 26, the key repeating
36fn vig a view uchar * r edit uchar * dir ulong to void
37for i ulong len a
38k = sub get key rem i len key 65
39c = sub get a i 65
40if eq dir 0
41c = rem add c k 26
42else
43c = rem sub add c 26 k 26
44end
45put r i add c 65
46end
47end
48fn main to int
49t = new uchar 256 0
50e = new uchar 256 0
51d = new uchar 256 0
52n = clean msg t
53emit part t 0 n
54emit nl
55vig part t 0 n part e 0 n 0
56emit part e 0 n
57emit nl
58vig part e 0 n part d 0 n 1
59emit part d 0 n
60emit nl
61ret 0
62end
63</syntaxhighlight>
64{{out}}
65<pre>
66BEWARETHEJABBERWOCKMYSONTHEJAWSTHATBITETHECLAWSTHATCATCH
67WMCEEIKLGRPIFVMEUGXQPWQVIOIAVEYXUEKFKBTALVXTGAFXYEVKPAGY
68BEWARETHEJABBERWOCKMYSONTHEJAWSTHATBITETHECLAWSTHATCATCH
69</pre>