Onionr/scripts/generate-onions.py

23 lines
544 B
Python
Raw Normal View History

2020-10-24 16:50:25 +00:00
#!/usr/bin/env python3
import sys
import os
2021-02-02 23:24:35 +00:00
from base64 import b32encode
from hashlib import sha3_256
2020-10-24 16:50:25 +00:00
2020-10-25 04:12:42 +00:00
try:
2021-02-02 23:24:35 +00:00
amount = int(sys.argv[1])
2020-10-25 04:12:42 +00:00
except IndexError:
2021-02-02 23:24:35 +00:00
amount = 1
2020-10-25 04:12:42 +00:00
2021-02-02 23:24:35 +00:00
version = int(3).to_bytes(1, "little")
for i in range(amount):
pubkey = os.urandom(32)
#digest = sha3_256(b".onion checksum" + pubkey + version).digest()[:2]
digest = sha3_256()
digest.update(b".onion checksum")
digest.update(pubkey)
digest.update(version)
digest = digest.digest()[:2]
print(b32encode(pubkey + digest + version).decode().lower() + ".onion")