(n << rotate) | (n >> (32 - rotate));
68 const char* hexChars =
"0123456789abcdef";
69 auto* intsig =
static_cast<uint8_t*
>(sig);
70std::string hex =
"";
71 for(uint8_t i = 0; i < 20; i++) {
72hex.push_back(hexChars[(intsig[i] >> 4) & 0xF]);
73hex.push_back(hexChars[(intsig[i]) & 0xF]);
84void*
hash_bs(
const void* input_bs, uint64_t input_size) {
85 auto* input =
static_cast<constuint8_t*
>(input_bs);
88uint32_t h0 = 0x67452301, a = 0;
89uint32_t h1 = 0xEFCDAB89, b = 0;
90uint32_t h2 = 0x98BADCFE, c = 0;
91uint32_t h3 = 0x10325476, d = 0;
92uint32_t h4 = 0xC3D2E1F0, e = 0;
97uint64_t padded_message_size = 0;
98 if(input_size % 64 < 56) {
99padded_message_size = input_size + 64 - (input_size % 64);
101padded_message_size = input_size + 128 - (input_size % 64);
105std::vector<uint8_t> padded_message(padded_message_size);
108std::copy(input, input + input_size, padded_message.begin());
111padded_message[input_size] = 1 << 7;
112 for(uint64_t i = input_size; i % 64 != 56; i++) {
113 if(i == input_size) {
116padded_message[i] = 0;
121uint64_t input_bitsize = input_size * 8;
122 for(uint8_t i = 0; i < 8; i++) {
123padded_message[padded_message_size - 8 + i] =
124(input_bitsize >> (56 - 8 * i)) & 0xFF;
128std::array<uint32_t, 80> blocks{};
131 for(uint64_t chunk = 0; chunk * 64 < padded_message_size; chunk++) {
133 for(uint8_t bid = 0; bid < 16; bid++) {
138 for(uint8_t cid = 0; cid < 4; cid++) {
139blocks[bid] = (blocks[bid] << 8) +
140padded_message[chunk * 64 + bid * 4 + cid];
144 for(uint8_t i = 16; i < 80; i++) {
147blocks[i - 14] ^ blocks[i - 16],
159 for(uint8_t i = 0; i < 80; i++) {
160uint32_t F = 0, g = 0;
162F = (b & c) | ((~b) & d);
168F = (b & c) | (b & d) | (c & d);
194 auto* sig =
newuint8_t[20];
195 for(uint8_t i = 0; i < 4; i++) {
196sig[i] = (h0 >> (24 - 8 * i)) & 0xFF;
197sig[i + 4] = (h1 >> (24 - 8 * i)) & 0xFF;
198sig[i + 8] = (h2 >> (24 - 8 * i)) & 0xFF;
199sig[i + 12] = (h3 >> (24 - 8 * i)) & 0xFF;
200sig[i + 16] = (h4 >> (24 - 8 * i)) & 0xFF;
211void*
hash(
conststd::string& message) {
212 return hash_bs(&message[0], message.size());
224std::cout <<
"Hashing empty string"<< std::endl;
229 "da39a3ee5e6b4b0d3255bfef95601890afd80709") == 0);
234std::cout <<
"Hashing The quick brown fox jumps over the lazy dog" 240 "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12") == 0);
246std::cout <<
"Hashing " 247 "The quick brown fox jumps over the lazy dog." 253 "408d94384216f890ff7a0c3528e8bed1e0b01621") == 0);
258 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
261 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" 267 "761c457bf73b14d27e9e9265c46f4b4dda11f940") == 0);
278std::cout <<
"Enter a message to be hashed (Ctrl-C to exit): " 280std::getline(std::cin, input);
285std::cout <<
"Want to enter another message? (y/n) ";
286std::getline(std::cin, input);
287 if(input.compare(
"y") == 0) {
289}
else if(input.compare(
"n") == 0) {
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4