Skip to content

Instantly share code, notes, and snippets.

@Pita
Created January 4, 2012 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pita/1559765 to your computer and use it in GitHub Desktop.
Save Pita/1559765 to your computer and use it in GitHub Desktop.
v8 hash collision brute force
#include <stdio.h>
#include <string.h>
int v8hash(char *str, int length){
int hash = 0, i=0;
for(;i<length;i++){
hash += str[i];
hash += (hash << 10);
hash ^= (hash >> 6);
}
return hash;
}
void crack(char *str, int length, int minLength, int maxLength, int searchedHash, int basisHash){
char newStr[10];
int i=0, hash,newLength = length+1;
/*copy the string and add a null*/
strncpy(newStr, str, length);
newStr[newLength] = '\0';
for(i=32;i<127;i++){
/* add a new character */
newStr[length] = i;
/* hash recursive */
hash = basisHash;
hash += i;
hash += (hash << 10);
hash ^= (hash >> 6);
/* check if we have reached the minLength */
if(newLength > minLength){
/* check if we have found a collision */
if(hash == searchedHash){
printf("'%s'\n",newStr);
fflush(stdout);
}
}
/* recursive */
if(newLength < maxLength){
crack(newStr, newLength, minLength, maxLength, searchedHash, hash);
}
}
}
int main(void)
{
int searchedHash = v8hash("hash", 4);
int i = 0;
for(i=0;i<8;i++){
printf("# %d characters\n",i+1);
fflush(stdout);
crack("",0,i,i+1,searchedHash,0);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment