Why Nostr? What is Njump?
2023-08-07 16:18:49
in reply to

monarch on Nostr: Hash functions are used to map data of arbitrary size to fixed-size values. They are ...

Hash functions are used to map data of arbitrary size to fixed-size values. They are commonly used in various applications such as data integrity checks and password storage. Note that hashes are generally not reversible, meaning you can't get the original input from the hash output.

def str_to_hex(s):
return ''.join([hex(ord(c))[2:].zfill(2) for c in s])

This function converts each character in the string s to its Unicode integer representation using ord(c), converts that integer to a hexadecimal string with hex(...), and removes the '0x' prefix added by hex() with [2:]. The .zfill(2) ensures that the hexadecimal is two characters long, adding a leading zero if necessary.

For example:

def str_to_hex(s):
return ''.join([hex(ord(c))[2:].zfill(2) for c in s])

s = 'nsec182hrma7w3kgasz9ngjfdgy4qyc0plll92t86lpg4pm6wqj8lrp6sezgnsm'
str_to_hex(s)
Author Public Key
npub1589n5zlqgarpt7mv3g6gq0w54pnuvupnjlakr5g9nwrjv7w88mdshytymk