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/interplane-forge/blob/main/tools/bring/src/35enc.om # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-forge / tools / bring / src / 35enc.om` 217 lines ยท 3973 bytes Raw Blame History 1 note Encodings used by bring/get. SHA-256 is om/tls/sha2.om, composed before this unit. 2 text thex "`0123456789abcdef`" 3 text tb64 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" 4 text tb64u "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" 5 text tb58 "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" 6 text tdidk "did:key:" 7 text tproject "project" 8 fn hexw d view uchar * o edit uchar * n ulong to ulong 9 for i ulong len d bound `9223372036854775807` 10 put o add n mul i 2 get thex shr get d i 4 11 put o add add n mul i 2 1 get thex and get d i 15 12 end 13 ret add n mul len d 2 14 end 15 note sha of an open descriptor from its current position to EOF. 16 fn shafd fd int d edit uchar 32 to void 17 c = new ulong 40 0 18 b = new uchar 65536 0 19 sha256_init c 20 while true bound `9223372036854775807` 21 r = read fd b 0 len b 22 if eq r -4 23 continue 24 end 25 if lt r 0 26 die terrio 27 end 28 if eq r 0 29 break 30 end 31 sha256_update c part b 0 ulong r 32 end 33 sha256_final c d 34 end 35 note base64url, no padding. Returns output length. 36 fn b64u s view uchar * o edit uchar * to ulong 37 n = ulong 0 38 i = ulong 0 39 while lt i len s bound `9223372036854775807` 40 k = sub len s i 41 w = shl ulong get s i 16 42 if gt k 1 43 w = or w shl ulong get s add i 1 8 44 end 45 if gt k 2 46 w = or w ulong get s add i 2 47 end 48 put o n get tb64u and shr w 18 63 49 put o add n 1 get tb64u and shr w 12 63 50 n = add n 2 51 if gt k 1 52 put o n get tb64u and shr w 6 63 53 n = add n 1 54 end 55 if gt k 2 56 put o n get tb64u and w 63 57 n = add n 1 58 end 59 i = add i 3 60 end 61 ret n 62 end 63 fn b64v c uchar to long 64 for i ulong 64 65 if eq get tb64 i c 66 ret long i 67 end 68 end 69 ret -1 70 end 71 note standard padded base64 decode; returns length or -1. 72 fn b64d s view uchar * o edit uchar * to long 73 if ne rem len s 4 0 74 ret -1 75 end 76 n = ulong 0 77 i = ulong 0 78 while lt i len s bound `9223372036854775807` 79 g = b64grp s i 80 if lt g 0 81 ret -1 82 end 83 if and ge g `16777216` lt add i 4 len s 84 ret -1 85 end 86 k = b64emit ulong g o n 87 if lt k 0 88 ret -1 89 end 90 n = ulong k 91 i = add i 4 92 end 93 ret long n 94 end 95 fn b64emit w ulong o edit uchar * n ulong to long 96 pad = shr w 24 97 k = n 98 for j ulong sub 3 pad 99 if ge k len o 100 ret -1 101 end 102 sh = sub 16 mul j 8 103 put o k uchar and shr w sh 255 104 k = add k 1 105 end 106 ret long k 107 end 108 note b64grp: one 4-char group at s[i]: the 24 bits, plus the pad count shifted 24; -1 when invalid 109 fn b64grp s view uchar * i ulong to long 110 w = ulong 0 111 pad = ulong 0 112 for j ulong 4 113 c = get s add i j 114 v = long 0 115 if eq c 61 116 if lt j 2 117 ret -1 118 end 119 pad = add pad 1 120 else 121 if gt pad 0 122 ret -1 123 end 124 v = b64v c 125 if lt v 0 126 ret -1 127 end 128 end 129 w = or shl w 6 ulong v 130 end 131 ret long or and w `16777215` shl pad 24 132 end 133 note did:key:z + base58btc(0xed 0x01 + 32 bytes): exactly the Radicle `ed25519` form. 134 fn didkey pk view uchar 32 o edit uchar * to ulong 135 x = new uchar 34 0 136 put x 0 237 137 put x 1 1 138 for i ulong 32 139 put x add i 2 get pk i 140 end 141 dg = new uchar 64 0 142 dn = ulong 0 143 for i ulong 34 144 carry = ulong get x i 145 for j ulong dn bound 64 146 carry = add carry mul ulong get dg j 256 147 put dg j uchar rem carry 58 148 carry = div carry 58 149 end 150 while gt carry 0 bound 64 151 put dg dn uchar rem carry 58 152 dn = add dn 1 153 carry = div carry 58 154 end 155 end 156 n = cpy o 0 tdidk 157 put o n 122 158 n = add n 1 159 for i ulong dn bound 64 160 put o n get tb58 get dg sub sub dn i 1 161 n = add n 1 162 end 163 ret n 164 end 165 note form encoding of every byte except unreserved ASCII. 166 fn formw s view uchar * o edit uchar * n ulong to ulong 167 k = n 168 for i ulong len s bound `9223372036854775807` 169 c = get s i 170 if unres c 171 put o k c 172 k = add k 1 173 else 174 put o k 37 175 put o add k 1 get thex shr c 4 176 put o add k 2 get thex and c 15 177 k = add k 3 178 end 179 end 180 ret k 181 end 182 fn unres c uchar to bool 183 if isaln c 184 ret true 185 end 186 if or eq c 45 eq c 46 187 ret true 188 end 189 ret or eq c 95 eq c 126 190 end 191 fn projname folder view uchar * o edit uchar 64 to ulong 192 n = ulong 0 193 dash = false 194 for i ulong len folder bound `9223372036854775807` 195 c = lcb get folder i 196 ok = or and ge c 97 le c 122 isdig c 197 if ok 198 if and dash gt n 0 199 if lt n 63 200 put o n 45 201 n = add n 1 202 end 203 end 204 dash = false 205 if lt n 64 206 put o n c 207 n = add n 1 208 end 209 else 210 dash = true 211 end 212 end 213 if eq n 0 214 n = cpy o 0 tproject 215 end 216 ret n 217 end