Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- import struct
- from Crypto.Cipher import Blowfish #pip install pycrypto
- FILE_DIR = "files"
- OUT_DIR = "output"
- BLOCK_SIZE = 8
- for single in [FILE_DIR, OUT_DIR]:
- if not os.path.isdir(single):
- os.mkdir(single)
- player_key = "0d710d1d63ff36fe9bafd4c3874c64dd"
- world_key = "9ae3efe6a4debdeb8290eabd5f832ad4"
- def encrypt_player(dec_data, version = 24):
- bf = Blowfish.new(player_key, Blowfish.MODE_ECB)
- return struct.pack("<h", version) + bf.encrypt(dec_data)
- def decrypt_player(enc_data):
- bf = Blowfish.new(player_key, Blowfish.MODE_ECB)
- #might do something with this
- save_version = struct.unpack("<h", enc_data[:2])
- return bf.decrypt(enc_data[:2])
- def encrypt_world(dec_data, version = 24):
- bf = Blowfish.new(world_key, Blowfish.MODE_ECB)
- return struct.pack("<h", version) + bf.encrypt(dec_data)
- def decrypt_world(enc_data):
- bf = Blowfish.new(world_key, Blowfish.MODE_ECB)
- #might do something with this
- save_version = struct.unpack("<h", enc_data[:2])
- return bf.decrypt(enc_data[2:])
- argc = len(sys.argv)
- if argc == 3:
- mode = sys.argv[1]
- filename = sys.argv[2]
- load_path = os.path.join(FILE_DIR, filename)
- if os.path.isfile(load_path):
- save_file = open(load_path, "rb").read()
- (base_name, ext) = os.path.basename(filename).split(".", 1)
- if ext == "player":
- if mode == "encrypt":
- encrypted = encrypt_player(save_file)
- save_path = os.path.join(OUT_DIR, "enc-" + base_name + "." + ext)
- open(save_path, "wb").write(encrypted)
- elif mode == "decrypt":
- decrypted = decrypt_player(save_file)
- save_path = os.path.join(OUT_DIR, "dec-" + base_name + "." + ext)
- open(save_path, "wb").write(decrypted)
- else:
- print "Invalid Mode"
- elif ext == "world":
- if mode == "encrypt":
- encrypted = encrypt_world(save_file)
- save_path = os.path.join(OUT_DIR, "enc-" + base_name + "." + ext)
- open(save_path, "wb").write(encrypted)
- elif mode == "decrypt":
- decrypted = decrypt_world(save_file)
- save_path = os.path.join(OUT_DIR, "dec-" + base_name + "." + ext)
- open(save_path, "wb").write(decrypted)
- else:
- print "Invalid Mode"
- else:
- print "Invalid File Type"
- else:
- print "File Doesn't Exist"
- else:
- print "Usage: python terraria.py (encrypt/decrypt) (filename)"
Advertisement
Add Comment
Please, Sign In to add comment