Created
July 9, 2020 23:22
-
-
Save bostrot/8381dc016476dc0c67e5b20e324bd5f3 to your computer and use it in GitHub Desktop.
Cheap and disgusting md5 utf16le with c++ and nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
std::string exec(std::string cmd) { | |
std::string data; | |
FILE * stream; | |
const int max_buffer = 256; | |
char buffer[max_buffer]; | |
cmd.append(" 2>&1"); | |
stream = popen(cmd.c_str(), "r"); | |
if (stream) { | |
while (!feof(stream)) | |
if (fgets(buffer, max_buffer, stream) != nullptr) data.append(buffer); | |
pclose(stream); | |
} | |
return data; | |
} | |
std::string md5sum(const std::string &input) | |
{ | |
// TODO: make this less cheap | |
std::string result = exec("echo \"console.log(require('crypto').createHash('md5')" | |
".update(Buffer('"+input+"', 'UTF-16LE')).digest('hex'));\" | node -"); | |
result = result.substr(0, 32); | |
return result; | |
} | |
int main() | |
{ | |
std::cout << md5sum("abcdef-ghijklm"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment