schoentoon / hashidsxx Goto Github PK
View Code? Open in Web Editor NEWC++11 implementation of https://hashids.org/
License: MIT License
C++11 implementation of https://hashids.org/
License: MIT License
I am using a different suite library (not gtest), but the test.cpp
file seems broken anyways.
C:\prj\hashidsxx>test
------ Encode Saltless
[FAIL] Test 1 at test.cpp:11 (0 s)
hash.encode({123}) == "Mj3"
TEE == Mj3
(unexpected)
------ Decode Saltless
[FAIL] Test 2 at test.cpp:17 (0 s)
output.size() == 1
2 == 1
(unexpected)
[FAIL] Test 3 at test.cpp:18 (0 s)
output[0] == 123
0 == 123
(unexpected)
------ Encode Salt
[FAIL] Test 4 at test.cpp:23 (0 s)
hash.encode({123}) == "0lb"
6uu == 0lb
(unexpected)
------ Decode Salt
[FAIL] Test 5 at test.cpp:29 (0 s)
output.size() == 1
2 == 1
(unexpected)
[FAIL] Test 6 at test.cpp:30 (0 s)
output[0] == 123
0 == 123
(unexpected)
------ Encode SaltMinLength
[ OK ] Test 7 at test.cpp:36 (0 s)
[FAIL] Test 8 at test.cpp:37 (0 s)
output == "7P231QiYuXU53Y9"
uw1FuZb4czdZtUz == 7P231QiYuXU53Y9
(unexpected)
------ Decode SaltMinLength
[FAIL] Test 9 at test.cpp:43 (0 s)
output.size() == 4
2 == 4
(unexpected)
[FAIL] Test 10 at test.cpp:44 (0.0010001 s)
output[0] == 1
30819229 == 1
(unexpected)
[FAIL] Test 11 at test.cpp:45 (0.0010001 s)
output[1] == 2
1259390737886 == 2
(unexpected)
[FAIL] Test 12 at test.cpp:46 (0 s)
output[2] == 3
30681189080760423 == 3
(unexpected)
[FAIL] Test 13 at test.cpp:47 (0 s)
output[3] == 4
9223372961785795680 == 4
(unexpected)
[FAIL] Test 14 at test.cpp:51 (0 s)
output.size() == 1
2 == 1
(unexpected)
[FAIL] Test 15 at test.cpp:52 (0 s)
output[0] == 123
0 == 123
(unexpected)
------ Encode SaltMinLengthAlphabet
[ OK ] Test 16 at test.cpp:59 (0 s)
[FAIL] Test 17 at test.cpp:60 (0 s)
output == "oavlpogkzrxrkpxd"
slmwqitqnovtwtyk == oavlpogkzrxrkpxd
(unexpected)
[ OK ] Test 18 at test.cpp:62 (0 s)
------ Decode SaltMinLengthAlphabet
[FAIL] Test 19 at test.cpp:69 (0 s)
output.size() == 1
2 == 1
(unexpected)
[FAIL] Test 20 at test.cpp:70 (0 s)
output[0] == 123456789
0 == 123456789
(unexpected)
------ Encode Hex
[FAIL] Test 21 at test.cpp:76 (0 s)
output == "5RzW"
7LPL == 5RzW
(unexpected)
[FAIL] Test 22 at test.cpp:78 (0 s)
output == "8OlB1X6RjYuzPWW"
HUTw1Z95FHPr1x0v == 8OlB1X6RjYuzPWW
(unexpected)
------ Decode Hex
[FAIL] Test 23 at test.cpp:84 (0 s)
output == "abc"
== abc
(unexpected)
[FAIL] Test 24 at test.cpp:86 (0 s)
output == "f000000000000000f"
2d6336c == f000000000000000f
(unexpected)
[FAIL] Failure! 21/24 tests failed :(
Breakpoints: 0 (*)
Total time: 0.0490049 seconds.
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 :]
When compile the demo src in vs, will get an error.
error C2511: 'hashidsxx::Hashids::Hashids(hashidsxx::Hashids &&)': overloaded member function not found in 'hashidsxx::Hashids'
the __cpluscplus is defined to 199711L , but in the hashids.cpp:71 need
`
Hashids::Hashids(Hashids &&that)
: _salt(std::move(that._salt)), _alphabet(std::move(that._alphabet)),
_min_length(that._min_length), _separators(std::move(that._separators)),
_guards(std::move(that._guards)) {}
`
same as the header file.
I tried this but it generates a way too long hash v25TOEtz2CqquQ5c4ri7KtDFxQfNxfpoSp9TEKcMRiGTwX
using namespace boost::uuids;
std::string guidString {"3eb3ad5a-a9ae-4216-ab74-d96ea2fd0c96"};
uuid guidBytes {boost::lexical_cast<uuid>(guidString)};
hashidsxx::Hashids hasher {};
std::string hash {hasher.encode(guidBytes.begin(), guidBytes.end())};
std::stringstream ss;
for (uint8_t byte : guidBytes) {
ss << std::to_string(byte) << ", ";
}
return session->close(
guidString + "\n" +
std::to_string(guidBytes.size()) + "\n" +
ss.str() + "\n" +
hash
);
This is the equivalent in JS https://codepen.io/anon/pen/KQKKrK
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.