interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / si / rosetta / tasks / base64-encode-data / base64-encode-data.om

60 lines · 1368 bytes Raw Blame History
1note Rosetta Code task "Base64 encode data": https://rosettacode.org/wiki/Base64_encode_data
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text abc "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
6text m0 "M"
7text m1 "Ma"
8text m2 "Man"
9text m3 "Hello, World!"
10text m4 "To err is human, but to really foul things up you need a computer.\n -- Paul R. Ehrlich"
11note emit writes every byte of a to stdout; a short write is retried, an error exits 1
12fn emit a view uchar * to void
13o = ulong 0
14while lt o len a bound 4096
15k = write 1 a o sub len a o
16if le k 0
17exit 1
18end
19o = add o ulong k
20end
21end
22note b64 takes the input 3 bytes (24 bits) at a time and writes 4 alphabet characters, '=' padding
23note a short last group; output up to 512 bytes (input up to 384, longer traps 3)
24fn b64 a view uchar * to void
25o = new uchar 512 0
26p = ulong 0
27i = ulong 0
28while lt i len a bound 200
29r = sub len a i
30v = shl ulong get a i 16
31if gt r 1
32v = or v shl ulong get a add i 1 8
33end
34if gt r 2
35v = or v ulong get a add i 2
36end
37put o p get abc shr v 18
38put o add p 1 get abc and shr v 12 63
39put o add p 2 61
40put o add p 3 61
41if gt r 1
42put o add p 2 get abc and shr v 6 63
43end
44if gt r 2
45put o add p 3 get abc and v 63
46end
47p = add p 4
48i = add i 3
49end
50emit part o 0 p
51emit nl
52end
53fn main to int
54b64 m0
55b64 m1
56b64 m2
57b64 m3
58b64 m4
59ret 0
60end