schoentoon/hashidsxx

Bump up to 1.0

jd327 opened this issue · 11 comments

Hi @schoentoon,

I updated the site (http://hashids.org/) + my versions to 1.0. Here's what's different: https://github.com/ivanakimov/hashids.js#changelog (which is not much).

If you want to come over to Hashids group, we'd be glad to have you. Are you still up for maintaining C++ port?

If you have any issues with the site (hashids/hashids.github.io#4) or any issues in general, just ping :]

What's the difference between encode and encodeHex if I may ask? Same goes for decode of course.

Encode converts integers to hashids, encodeHex converts hex values to hashids. Decode (ids -> ints), decodeHex (ids -> hex).

It's usually popular among MongoDB devs, they convert objectIds (which are in hexadecimal) to hashids.

So instead accepting a bunch of integers for encode I should accepts a bunch of strings which I should decode from hex numbers to integers myself? And for decode I should return a vector filled with strings which represent hex encoded integers?... That sounds kind of stupid to me tbh.

Ok, here's the deal. encodeHex takes one parameter which is a hexadecimal sting as you can see here, here and here.

It returns one value which is an id. decodeHex does the same but in reverse - takes that id, and returns back a hexadecimal string - once again one value. Both methods take advantage of encode and decode functions, but only take care of the additional hex format complexity.

Ok, I implemented both mostly. I'm still not entirely sure if they are the same as in the other ones. Mind checking this? The example program (hashidsxx.cpp) has support for it as well, makes it easier to check.

Hi Toon, two things:

  1. I had to add #include <cmath> to hashids.cpp in order to successfully compile on my OS X.
  2. When I try to encodeHex('abc') with custom salt, in other implementations I get "5RzW", but in this one:
hashidsxx-master ❯ ./hashidsxx encodeHex -s 'this is my salt' -i 'abc'      
2bRr

For "f000000000000000f" hex value, it's supposed to be "8OlB1X6RjYuzPWW", but C++:

hashidsxx-master ❯ ./hashidsxx encodeHex -s 'this is my salt' -i 'f000000000000000f'
libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: stoul: out of range
[1]    1028 abort      ./hashidsxx encodeHex -s 'this is my salt' -i 'f000000000000000f'

That's 3 things ;)

Curious, what is OS X complaining about that it needs cmath? I will look into them asap.

Mac OS X 10.9.5

hashidsxx-master ❯ c++ --version                                                                                                                                                                                                                                                                                            ⏎
Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

And compiling

hashidsxx-master ❯ make
c++ -std=c++11 -g -Wall -O2 -pipe -Wno-sign-compare  -I. -c hashids.cpp -o hashids.o
hashids.cpp:42:17: error: no member named 'ceil' in namespace 'std'
      (int)std::ceil((float)_alphabet.length() / RATIO_SEPARATORS);
           ~~~~~^
hashids.cpp:55:30: error: no member named 'ceil' in namespace 'std'
  int num_guards = (int)std::ceil((float)_alphabet.length() / RATIO_GUARDS);
                        ~~~~~^
hashids.cpp:147:21: error: no member named 'pow' in namespace 'std'; did you mean 'pos'?
    output += pos * std::pow(alphabet.size(), input.size() - i - 1);
                    ^~~~~~~~
                    pos
hashids.cpp:146:28: note: 'pos' declared here
    std::string::size_type pos = alphabet.find(c);
                           ^
hashids.cpp:147:29: error: called object type 'std::string::size_type' (aka 'unsigned long') is not a function or function pointer
    output += pos * std::pow(alphabet.size(), input.size() - i - 1);
                    ~~~~~~~~^
4 errors generated.
make: *** [hashids.o] Error 1

Should be all good now. Missed a few things.

Great, thanks. Updating site now.

Your readme could be updated btw (encrypt/decrypt).