Skip to content

Instantly share code, notes, and snippets.

@saswata-dutta
Last active July 24, 2022 14:55
Show Gist options
  • Save saswata-dutta/47167449b0f89045439bbb977801ab74 to your computer and use it in GitHub Desktop.
Save saswata-dutta/47167449b0f89045439bbb977801ab74 to your computer and use it in GitHub Desktop.
string to int mapping using md5
bs = hashlib.md5("Apple".encode('utf-8')).digest()
# b'\x9fb\x90\xf4CnZ#Q\xf1.\x03\xb6C<<'

int.from_bytes(bs[:4], 'big', signed=True)
# -1620930316
val md5 = MessageDigest.getInstance("MD5")
val bs = md5.digest("Apple".getBytes(java.nio.charset.StandardCharsets.UTF_8))
// val bs: Array[Byte] = Array(-97, 98, -112, -12, 67, 110, 90, 35, 81, -15, 46, 3, -74, 67, 60, 60)

java.nio.ByteBuffer.wrap(bs).order(java.nio.ByteOrder.BIG_ENDIAN).getInt()
// -1620930316
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment