Does anybody know of a way to decrypt a code if you know the code and password it was encoded with?
This is the code used to create the hash values
Code: Select all
var alpha="1qazxsw23edcvfr€45tgbnhy67ujm,ki89ol./;p0-['#]=!QAZXSW£EDCVFR$%TGBNHY^&UJM<KI*(OL>?:P)_{@~}+`¬ ";
function makehash(str,mult){ // makehash("doogle",6);
hash=0; // Output
for (j=0;j<str.length;j++) hash=hash*mult+alpha.indexOf(str.substring(j,j+1),0)+1; // Generate hash code, on first loop,
// hash is 0 so hash*mult is also 0.
return hash; // Return output
}
username = makehash("doogle",6);
username shows as 139402. What I'm wanting to do is take the '139402' and turn it back into 'doogle', but when I attempt to reverse the code, I'm at a loss as to how to get it to return text rather than numbers. Is it even possible?
This is the code to encrypt and decrypt the rest of the code that is encrypted with the hash codes created above...
Code: Select all
function encrypt(str,pass,enc){ // encrypt("username¬password¬etc","password hash","1");
var sc=""; // Output value
var cnt=0; // counter
if(str==null) return; // No string passed, leave function
for(k=0;k<str.length;k++){ // Loop through all characters in str
c=str.substring(k,k+1); // Grab current character from str
a=alpha.indexOf(c); // Grab position of this character in alpha string
// (ie the letter 'e' is character 9 in the string)
if(a>=0){ // Check if character exists in alpha string
if(enc){ // Encode the string
b=pass.substring(cnt,cnt+1)*1+a; // Grab first value from password hash and add
// the position of the current character. The *1 just ensures it is a numerical value
if(b>alpha.length-1) b=b-alpha.length; // Make sure that b stays within the bounds of the alpha string
}else{ // Decode the string
b=a-pass.substring(cnt,cnt+1); // Remove the first value of the password hash from the
// position of the current character
if(b<0) b=b+alpha.length; // Make sure that b stays within the bounds of the alpha string
}
if(b>alpha.length||b<0) // There are either too many or too few characters in the resulting string
alert("There has been an error with the encoding process.");
c=alpha.substring(b,b+1); // Replace the current character with one from the alpha string
(cnt<pass.length)? cnt=cnt+1 : cnt=0; // Check if counter has reached the password hash length, if not,
// add 1 to it, otherwise reset it to 0.
}
sc+=c; // Add this character to the final output, if the character doesn't exist in the alpha string, put it here in plain text.
}
return sc; // Return output
}