Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3
feat: std v3#13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
feat: std v3 #13
Changes from all commits
7ed4d8432866557514f3f8dc0ceeab3d49a1daeb15390410075fb420490913720d378ca925aa56d6da054ab4d5bFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| list base64_buffer; | ||
| list base64_strbuf; | ||
| list base64_lut; # lookup table: ASCII costume_number -> base64 value (0-63), 255=invalid/pad | ||
| %define BASE64_CHARSET "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" | ||
| %define BASE64_URLSAFE "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=" | ||
| # Build LUT from a charset string into base64_lut. | ||
| # base64_lut[costume_number_of_char] = base64 value (0-63), or 255 for '=' | ||
| proc base64_build_lut charset { | ||
| delete base64_lut; | ||
| # Fill 256 slots with 255 (invalid) | ||
| local j = 0; | ||
| repeat 256 { | ||
| add 255 to base64_lut; | ||
| j++; | ||
| } | ||
| # Map each charset char to its index (0-63), slot 65 (index 64) is '=' -> 255 already | ||
| local idx = 0; | ||
| repeat 64 { | ||
| switch_costume $charset[1 + idx]; | ||
| base64_lut[costume_number()] = idx; | ||
| idx++; | ||
| } | ||
| } | ||
| func base64_encode(charset) { | ||
| delete base64_strbuf; | ||
| local i = 1; | ||
| until i > length(base64_buffer) { | ||
| local a6 = base64_buffer[i] // 0b100; | ||
| local a2 = base64_buffer[i] % 0b100; | ||
| add $charset[1 + a6] to base64_strbuf; | ||
| i++; | ||
| if i <= length(base64_buffer) { | ||
| local b4hi = base64_buffer[i] // 0x10; | ||
| local b4lo = base64_buffer[i] % 0x10; | ||
| add $charset[1 + a2 * 0x10 + b4hi] to base64_strbuf; | ||
| i++; | ||
| if i <= length(base64_buffer) { | ||
| local c2 = base64_buffer[i] // 0b1000000; | ||
| local c6 = base64_buffer[i] % 0b1000000; | ||
| add $charset[1 + b4lo * 4 + c2] to base64_strbuf; | ||
| add $charset[1 + c6] to base64_strbuf; | ||
| i++; | ||
| } else { | ||
| add $charset[1 + b4lo * 4] to base64_strbuf; | ||
| add $charset[65] to base64_strbuf; | ||
| } | ||
| } else { | ||
| add $charset[1 + a2 * 0x10] to base64_strbuf; | ||
| add $charset[65] & $charset[65] to base64_strbuf; | ||
| } | ||
| } | ||
| return base64_strbuf; | ||
| } | ||
| # Decode base64 string $data into base64_buffer. | ||
| # Call base64_build_lut with the appropriate charset before calling this. | ||
| # Appends decoded bytes to base64_buffer (clear it first if needed). | ||
| proc base64_decode data { | ||
| local len = length($data); | ||
| local i = 1; | ||
| until i > len { | ||
| # Read up to 4 base64 chars, get their 6-bit values via LUT | ||
| switch_costume $data[i]; | ||
| local v0 = base64_lut[costume_number()]; | ||
| i++; | ||
| switch_costume $data[i]; | ||
| local v1 = base64_lut[costume_number()]; | ||
| i++; | ||
| # Byte 1: high 6 bits from v0, low 2 bits from v1 high | ||
| add v0 * 4 + v1 // 16 to base64_buffer; | ||
| # Check for padding or end: if 3rd char is '=' or beyond end, stop | ||
| if i > len { | ||
| stop_this_script; | ||
| } | ||
| switch_costume $data[i]; | ||
| local v2 = base64_lut[costume_number()]; | ||
| i++; | ||
| if v2 == 255 { | ||
| # Padding '=' — only 2 encoded chars, 1 decoded byte (already added) | ||
| stop_this_script; | ||
| } | ||
| # Byte 2: low 4 bits of v1, high 4 bits of v2 | ||
| add (v1 % 16) * 16 + v2 // 4 to base64_buffer; | ||
| if i > len { | ||
| stop_this_script; | ||
| } | ||
| switch_costume $data[i]; | ||
| local v3 = base64_lut[costume_number()]; | ||
| i++; | ||
| if v3 == 255 { | ||
| # Padding '=' — only 3 encoded chars, 2 decoded bytes | ||
| stop_this_script; | ||
| } | ||
| # Byte 3: low 2 bits of v2, all 6 bits of v3 | ||
| add (v2 % 4) * 64 + v3 to base64_buffer; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| list xor4 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9, 14, 15, 12, 13, 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12, 4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11, 5, 4, 7, 6, 1, 0, 3, 2, 13, 12, 15, 14, 9, 8, 11, 10, 6, 7, 4, 5, 2, 3, 0, 1, 14, 15, 12, 13, 10, 11, 8, 9, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 9, 8, 11, 10, 13, 12, 15, 14, 1, 0, 3, 2, 5, 4, 7, 6, 10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 5, 11, 10, 9, 8, 15, 14, 13, 12, 3, 2, 1, 0, 7, 6, 5, 4, 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3, 13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2, 14, 15, 12, 13, 10, 11, 8, 9, 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7, 7, 11, 11, 11, 11, 15, 15, 15, 15, 4, 5, 6, 7, 4, 5, 6, 7, 12, 13, 14, 15, 12, 13, 14, 15, 5, 5, 7, 7, 5, 5, 7, 7, 13, 13, 15, 15, 13, 13, 15, 15, 6, 7, 6, 7, 6, 7, 6, 7, 14, 15, 14, 15, 14, 15, 14, 15, 7, 7, 7, 7, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 8, 9, 10, 11, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 15, 9, 9, 11, 11, 13, 13, 15, 15, 9, 9, 11, 11, 13, 13, 15, 15, 10, 11, 10, 11, 14, 15, 14, 15, 10, 11, 10, 11, 14, 15, 14, 15, 11, 11, 11, 11, 15, 15, 15, 15, 11, 11, 11, 11, 15, 15, 15, 15, 12, 13, 14, 15, 12, 13, 14, 15, 12, 13, 14, 15, 12, 13, 14, 15, 13, 13, 15, 15, 13, 13, 15, 15, 13, 13, 15, 15, 13, 13, 15, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]; | ||
| %define XOR4(A, B) xor4[1+(A)*0x10+(B)] | ||
| func xor8(a, b) { | ||
| return XOR4($a//0x10, $b//0x10)*0x10 + XOR4($a%0x10, $b%0x10); | ||
| } | ||
| func xor16(a, b) { | ||
| return xor8($a//0x100, $b//0x100)*0x100 + xor8($a%0x100, $b%0x100); | ||
| } | ||
| func xor32(a, b) { | ||
| return xor16($a//0x10000, $b//0x10000)*0x10000 + xor16($a%0x10000, $b%0x10000); | ||
| } | ||
| %define AND4(A, B) and4[1+(A)*0x10+(B)] | ||
| %define OR4(A, B) or4[1+(A)*0x10+(B)] | ||
| func and8(a, b) { | ||
| return AND4($a//0x10, $b//0x10)*0x10 + AND4($a%0x10, $b%0x10); | ||
| } | ||
| func and16(a, b) { | ||
| return and8($a//0x100, $b//0x100)*0x100 + and8($a%0x100, $b%0x100); | ||
| } | ||
| func and32(a, b) { | ||
| return and16($a//0x10000, $b//0x10000)*0x10000 + and16($a%0x10000, $b%0x10000); | ||
| } | ||
| func or8(a, b) { | ||
| return OR4($a//0x10, $b//0x10)*0x10 + OR4($a%0x10, $b%0x10); | ||
| } | ||
| func or16(a, b) { | ||
| return or8($a//0x100, $b//0x100)*0x100 + or8($a%0x100, $b%0x100); | ||
| } | ||
| func or32(a, b) { | ||
| return or16($a//0x10000, $b//0x10000)*0x10000 + or16($a%0x10000, $b%0x10000); | ||
| } | ||
| %define NOT4(A) XOR4((A), 0xF) | ||
| func not8(a) { | ||
| return xor8($a, 0xFF); | ||
| } | ||
| func not16(a) { | ||
| return xor16($a, 0xFFFF); | ||
| } | ||
| func not32(a) { | ||
| return xor32($a, 0xFFFFFFFF); | ||
| } | ||
| %define ADD32(A,B) (((A)+(B))%0x100000000) | ||
| func add32(a, b) { | ||
| return ($a + $b) % 0x100000000; | ||
| } | ||
| %define ROL32(A) ((((A)*2)%0x100000000)+((A) > 0x7FFFFFFF)) | ||
| func rol32(a, b) { | ||
| local a = $a; | ||
| repeat $b % 32 { a = ROL32(a); } | ||
| return a; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| list bytes_strbuf; | ||
| list bytes_hex_table = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0A", "0B", "0C", "0D", "0E", "0F", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1A", "1B", "1C", "1D", "1E", "1F", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2A", "2B", "2C", "2D", "2E", "2F", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3A", "3B", "3C", "3D", "3E", "3F", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4A", "4B", "4C", "4D", "4E", "4F", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5A", "5B", "5C", "5D", "5E", "5F", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6A", "6B", "6C", "6D", "6E", "6F", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7A", "7B", "7C", "7D", "7E", "7F", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8A", "8B", "8C", "8D", "8E", "8F", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9A", "9B", "9C", "9D", "9E", "9F", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "AA", "AB", "AC", "AD", "AE", "AF", "B0", "B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9", "BA", "BB", "BC", "BD", "BE", "BF", "C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "CA", "CB", "CC", "CD", "CE", "CF", "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "DA", "DB", "DC", "DD", "DE", "DF", "E0", "E1", "E2", "E3", "E4", "E5", "E6", "E7", "E8", "E9", "EA", "EB", "EC", "ED", "EE", "EF", "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "FA", "FB", "FC", "FD", "FE", "FF"]; | ||
| %define BYTES_ENCODE_ASCII(LIST) \ | ||
| local i = 1; \ | ||
| repeat length($text) { \ | ||
| switch_costume $text[i]; \ | ||
| add costume_number()+31 to LIST; \ | ||
| i++; \ | ||
| } | ||
| %define BYTES_DECODE_ASCII(LIST) \ | ||
| delete bytes_strbuf; \ | ||
| local start = $start; \ | ||
| local end = $end; \ | ||
| if start < 0 { \ | ||
| start = length(LIST) + start + 1; \ | ||
| } \ | ||
| if end < 0 { \ | ||
| end = length(LIST) + end + 1; \ | ||
| } \ | ||
| local i = start; \ | ||
| repeat end - start + 1 { \ | ||
| switch_costume LIST[i]-31; \ | ||
| add costume_name() to bytes_strbuf; \ | ||
| i++; \ | ||
| } \ | ||
| return bytes_strbuf; | ||
| %define BYTES_ENCODE_HEX(LIST) \ | ||
| local i = 1; \ | ||
| repeat length($text)//2 { \ | ||
| add ("0x"&$text[i]&$text[i+1]) to LIST; \ | ||
| i+=2; \ | ||
| } | ||
| %define BYTES_DECODE_HEX(LIST) \ | ||
| delete bytes_strbuf; \ | ||
| local start = $start; \ | ||
| local end = $end; \ | ||
| if start < 0 { \ | ||
| start = length(LIST) + start + 1; \ | ||
| } \ | ||
| if end < 0 { \ | ||
| end = length(LIST) + end + 1; \ | ||
| } \ | ||
| local i = start; \ | ||
| repeat end - start + 1 { \ | ||
| add bytes_hex_table[1+LIST[i]][1] to bytes_strbuf; \ | ||
| add bytes_hex_table[1+LIST[i]][2] to bytes_strbuf; \ | ||
| i++; \ | ||
| } \ | ||
| return bytes_strbuf; |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???