Skip to content

Commit f6f1b74

Browse files
committed
1 parent d2d9c03 commit f6f1b74

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

meshtastic/node.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ def xor_hash(data: bytes) -> int:
2727
result ^= char
2828
return result
2929

30-
def generate_hash(name: str, key_bytes: bytes) -> int:
31-
"""Generate the channel number by hashing the channel name and psk bytes."""
32-
# If key_bytes is the default "AQ==", use the fallback key
33-
if base64.b64encode(key_bytes).decode("utf-8") == "AQ==":
34-
key_bytes = base64.b64decode("1PG7OiApB1nwvP+rz05pAQ==")
35-
h_name = xor_hash(name.encode("utf-8"))
30+
def generate_hash(name: str, key: str) -> int:
31+
"""generate the channel number by hashing the channel name and psk"""
32+
if key == "AQ==":
33+
key = "1PG7OiApB1nwvP+rz05pAQ=="
34+
replaced_key = key.replace("-", "+").replace("_", "/")
35+
key_bytes = base64.b64decode(replaced_key.encode("utf-8"))
36+
h_name = xor_hash(bytes(name, "utf-8"))
3637
h_key = xor_hash(key_bytes)
37-
return h_name ^ h_key
38+
result: int = h_name ^ h_key
39+
return result
3840

3941
class Node:
4042
"""A model of a (local or remote) node in the mesh

0 commit comments

Comments
 (0)