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

93 lines · 2051 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 secret "rosetta code"
8text cover "bacon's cipher is a method of steganography devised by francis bacon. a message is concealed in the presentation of text rather than its content."
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 emitc writes one byte
21fn emitc c uchar to void
22b = new uchar 1 0
23put b 0 c
24emit b
25end
26note 26-letter variant: letter n (a = 0) is 5 bits, most significant first; a space is 26 (11010).
27note The bits ride on the cover text's letters: 0 lower case, 1 upper case; other bytes are copied,
28note letters after the last bit stay lower case. Decoding reads the case of the letters 5 at a time.
29fn code c uchar to ulong
30if eq c 32
31ret 26
32end
33ret ulong sub c 97
34end
35fn isl c uchar to bool
36ret and ge c 97 le c 122
37end
38fn enc o edit uchar * to void
39nb = mul len secret 5
40b = ulong 0
41for i ulong len cover
42c = get cover i
43if and isl c lt b nb
44v = code get secret div b 5
45if eq and shr v sub 4 rem b 5 1 1
46c = sub c 32
47end
48b = add b 1
49end
50put o i c
51end
52end
53fn dec e view uchar * n ulong to void
54v = ulong 0
55k = ulong 0
56m = ulong 0
57for i ulong len e
58c = get e i
59if and lt m n or isl c and ge c 65 le c 90
60v = shl v 1
61if le c 90
62v = or v 1
63end
64k = add k 1
65if eq k 5
66if eq v 26
67emitc 32
68else
69emitc add uchar v 97
70end
71v = 0
72k = 0
73m = add m 1
74end
75end
76end
77emit nl
78end
79fn main to int
80o = new uchar 256 0
81n = len cover
82enc part o 0 n
83emit part o 0 n
84emit nl
85dec part o 0 n len secret
86ret 0
87end
88</syntaxhighlight>
89{{out}}
90<pre>
91BacoN's CIPhEr iS a meThoD of STEgaNOgraphY DeVised By fRANcis bACon. A message is concealed in the presentation of text rather than its content.
92rosetta code
93</pre>