Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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