The 42 Imperative -- 42a -- Help make a simple Base-63 convertor?

Rule: Strictly simple character substitution (+ maths if needed)

Base (note): My Base-63 = regex [A-Za-z0-9\s] = 26+26+10+1 = 63

Method: I suggest simple Caesarian Substitution

Prohibited: NO JavaScript allowed

Prize: A large sandwich. Or Amazon gift of $20


Submission: (i) Here, with code to try on a TW. (ii) With an example.

Proofs: (i) What is 1000 (decimal) in (my) Base-63? (ii) What is 1000 (Base-63) in decimal? (easy-peasy)

Ever hopeful
TT

There seems to be a curveball that makes this not “easy-peasy” — if we pay attention to the fact that you’ve apparently not put the 0 and 1 in their intuitive place at the beginning of the series, but in positions 53 and 54. So 1000 (by that ordering) would cash out to 54*63^3 + 53*63^2 + 53*63 + 53. :crazy_face:

But if you meant it to work more like hexadecimal ordering regex [0-9A-Za-z\s], then part 2 gets us a simple 250047. :slight_smile:

Right. Unintended.

The issue that arises is CONVENTIONS on Base-Notation above 26 (simple a-z) + (0-9) go peculiar (above base-36) … StackO.

My puzzle needs more clarity.
So: back to the drawing board for me to control the process better.

It’s funny, I didn’t even consider that the regex suggested digit ordering. I just assumed that it was "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ".split('')

I haven’t tried the problem, although I did write JS functions to handle this for the limited range of JS Numbers:

const base = (...cs) => {
  const to = (n) => n < 0 ? [''] : n == 0 ? cs[0] : to(~~(n / cs.length)) + cs[n % cs.length]
  const fromBase = (ds) => [...ds].reduce((a, d) => cs.length * a + cs.indexOf(d), 0)
  return {
    toBase: n => to(n).replace(/^0/, '').replace(/^$/, cs[0]),
    fromBase
  }
}
const {toBase: toBase63, fromBase: fromBase63} = 
  base(...'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ')

console.log(toBase63(1000))        //=> "Ft"
console.log(fromBase63('Ft'))      //=> 1000
console.log(toBase63(11497570248)) //=> "Base63"

If I find some time, I will see if I can do this in wikitext, but it’s not exactly high priority.

I have done this previously specifically to compress large numbers.

All you need in the array as Scott illustrated

Then use the remainder[] operator eg;

  • {{{ [[59]remainder[63]] }}} 59
  • {{{ [[70]remainder[63]] }}} 7

You have to handle the numbers greater than 63 eg above 70 becomes 07, Which

There is more to this of course

A very minor correction: there should be a space at the end of that string. TiddlyTweeter’s digits included the decimal digits, the capital letters, the lower-case letters, and the space.

This means, for instance, that

toBase63(2708110998568296910813949) //=> "A large number"
fromBase63('A large number')        //=> 2708110998568296910813949

To do this with such large numbers in JS, and hence in Tiddlywiki, you’d have to switch from plain numbers to BigInt. That would make it difficult to deal with in TW for large inputs.

Base64, over whatever alphabet, is much easier to deal with, as you can easily compress any length input, replacing every three-byte set with four base-64 digits.

1 Like

Right. The idea is: “A-Z. a-z. 0-9, space” = 63, not 64.

I do feel beholden to anyone who is interested.

Are you looking to convert only numbers, or arbitrary text? If the latter, can you explain the circumstances where this would do, but base-64 wouldn’t? Because that’s built in.

Merely text substitution. The Caesar Method.
I find base-63 interesting because it isn’t 64. 64 is another world. 63 is still palpable.

Something like that.

TT

I am only looking at this from an arbitrary character set for base N, without JavaScript or Regular expressions. I am happy with 10+26+26, 0-9, A-Z, a-Z = 62

  • The occasion for me to use it was to compress a decimal number so it would make a somewhat large decimal number into a much shorter alphanumeric number, not unlike Decimal to Hexadecimal but on steroids.
    • The value was to use less bytes than more.
  • Because the character set can be arbitary I would personally not use space, so there is no need to treat it like a title.

Although you’d mentioned a cipher before, I had basically ignored it, following up on base-63, assuming you meant it like base-2, base-10, or base-16.

I certainly know how Caesarian ciphers work: pretty well the simplest encoding scheme known. But it’s not clear to me what you’re looking to do. Do you simply want to be able to en/decode something using a fixed shift on your alphabet? What do you want to en/decode: the text of a given tiddler, an arbitrary string, something else?