QR Code Encoding Mode for Short URLs

Regular URL Simplification uses a few characters of a regular URL encoding because you don’t need more. A typical short URL http://domain/code, where the code is an integer. Suppose I can use any base (base10, base16, base36 , base62, etc.) to represent a number.

QR code has many encodings , and we can optimize the QR code (the minimum version to get the lowest density ), so we can test baseX-modeY pairs ...

What is the best base mode pair?


NOTES

A guess...

Two modes correspond to the "URL profile abbreviation",

  • 0010 - Alphanumeric Encoding (11 bits to 2 )
  • 0100- Byte Encoding (8 bits per character)

My choice was “base36 uppercase” and alphanumeric (which also encodes “/”, “:”, etc.), but does not see any demonstration that it is always (for any URL length) the best. Got some good recommendations or math demos about this optimization?

Ideal (possibly impracticable)

There is another variation: “coding modes can be mixed as needed in a QR symbol” (Wikipedia) ... So, we can use also

  • HTTP://DOMAIN/with alphanumeric + change_mode + digital coding (10 bits by 3 )

URL- ( ), , (!), , ... ?

, ( ) QRCode-... ? ?

() - , (, Javascript),

 function bestBaseMode(domain,number_range) {
    var dom_len = domain.length;
    var urlBase_len = dom_len+8; // 8 = "http://".length + "/".length;
    var num_min = number_range[0];
    var num_max = number_range[1];
    // ... check optimal base and mode
    return [base,mode];
 }

-1: " .ly" ISO3166-1- , 4 894. , urlBase_len=14, num_min=4 num_max=894.

-2: "postcode-resolver.org", number_range - , , ~ 999 ~ 999999. , urlBase_len=27, num_min=999 num_max=9999999.

-3: "my-example3.net" number_range - SHA-1, 40 (2 40- ). num_max=num_min=Math.pow(8,40).

+4
1

... , ;-)


goQR.me , , , ,

, api qr. . QR- , .

... " ".

 /**
  * Find the best base-mode pair for a short URL template as QR-Code.
  * @param Msg for debug or report.
  * @param domain the string of the internet domain
  * @param digits10 the max. number of digits in a decimal representation
  * @return array of objects with equivalent valid answers.
  */
 function bestBaseMode(msg,  domain,digits10) {
    var commomBases= [2,8,10,16,36,60,62,64,124,248];  // your config
    var dom_len = domain.length;
    var urlBase_len = dom_len+8; // 8 = "http://".length + "/".length
    var numb = parseFloat( "9".repeat(digits10) );  
    var scores = [];
    var best = 99999;
    for(i in commomBases) {
        var b  = commomBases[i];
        // formula at http://math.stackexchange.com/a/335063
        var digits = Math.floor(Math.log(numb) / Math.log(b)) + 1;
        var mode = 'alpha';
        var len = dom_len + digits;
        var lost = 0;
        if (b>36) {
            mode = 'byte';
            lost = parseInt( urlBase_len*0.25); // only 6 of 8 bits used at URL
        }
        var score = len+lost; // penalty
        scores.push({BASE:b,MODE:mode,digits:digits,score:score});
        if (score<best) best = score;
    }
    var r = [];
    for(i in scores) {
        if (scores[i].score==best) r.push(scores[i]);
    }
    return r;
}

:

var x = bestBaseMode("Example-1",   "bit.ly",3);
console.log(JSON.stringify(x))   // "BASE":36,"MODE":"alpha","digits":2,"score":8

var x = bestBaseMode("Example-2",   "postcode-resolver.org",7);
console.log(JSON.stringify(x))  // "BASE":36,"MODE":"alpha","digits":5,"score":26

var x = bestBaseMode("Example-3",  "my-example3.net",97);
console.log(JSON.stringify(x))  // "BASE":248,"MODE":"byte","digits":41,"score":61
0

Source: https://habr.com/ru/post/1653243/


All Articles