diff options
Diffstat (limited to 'lib/base64/init.nom')
| -rw-r--r-- | lib/base64/init.nom | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/base64/init.nom b/lib/base64/init.nom index a76a49f..5257519 100644 --- a/lib/base64/init.nom +++ b/lib/base64/init.nom @@ -4,7 +4,7 @@ https://tools.ietf.org/html/rfc4648 $b64_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" -$b64_chars = [: for $ in 1 to (size of $b64_str): add ($b64_str, character $)] +$b64_chars = [: for $ in 1 to (#$b64_str): add ($b64_str, character $)] $reverse_b64 = {: for $c in $b64_chars at $i: add $c = ($i - 1)} $reverse_b64."=" = 64 set $reverse_b64's metatable to {.__index = (-> 0)} @@ -18,10 +18,10 @@ test: external: [base64 $str, base64 encode $str, $str base64] all mean: $chars = [] - for $i in 1 to (size of $str) via 3: + for $i in 1 to (#$str) via 3: $bytes = [=lua "\$str:byte(\$i, \($i + 2))"] $chars, add $b64_chars.((($bytes.1 & 252) >> 2) + 1) - if (size of $bytes) is: + if (#$bytes) is: 3: $chars, add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1) $chars, add $b64_chars.((($bytes.2 & 15) << 2) + (($bytes.3 & 192) >> 6) + 1) @@ -40,11 +40,11 @@ external: (chr $) means (=lua "string.char(\$)") [decode base64 $str, $str base64 decoded, base64 decode $str] all mean: $chars = [] - for $i in 1 to (size of $str) via 4: + for $i in 1 to (#$str) via 4: $indices = [: for $j in $i to ($i + 3): add $reverse_b64.($str, character $j)] $chars, add (chr (($indices.1 << 2) + (($indices.2 & 48) >> 4))) if (($str, character ($i + 2)) == "="): stop $chars, add (chr ((($indices.2 & 15) << 4) + (($indices.3 & 60) >> 2))) if (($str, character ($i + 3)) == "="): stop $chars, add (chr ((($indices.3 & 3) << 6) + $indices.4)) - return ($chars, joined) + return ($chars, joined)
\ No newline at end of file |
