The code underneath is meant to look trough Strings that have the same hashvalue as “golf” yet it starts at 1 charachter, then goes up to 2, then 3 and then 4… I want the code to start at 4 instead of going up trough 1 tot 3.
The reason I want this is because I want to use this code to find hashes of stringlength 10+… it would take too much time to go trough 1 to 9 stringlengths.
const fs = require('fs')
hashCode = function(s) {
var h= 0, l = s.length, i = 0;
if ( l > 0 )
while (i<l)
h = (h << 5) - h + s.charCodeAt(i++) | 0;
return h;
}
var crackableSeedInt = hashCode("golf")
// Javascript program for the above approach
//
// Function to generate permutations of
// at most X elements from array arr[]
function differentFlagPermutations(X, arr)
{
let ml = [];
ml = arr;
for(let i = 0; i < ml.length; i++)
{
//console.log(ml[i] + " ")
//document.write(ml[i] + " ");
}
let count2 = 0
let count = ml.length;
// Traverse all possible lengths
for(var z = 0; z < X - 1; z++)
{
// Stores all combinations
// of length z
let tmp = [];
// Traverse the array
for(let i = 0; i < arr.length; i++)
{
for(let k = 0; k < ml.length; k++)
{
if (arr[i] != ml[k])
{
// Generate all
// combinations of length z
tmp.push(ml[k] + arr[i]);
count += 1;
}
}
}
// Print all combinations of length z
for(let i = 0; i < tmp.length; i++)
{
//console.log(tmp[i] + " ")
var testInt = hashCode(tmp[i])
count2 += 1
var length = tmp[i].length
console.log(count2 + " > " + length + " > " + tmp[i] + ' > ' + testInt)
if (crackableSeedInt == testInt) {
var data = String(tmp[i] + ' > ' + crackableSeedInt + ' > ' + testInt + "n")
fs.appendFileSync('Output.txt', data, (err) => {
console.log(err)
// In case of a error throw err.
if (err) throw err;
})
}
//document.write(tmp[i] + " ");
}
// Replace all combinations of length z - 1
// with all combinations of length z
ml = tmp;
}
}
// Given array
//let arr = [" ","=","&",".","z","y","x","w","v","u","t","s","r","q","p","o","n","m","l","k","j","i","h","g","f","e","d","c","b","a"]
//let arr = ["b","a"]
let arr = ["a","b","c","d","e","f","g","h","i","j","k","l","m","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","&","="," "];
// Given X
let X = 4;
differentFlagPermutations(X, arr);
// count += 1
// var testInt = hashCode(randomstring)
// console.log(count + ' > ' + randomstring + ' > ' + testInt)
// if (crackableSeedInt == testInt) {
// console.log("Found a seed")
// var data = String(tmp[i] + ' > ' + crackableSeedInt + ' > ' + testInt + "n")
// fs.appendFileSync('Output.txt', data, (err) => {
// console.log(err)
//
// // In case of a error throw err.
// if (err) throw err;
// })
// }
//setInterval(differentFlagPermutations,0)