Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

288
Views
Jenkins one_at_a_time hash: tratando de hacer que Python Code reproduzca código JavaScript

Tomé prestado este código de otra publicación recientemente , y funciona muy bien para mis necesidades... Pero estoy tratando de reproducir los mismos resultados del código de Python para que las dos funciones del lenguaje coincidan, y he estado luchando... Estos dos hasta ahora NO producen los mismos resultados que necesito... Sospecho que es un problema con los enteros sin firmar en Python vs JavaScript.

Código JavaScript:

 //Credits (modified code): Bob Jenkins (http://www.burtleburtle.net/bob/hash/doobs.html) //See also: https://en.wikipedia.org/wiki/Jenkins_hash_function //Takes a string of any size and returns an avalanching hash string of 8 hex characters. function jenkinsOneAtATimeHash(keyString) { let hash = 0; for (charIndex = 0; charIndex < keyString.length; ++charIndex) { hash += keyString.charCodeAt(charIndex); hash += hash << 10; hash ^= hash >> 6; } hash += hash << 3; hash ^= hash >> 11; //4,294,967,295 is FFFFFFFF, the maximum 32 bit unsigned integer value, used here as a mask. return (((hash + (hash << 15)) & 4294967295) >>> 0).toString(16) };

código pitón:

 def calcuulateChecksum(keyString: str): # Credits(modified code): Bob Jenkins (http://www.burtleburtle.net/bob/hash/doobs.html) # See also: https://en.wikipedia.org/wiki/Jenkins_hash_function # Takes a string of any size and returns an avalanching hash string of 8 hex characters. hash = 0 # for (charIndex = 0; charIndex < keyString.length; ++charIndex): for char in keyString: hash += ord(char.encode("utf-8")) hash &= 0xFFFFFFFF hash += hash << 10 hash &= 0xFFFFFFFF hash ^= hash >> 6 hash &= 0xFFFFFFFF hash += hash << 3 hash &= 0xFFFFFFFF hash ^= hash >> 11 hash &= 0xFFFFFFFF hash += hash << 15 hash &= 0xFFFFFFFF # # 4,294,967,295 is 0xffffffff, the maximum 32 bit unsigned integer value, used here as a mask. return hex((hash & 4294967295))

Se agradecería cualquier ayuda para hacer que el código de Python coincida con la función de JavaScript... Por otro lado, creo que el código de Python coincide con los resultados que se muestran en la Wiki, entonces, ¿por qué no lo hace el código de JavaScript?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

TAL VEZ me acabo de dar cuenta de esto... simplemente no estoy seguro de por qué funciona... Si cambio el código JavaScript para usar solo cambios a la derecha sin firmar, parecería dar como resultado el mismo resultado que Python (y C original code) lo hace.... Tendré que hacer más pruebas en un rango de valores de keyString.

 function jenkinsOneAtATimeHash(keyString) { let hash = 0; for (charIndex = 0; charIndex < keyString.length; ++charIndex) { hash += keyString.charCodeAt(charIndex); hash += hash << 10; hash ^= hash >>> 6; } hash += hash << 3; hash ^= hash >>> 11; //4,294,967,295 is FFFFFFFF, the maximum 32 bit unsigned integer value, used here as a mask. return (((hash + (hash << 15)) & 4294967295) >>> 0).toString(16) };
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!