Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/si/rosetta/tasks/base64-encode-data/base64-encode-data.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / si / rosetta / tasks / base64-encode-data / base64-encode-data.om` 60 lines ยท 1368 bytes Raw Blame History 1 note Rosetta Code task "Base64 encode data": https://rosettacode.org/wiki/Base64_encode_data 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text abc "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" 6 text m0 "M" 7 text m1 "Ma" 8 text m2 "Man" 9 text m3 "Hello, World!" 10 text m4 "To err is human, but to really foul things up you need a computer.\n -- Paul R. Ehrlich" 11 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 12 fn emit a view uchar * to void 13 o = ulong 0 14 while lt o len a bound 4096 15 k = write 1 a o sub len a o 16 if le k 0 17 exit 1 18 end 19 o = add o ulong k 20 end 21 end 22 note b64 takes the input 3 bytes (24 bits) at a time and writes 4 alphabet characters, '=' padding 23 note a short last group; output up to 512 bytes (input up to 384, longer traps 3) 24 fn b64 a view uchar * to void 25 o = new uchar 512 0 26 p = ulong 0 27 i = ulong 0 28 while lt i len a bound 200 29 r = sub len a i 30 v = shl ulong get a i 16 31 if gt r 1 32 v = or v shl ulong get a add i 1 8 33 end 34 if gt r 2 35 v = or v ulong get a add i 2 36 end 37 put o p get abc shr v 18 38 put o add p 1 get abc and shr v 12 63 39 put o add p 2 61 40 put o add p 3 61 41 if gt r 1 42 put o add p 2 get abc and shr v 6 63 43 end 44 if gt r 2 45 put o add p 3 get abc and v 63 46 end 47 p = add p 4 48 i = add i 3 49 end 50 emit part o 0 p 51 emit nl 52 end 53 fn main to int 54 b64 m0 55 b64 m1 56 b64 m2 57 b64 m3 58 b64 m4 59 ret 0 60 end