Skip to content

Instantly share code, notes, and snippets.

@csrutil
Last active April 19, 2025 05:58
Show Gist options
  • Save csrutil/25b26295080dbce9086fda48726c80c7 to your computer and use it in GitHub Desktop.
Save csrutil/25b26295080dbce9086fda48726c80c7 to your computer and use it in GitHub Desktop.
import sys
import hashlib
# Usage: xiaomi-purifier-pwd.py 04A03CAA1E7080
def getpwd(uid):
uid = bytearray.fromhex(uid)
h = bytearray.fromhex(hashlib.sha1(uid).hexdigest())
pwd = ""
pwd += "%02X" % h[h[0] % 20]
pwd += "%02X" % h[(h[0]+5) % 20]
pwd += "%02X" % h[(h[0]+13) % 20]
pwd += "%02X" % h[(h[0]+17) % 20]
return pwd
assert getpwd("04A03CAA1E7080") == "CD91AFCC"
assert getpwd("04112233445566") == "EC9805C8"
print("PWD:", getpwd(sys.argv[1]))
command = "1B%s,3008,A20800000000" % getpwd(sys.argv[1])
print("CMD:", command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment