2023-05-13 21:25:27 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
from pathlib import Path
|
2023-05-14 08:11:27 +00:00
|
|
|
from sys import argv
|
2023-05-13 21:25:27 +00:00
|
|
|
|
2023-06-03 02:55:17 +00:00
|
|
|
from lib.encdec import eprint, encrypt, decrypt
|
2023-05-13 21:25:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
def usage(info = None):
|
|
|
|
if info:
|
2023-05-14 07:18:12 +00:00
|
|
|
eprint(info)
|
|
|
|
eprint(f'Usage: {argv[0]} <e|d> filename.bin > raw.bin')
|
|
|
|
eprint(f' Example decode: {argv[0]} d k5_26_encrypted.bin > k5_26_raw.bin')
|
|
|
|
eprint(f' Example encode: {argv[0]} e k5_26_raw.bin > k5_26_encrypted.bin')
|
2023-05-13 21:25:27 +00:00
|
|
|
exit(128)
|
|
|
|
|
2023-05-14 07:18:12 +00:00
|
|
|
|
2023-05-13 21:25:27 +00:00
|
|
|
def main():
|
2023-05-16 11:33:04 +00:00
|
|
|
if len(argv) == 3:
|
|
|
|
mode = argv[1]
|
|
|
|
file_bytes = Path(argv[2]).read_bytes()
|
|
|
|
|
|
|
|
if mode == 'd':
|
2023-06-03 02:55:17 +00:00
|
|
|
decrypted, version = decrypt(file_bytes)
|
|
|
|
eprint('version:', version)
|
|
|
|
os.write(1, decrypted)
|
2023-05-16 11:33:04 +00:00
|
|
|
eprint('Success!')
|
|
|
|
return
|
|
|
|
|
|
|
|
if mode == 'e':
|
|
|
|
os.write(1, encrypt(file_bytes))
|
|
|
|
eprint('Success!')
|
|
|
|
return
|
2023-05-13 21:25:27 +00:00
|
|
|
|
|
|
|
usage()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|