Skip to content

Instantly share code, notes, and snippets.

@jhasse
Created May 25, 2011 10:18
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhasse/990731 to your computer and use it in GitHub Desktop.
Save jhasse/990731 to your computer and use it in GitHub Desktop.
SHA-1 With Boost
#include <iostream>
#include <boost/uuid/sha1.hpp>
void display(char* hash)
{
std::cout << "SHA1: " << std::hex;
for(int i = 0; i < 20; ++i)
{
std::cout << ((hash[i] & 0x000000F0) >> 4)
<< (hash[i] & 0x0000000F);
}
std::cout << std::endl; // Das wars
}
int main() {
boost::uuids::detail::sha1 s;
char hash[20];
std::string a = "Franz jagt im komplett verwahrlosten Taxi quer durch Bayern";
s.process_bytes(a.c_str(), a.size());
unsigned int digest[5];
s.get_digest(digest);
for(int i = 0; i < 5; ++i)
{
const char* tmp = reinterpret_cast<char*>(digest);
hash[i*4] = tmp[i*4+3];
hash[i*4+1] = tmp[i*4+2];
hash[i*4+2] = tmp[i*4+1];
hash[i*4+3] = tmp[i*4];
}
display(hash);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment