Re: Decimal to Base64 conversion + Custom character list
Posted: 15 Oct 2017, 08:26
@Helgef
I have studied your functions, and I think I see how they work, more or less. Some of the math is well over my head but I was able to modify the code and have it still function. This version should allow use of any desired character table, the length of which determines the 'Base', with the possible exception of Base2 (binary) simply because of the need for a consistent 8 bit length. Please have a look and see if there are any obvious flaws. You should be able to use this site to check results, assuming you use a standard character table: http://extraconversion.com/base-number
I do have a math question. Why is X & Y equivalent to X mod (Y + 1)? Please keep in mind my math skills are roughly those of a 5 year old.
@jeeswg
Wow. Those functions are interesting! I can't understand most of the math in the code, but the idea of handling math as strings to get around the 64 bit integer limit is amazing.
I played around with prime number code a while back, but I lost interest because of the limit on the size of the primes it could work with. No idea if your functions could be applied...
I have studied your functions, and I think I see how they work, more or less. Some of the math is well over my head but I was able to modify the code and have it still function. This version should allow use of any desired character table, the length of which determines the 'Base', with the possible exception of Base2 (binary) simply because of the need for a consistent 8 bit length. Please have a look and see if there are any obvious flaws. You should be able to use this site to check results, assuming you use a standard character table: http://extraconversion.com/base-number
Code: Select all
#noenv
#singleinstance, ignore
setbatchlines, 10ms
setworkingdir, %a_scriptdir%
table := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
input := 64
msgbox, % "Table: " . table . "`n`nBase10: " . input . "`nBase" . strlen(table) . ": " base10to64(table, input) . "`nBase10: " . base64to10(table, base10to64(table, input))
base10to64(table, input)
{
base := strlen(table)
loop
{
output := SubStr(table, mod(input, base) + 1, 1) . output
input /= base
} until !input
return output
}
base64to10(table, input)
{
base := strlen(table)
in_length := strlen(input)
output := 0
for position, character in strsplit(input)
{
character := instr(table, character, 1) - 1
output += base ** (in_length - position) * character
}
return output
}
@jeeswg
Wow. Those functions are interesting! I can't understand most of the math in the code, but the idea of handling math as strings to get around the 64 bit integer limit is amazing.
I played around with prime number code a while back, but I lost interest because of the limit on the size of the primes it could work with. No idea if your functions could be applied...