GJY4PXRQ55XUVKTZSPP5WFKLVVEIBKIGSP7PLHXK5YFNUQWYC6KQC local start = 1for i = 1, #str doif i % max == 0 thentable.insert( result, str:sub( start, i ) )start = i + 1elseif i == #str thentable.insert( result, str:sub( start, i ) )endend
local start = 1for i = 1, #str doif i % max == 0 thentable.insert(result, str:sub(start, i))start = i + 1elseif i == #str thentable.insert(result, str:sub(start, i))endend
local function pure_from_bit( str )return ( str:gsub( '........', function ( cc )return string.char( tonumber( cc, 2 ) )end ) )
local function pure_from_bit(str)return (str:gsub('........', function(cc)return string.char(tonumber(cc, 2))end))
local function unexpected_char_error( str, pos )local c = string.sub( str, pos, pos )return string.format( "unexpected character at position %d: '%s'", pos, c )
local function unexpected_char_error(str, pos)local c = string.sub(str, pos, pos)return string.format("unexpected character at position %d: '%s'", pos, c)
function basexx.from_bit( str, ignore )str = ignore_set( str, ignore )str = string.lower( str )str = str:gsub( '[ilo]', function( c ) return bitMap[ c ] end )local pos = string.find( str, "[^01]" )if pos then return nil, unexpected_char_error( str, pos ) end
function basexx.from_bit(str, ignore)str = ignore_set(str, ignore)str = string.lower(str)str = str:gsub('[ilo]', function(c) return bitMap[c] end)local pos = string.find(str, "[^01]")if pos then return nil, unexpected_char_error(str, pos) end
function basexx.to_bit( str )return ( str:gsub( '.', function ( c )local byte = string.byte( c )local bits = {}for _ = 1,8 dotable.insert( bits, byte % 2 )byte = math.floor( byte / 2 )endreturn table.concat( bits ):reverse()end ) )
function basexx.to_bit(str)return (str:gsub('.', function(c)local byte = string.byte(c)local bits = {}for _ = 1, 8 dotable.insert(bits, byte % 2)byte = math.floor(byte / 2)endreturn table.concat(bits):reverse()end))
function basexx.from_hex( str, ignore )str = ignore_set( str, ignore )local pos = string.find( str, "[^%x]" )if pos then return nil, unexpected_char_error( str, pos ) end
function basexx.from_hex(str, ignore)str = ignore_set(str, ignore)local pos = string.find(str, "[^%x]")if pos then return nil, unexpected_char_error(str, pos) end
function basexx.to_hex( str )return ( str:gsub( '.', function ( c )return string.format('%02X', string.byte( c ) )end ) )
function basexx.to_hex(str)return (str:gsub('.', function(c)return string.format('%02X', string.byte(c))end))
local function from_basexx( str, alphabet, bits )local result = {}for i = 1, #str dolocal c = string.sub( str, i, i )if c ~= '=' thenlocal index = string.find( alphabet, c, 1, true )if not index thenreturn nil, unexpected_char_error( str, i )endtable.insert( result, number_to_bit( index - 1, bits ) )endend
local function from_basexx(str, alphabet, bits)local result = {}for i = 1, #str dolocal c = string.sub(str, i, i)if c ~= '=' thenlocal index = string.find(alphabet, c, 1, true)if not index thenreturn nil, unexpected_char_error(str, i)endtable.insert(result, number_to_bit(index - 1, bits))endend
local value = table.concat( result )local pad = #value % 8return pure_from_bit( string.sub( value, 1, #value - pad ) )
local value = table.concat(result)local pad = #value % 8return pure_from_bit(string.sub(value, 1, #value - pad))
local chunks = divide_string( bitString, bits )local result = {}for _,value in ipairs( chunks ) doif ( #value < bits ) thenvalue = value .. string.rep( '0', bits - #value )endlocal pos = tonumber( value, 2 ) + 1table.insert( result, alphabet:sub( pos, pos ) )end
local chunks = divide_string(bitString, bits)local result = {}for _, value in ipairs(chunks) doif (#value < bits) thenvalue = value .. string.rep('0', bits - #value)endlocal pos = tonumber(value, 2) + 1table.insert(result, alphabet:sub(pos, pos))end
function basexx.from_base32( str, ignore )str = ignore_set( str, ignore )return from_basexx( string.upper( str ), base32Alphabet, 5 )
function basexx.from_base32(str, ignore)str = ignore_set(str, ignore)return from_basexx(string.upper(str), base32Alphabet, 5)
function basexx.from_crockford( str, ignore )str = ignore_set( str, ignore )str = string.upper( str )str = str:gsub( '[ILOU]', function( c ) return crockfordMap[ c ] end )return from_basexx( str, crockfordAlphabet, 5 )
function basexx.from_crockford(str, ignore)str = ignore_set(str, ignore)str = string.upper(str)str = str:gsub('[ILOU]', function(c) return crockfordMap[c] end)return from_basexx(str, crockfordAlphabet, 5)
local url64Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".."abcdefghijklmnopqrstuvwxyz".."0123456789-_"function basexx.from_url64( str, ignore )str = ignore_set( str, ignore )return from_basexx( str, url64Alphabet, 6 )
local url64Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" .."abcdefghijklmnopqrstuvwxyz" .."0123456789-_"function basexx.from_url64(str, ignore)str = ignore_set(str, ignore)return from_basexx(str, url64Alphabet, 6)
0x4B, 0x4C, 0x46, 0x41, 0x00, 0x3F, 0x3E, 0x45,0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,0x08, 0x09, 0x40, 0x00, 0x49, 0x42, 0x4A, 0x47,0x51, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A,0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32,0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A,0x3B, 0x3C, 0x3D, 0x4D, 0x00, 0x4E, 0x43, 0x00,0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10,0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,0x21, 0x22, 0x23, 0x4F, 0x00, 0x50, 0x00, 0x00 }
0x4B, 0x4C, 0x46, 0x41, 0x00, 0x3F, 0x3E, 0x45,0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,0x08, 0x09, 0x40, 0x00, 0x49, 0x42, 0x4A, 0x47,0x51, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A,0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32,0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A,0x3B, 0x3C, 0x3D, 0x4D, 0x00, 0x4E, 0x43, 0x00,0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10,0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,0x21, 0x22, 0x23, 0x4F, 0x00, 0x50, 0x00, 0x00 }
function basexx.from_z85( str, ignore )str = ignore_set( str, ignore )if ( #str % 5 ) ~= 0 thenreturn nil, length_error( #str, 5 )end
function basexx.from_z85(str, ignore)str = ignore_set(str, ignore)if (#str % 5) ~= 0 thenreturn nil, length_error(#str, 5)end
local value = 0for i = 1, #str dolocal index = string.byte( str, i ) - 31if index < 1 or index >= #z85Decoder thenreturn nil, unexpected_char_error( str, i )endvalue = ( value * 85 ) + z85Decoder[ index ]if ( i % 5 ) == 0 thenlocal divisor = 256 * 256 * 256while divisor ~= 0 dolocal b = math.floor( value / divisor ) % 256table.insert( result, string.char( b ) )divisor = math.floor( divisor / 256 )endvalue = 0endend
local value = 0for i = 1, #str dolocal index = string.byte(str, i) - 31if index < 1 or index >= #z85Decoder thenreturn nil, unexpected_char_error(str, i)endvalue = (value * 85) + z85Decoder[index]if (i % 5) == 0 thenlocal divisor = 256 * 256 * 256while divisor ~= 0 dolocal b = math.floor(value / divisor) % 256table.insert(result, string.char(b))divisor = math.floor(divisor / 256)endvalue = 0endend
local z85Encoder = "0123456789".."abcdefghijklmnopqrstuvwxyz".."ABCDEFGHIJKLMNOPQRSTUVWXYZ"..".-:+=^!/*?&<>()[]{}@%$#"
local z85Encoder = "0123456789" .."abcdefghijklmnopqrstuvwxyz" .."ABCDEFGHIJKLMNOPQRSTUVWXYZ" ..".-:+=^!/*?&<>()[]{}@%$#"
local value = 0for i = 1, #str dolocal b = string.byte( str, i )value = ( value * 256 ) + bif ( i % 4 ) == 0 thenlocal divisor = 85 * 85 * 85 * 85while divisor ~= 0 dolocal index = ( math.floor( value / divisor ) % 85 ) + 1table.insert( result, z85Encoder:sub( index, index ) )divisor = math.floor( divisor / 85 )endvalue = 0endend
local value = 0for i = 1, #str dolocal b = string.byte(str, i)value = (value * 256) + bif (i % 4) == 0 thenlocal divisor = 85 * 85 * 85 * 85while divisor ~= 0 dolocal index = (math.floor(value / divisor) % 85) + 1table.insert(result, z85Encoder:sub(index, index))divisor = math.floor(divisor / 85)endvalue = 0endend