Skip to content

Instantly share code, notes, and snippets.

@qpfiffer
Last active August 29, 2015 14:02
Show Gist options
  • Save qpfiffer/11b1551a05680adb65d2 to your computer and use it in GitHub Desktop.
Save qpfiffer/11b1551a05680adb65d2 to your computer and use it in GitHub Desktop.
Ported the hashing function from merveill.es to C, now we hunt for the mythological triple-six hash.
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define STRMAX 32
// Compile with: gcc -O3 -o 666 666.c
int hash_code(const char *str) {
int hash = 0;
size_t len = strnlen(str, STRMAX);
if (len == 0)
return hash;
int i = 0;
for (i = 0; i < len; i++) {
char char_at = str[i];
hash = ((hash<<5)-hash)+char_at;
}
return hash;
}
/* Ganked from here:
* http://stackoverflow.com/questions/440133/how-do-i-create-a-random-alpha-numeric-string-in-c
*/
void gen_random(char *s, const int len) {
static const char alphanum[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
int i;
for (i = 0; i < len; ++i) {
s[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
}
s[len] = 0;
}
int main() {
int i = 0;
char *uuid = NULL;
while(1) {
if (i % 1000000 == 0) {
printf("Iteration %i...\n", i);
}
char to_hash[STRMAX] = { 0 };
gen_random(to_hash, STRMAX);
int hash = hash_code(to_hash);
if (hash == 666) {
break;
}
i++;
}
printf("Hash found! uuid was %s\n", uuid);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment