Skip to content

Instantly share code, notes, and snippets.

@Andoryuuta
Created May 5, 2019 20:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andoryuuta/7e5c26f9d19ea10d18937f938286ecfa to your computer and use it in GitHub Desktop.
Save Andoryuuta/7e5c26f9d19ea10d18937f938286ecfa to your computer and use it in GitHub Desktop.
import sys
import os
# Check if we have an argument.
if(len(sys.argv) <= 1):
print('Usage: {} file.dyn'.format(sys.argv[0]))
sys.exit(1)
# File names
input_filename = sys.argv[1]
output_filename = os.path.splitext(input_filename)[0] + '.zip'
# XOR key and shuffle index arrays for decryption.
CHUNK_SIZE = 8
key = bytearray([(0x8D + i) for i in range(CHUNK_SIZE)])
indices = [5, 3, 6, 7, 4, 2, 0, 1]
# Decrypt...
with open(input_filename, 'rb') as input_file, open(output_filename, 'wb') as output_file:
while True:
# Read in a chunk of raw data
chunk = input_file.read(CHUNK_SIZE)
if not chunk:
break
# Need a full 8-byte chunk to decrypt.
if(len(chunk) == CHUNK_SIZE):
output = bytearray(CHUNK_SIZE)
# Decrypt the chunk.
for i in range(CHUNK_SIZE):
output[i] = chunk[indices[i]] ^ key[i]
else:
output = chunk
output_file.write(output)
print('Done.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment