import sys from binascii import hexlify, unhexlify import Crypto.Cipher.ARC4 from hashlib import md5 encoded = "Kunal".encode("utf-16le") hashed = md5(encoded).digest() key = hashed[:5] + 11 * b'\x00' # hardcoded key #key = b'9d62e7dd580000000000000000000000' #key = unhexlify(key) #print(key) def main(): if sys.argv[1] == "d": decrypt(sys.argv[2], sys.argv[3]) elif sys.argv[1] == "e": encrypt(sys.argv[2], sys.argv[3]) def encrypt(file_in, file_out): with open(file_in, 'rb') as file: data = file.read() # Decrypt the data text = data.decode("utf-8").encode("utf-16le") encrypted = Crypto.Cipher.ARC4.new(key).encrypt(text) with open(file_out, 'wb') as file: file.write(b'\xff\xfe') file.write(encrypted) def decrypt(file_in, file_out): # skip the first 2 bytes and read the beginning with open(file_in, 'rb') as file: file.seek(2) data = file.read() # Decrypt the data decrypted = Crypto.Cipher.ARC4.new(key).encrypt(data) text = decrypted.decode("utf-16le").encode("utf-8") with open(file_out, 'wb') as file: file.write(text) if __name__ == "__main__": main()