generate_hash to util

This commit is contained in:
SpudGunMan
2025-11-06 12:00:16 -08:00
parent 39c9864682
commit 471e3ce145
2 changed files with 22 additions and 12 deletions

View File

@@ -16,22 +16,11 @@ from meshtastic.util import (
pskToString,
stripnl,
message_to_json,
channel_hash,
generate_hash,
)
logger = logging.getLogger(__name__)
def generate_hash(name: str, key: str) -> int:
"""generate the channel number by hashing the channel name and psk"""
if key == "AQ==":
key = "1PG7OiApB1nwvP+rz05pAQ=="
replaced_key = key.replace("-", "+").replace("_", "/")
key_bytes = base64.b64decode(replaced_key.encode("utf-8"))
h_name = channel_hash(bytes(name, "utf-8"))
h_key = channel_hash(key_bytes)
result: int = h_name ^ h_key
return result
class Node:
"""A model of a (local or remote) node in the mesh