mirror of
https://github.com/meshtastic/python.git
synced 2026-08-02 10:07:06 -04:00
hashGen fix
using from https://raw.githubusercontent.com/pdxlocations/mudp/refs/heads/main/mudp/encryption.py @pdxlocations
This commit is contained in:
@@ -27,14 +27,16 @@ def xor_hash(data: bytes) -> int:
|
|||||||
result ^= char
|
result ^= char
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def generate_hash(name: str, key_bytes: bytes) -> int:
|
def generate_hash(name: str, key: str) -> int:
|
||||||
"""Generate the channel number by hashing the channel name and psk bytes."""
|
"""generate the channel number by hashing the channel name and psk"""
|
||||||
# If key_bytes is the default "AQ==", use the fallback key
|
if key == "AQ==":
|
||||||
if base64.b64encode(key_bytes).decode("utf-8") == "AQ==":
|
key = "1PG7OiApB1nwvP+rz05pAQ=="
|
||||||
key_bytes = base64.b64decode("1PG7OiApB1nwvP+rz05pAQ==")
|
replaced_key = key.replace("-", "+").replace("_", "/")
|
||||||
h_name = xor_hash(name.encode("utf-8"))
|
key_bytes = base64.b64decode(replaced_key.encode("utf-8"))
|
||||||
|
h_name = xor_hash(bytes(name, "utf-8"))
|
||||||
h_key = xor_hash(key_bytes)
|
h_key = xor_hash(key_bytes)
|
||||||
return h_name ^ h_key
|
result: int = h_name ^ h_key
|
||||||
|
return result
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
"""A model of a (local or remote) node in the mesh
|
"""A model of a (local or remote) node in the mesh
|
||||||
|
|||||||
Reference in New Issue
Block a user