Decrypt checksum? #3

Closed
opened 2017-08-30 10:31:22 +00:00 by florianbepunkt · 1 comment
florianbepunkt commented 2017-08-30 10:31:22 +00:00 (Migrated from github.com)

Is it possible to decode the checksum, so I get the original decodes string?

Is it possible to decode the checksum, so I get the original decodes string?
reviewher commented 2017-08-30 16:32:36 +00:00 (Migrated from github.com)

This is not possible because of collisions (multiple strings with the same value). For example, we can generalize the lyrics of the "99 Bottles of Beer" song:

var ADLER32 = require('adler-32'), sprintf = require('printj').sprintf;
var data = []; 
for(var i = 0; i < 1000; ++i) {
    var str = sprintf("%1$2d bottles of beer on the wall, %1$02d bottles of beer!", i);
    var hash = ADLER32.bstr(str);
    if(data[hash]) console.log("collision!", i, data[hash]);
    data[hash] = i;
}

You'll see a bunch of collisions! The first one is 201 120:

ADLER32.bstr("201 bottles of beer on the wall, 201 bottles of beer!") // -773058206
ADLER32.bstr("120 bottles of beer on the wall, 120 bottles of beer!") // -773058206

If you dig further, you'll find multiple collisions! There's a 5-way collision where 593, 674, 755, 836, and 917 yield the same value:

function x(i) { return ADLER32.bstr(i + " bottles of beer on the wall, " + i + " bottles of beer!"); } [593,674,755,836,917].map(x)
// [ -707784322, -707784322, -707784322, -707784322, -707784322 ]
This is not possible because of collisions (multiple strings with the same value). For example, we can generalize the lyrics of the "99 Bottles of Beer" song: ```js var ADLER32 = require('adler-32'), sprintf = require('printj').sprintf; var data = []; for(var i = 0; i < 1000; ++i) { var str = sprintf("%1$2d bottles of beer on the wall, %1$02d bottles of beer!", i); var hash = ADLER32.bstr(str); if(data[hash]) console.log("collision!", i, data[hash]); data[hash] = i; } ``` You'll see a bunch of collisions! The first one is `201 120`: ```js ADLER32.bstr("201 bottles of beer on the wall, 201 bottles of beer!") // -773058206 ADLER32.bstr("120 bottles of beer on the wall, 120 bottles of beer!") // -773058206 ``` If you dig further, you'll find multiple collisions! There's a 5-way collision where 593, 674, 755, 836, and 917 yield the same value: ```js function x(i) { return ADLER32.bstr(i + " bottles of beer on the wall, " + i + " bottles of beer!"); } [593,674,755,836,917].map(x) // [ -707784322, -707784322, -707784322, -707784322, -707784322 ] ```
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/js-adler32#3
No description provided.