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 / base64-encode-data.wiki

71 lines · 1649 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 abc "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
8text m0 "M"
9text m1 "Ma"
10text m2 "Man"
11text m3 "Hello, World!"
12text m4 "To err is human, but to really foul things up you need a computer.\n -- Paul R. Ehrlich"
13note emit writes every byte of a to stdout; a short write is retried, an error exits 1
14fn emit a view uchar * to void
15o = ulong 0
16while lt o len a bound 4096
17k = write 1 a o sub len a o
18if le k 0
19exit 1
20end
21o = add o ulong k
22end
23end
24note b64 takes the input 3 bytes (24 bits) at a time and writes 4 alphabet characters, '=' padding
25note a short last group; output up to 512 bytes (input up to 384, longer traps 3)
26fn b64 a view uchar * to void
27o = new uchar 512 0
28p = ulong 0
29i = ulong 0
30while lt i len a bound 200
31r = sub len a i
32v = shl ulong get a i 16
33if gt r 1
34v = or v shl ulong get a add i 1 8
35end
36if gt r 2
37v = or v ulong get a add i 2
38end
39put o p get abc shr v 18
40put o add p 1 get abc and shr v 12 63
41put o add p 2 61
42put o add p 3 61
43if gt r 1
44put o add p 2 get abc and shr v 6 63
45end
46if gt r 2
47put o add p 3 get abc and v 63
48end
49p = add p 4
50i = add i 3
51end
52emit part o 0 p
53emit nl
54end
55fn main to int
56b64 m0
57b64 m1
58b64 m2
59b64 m3
60b64 m4
61ret 0
62end
63</syntaxhighlight>
64{{out}}
65<pre>
66TQ==
67TWE=
68TWFu
69SGVsbG8sIFdvcmxkIQ==
70VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g=
71</pre>