Skip to content

Instantly share code, notes, and snippets.

@m-1-k-3
Forked from ryancdotorg/decrypt.py
Created December 23, 2021 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m-1-k-3/86ad277ac3875044d58bd10848462c29 to your computer and use it in GitHub Desktop.
Save m-1-k-3/86ad277ac3875044d58bd10848462c29 to your computer and use it in GitHub Desktop.
Decrypt firmware images for (some) EnGenius devices
#!/usr/bin/env python3
import sys
key = b'\xac\x78\x3c\x9e\xcf\x67\xb3\x59'
filename = sys.argv[1]
def decrypter(reference):
n = len(key)
def decrypt(value, offset):
nonlocal n, reference
return value ^ key[(offset-reference)%n]
return decrypt
with open(filename, 'rb') as f:
s = bytearray(f.read())
n = s[0x87]
d = n + 0x88
end = len(s)
decrypt = decrypter(s.find(key))
sys.stdout.buffer.write(bytes(s[0:d]))
while d < end:
stop = min(d + 4096, end)
for offset in range(d, stop):
s[offset] = decrypt(s[offset], offset)
sys.stdout.buffer.write(bytes(s[d:stop]))
d = stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment