Skip to content

Instantly share code, notes, and snippets.

@alco
Created August 23, 2014 09:37
Show Gist options
  • Save alco/54beac75f1188bbe280b to your computer and use it in GitHub Desktop.
Save alco/54beac75f1188bbe280b to your computer and use it in GitHub Desktop.
var Hashids = require("../lib/hashids");
var hashids = new Hashids();
var bignums = [
9007199254740992,
"9007199254740992 (2^53)",
9007199254740993,
"9007199254740993 (2^53+1)",
18014398509481984,
"18014398509481984 (2^54)",
18014398509481985,
"18014398509481985 (2^54+1)",
1152921504606846976,
"1152921504606846976 (2^60)",
];
for (var i = 0; i < bignums.length; i+=2) {
var num = bignums[i];
console.log(bignums[i+1]);
console.log(num);
console.log(hashids.encrypt(num));
console.log("---");
}
from hashids import Hashids
nums = [
("9007199254740992 (2^53)", 9007199254740992),
("9007199254740993 (2^53+1)", 9007199254740993),
("18014398509481984 (2^54)", 18014398509481984),
("18014398509481985 (2^54+1)", 18014398509481985),
("1152921504606846976 (2^60)", 1152921504606846976),
]
hashids = Hashids()
for s, num in nums:
print s
print num
print hashids.encrypt(num)
print "---"
9007199254740992 (2^53)
9007199254740992
mNWyy8yjQYE
---
9007199254740993 (2^53+1)
9007199254740992
mNWyy8yjQYE
---
18014398509481984 (2^54)
18014398509481984
7KpVVxJ6pOy
---
18014398509481985 (2^54+1)
18014398509481984
7KpVVxJ6pOy
---
1152921504606846976 (2^60)
1152921504606847000
YkZM1Vrj7yp0
---
9007199254740992 (2^53)
9007199254740992
mNWyy8yjQYE
---
9007199254740993 (2^53+1)
9007199254740993
n6WOO7OkrgY
---
18014398509481984 (2^54)
18014398509481984
7KpVVxJ6pOy
---
18014398509481985 (2^54+1)
18014398509481985
8LMKKyYqMOg
---
1152921504606846976 (2^60)
1152921504606846976
YkZM1Vrj77o0
---
@zakame
Copy link

zakame commented Sep 15, 2014

From perl (zakame/hashids.pm@8bc2925)

    # Subtest: JS vs Perl bignums
    1..10
    ok 1 - encode bignum 9007199254740993
    ok 2 - decode bignum 9007199254740993
    not ok 3 - encode bignum 152921504606846976

    #   Failed test 'encode bignum 152921504606846976'
    #   at t/01_hashids.t line 272.
    #          got: 'Y7wZnAVZ7o0p'
    #     expected: 'YkZM1Vrj77o0'
    not ok 4 - decode bignum 152921504606846976

    #   Failed test 'decode bignum 152921504606846976'
    #   at t/01_hashids.t line 274.
    #          got: undef
    #     expected: '152921504606846976'
    ok 5 - encode bignum 18014398509481984
    ok 6 - decode bignum 18014398509481984
    ok 7 - encode bignum 18014398509481985
    ok 8 - decode bignum 18014398509481985
    ok 9 - encode bignum 9007199254740992
    ok 10 - decode bignum 9007199254740992
    # Looks like you failed 2 tests of 10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment