Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

205
Visualizações
JS Hash Function Reversal?

I have this function that I found to hash a string, I have been attempting for some hours now to reverse this function to take the hash and return the string. I am not too familiar with left and right shifts, what exactly do they do in the case of this function and would reversing it be even possible? I have used the string "luxor" for my tests and I get "250B0C5E" as the hash but have been unable to get a string back that matches "luxor". I have attempted switching the shifts from left to right and moving the charcodeat but still no success.

function HashString(command) {
    let hash = 0;
    let string = command.toLowerCase();
    for(let i=0; i < string.length; i++) {
        let letter = string[i].charCodeAt();
        hash = hash + letter;
        hash += (hash << 10 >>> 0);
        hash ^= (hash >>> 6);
        hash = hash >>> 0
    }

    hash += (hash << 3);
    if (hash < 0) {
        hash = hash >>> 0
    }
    hash ^= (hash >>> 11);
    hash += (hash << 15);
    if (hash < 0) {
        hash = hash >>> 0
    }
    return hash.toString(16).toUpperCase();
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can't.

Hashing is a one-way process. When it's a two-way process, it's encryption/decryption. They have very different uses.

This is just a hash function. It takes a string (a series of 16-bit values) and produces a single number (an IEEE-754 double-precision floating point value, a "double") which it then turns into a hex string. But in places during that process, the value is reduced to 32 bits because of the bit shift operators, which convert the double to a 32-bit two's complement integer before doing their work, then convert it back to an equivalent double.

You can't reverse that process, it's lossy (it loses information). There isn't room in a 32-bit value to store the information needed to replicate a string of 16-bit values of any length; it could handle two chars without being lossy, or four if you limit the range to chars where the upper byte of the 16-bit value is 0, but that's it.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda