From 2e74224508eeffdb65df4bd1fc2b8593e3a55b82 Mon Sep 17 00:00:00 2001 From: donmai-me <71143298+donmai-me@users.noreply.github.com> Date: Sun, 14 Nov 2021 17:51:00 +0800 Subject: [PATCH] Fix finale encrypt/decrypt --- CHANGELOG.md | 7 ++++++- maiconverter/cli.py | 4 ++-- maiconverter/maicrypt/maifinalecrypt.py | 6 ++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 736eb81..1c1813e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.14.1] - 2021-11-14 +### Fixed +- Fixed bugs in finale charts encrypt/decrypt. + ## [0.14.0] - 2021-11-14 ### Added - New time tracking functions: measure_to_second, second_to_measure, and quantise. @@ -42,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Ma2 to Sdt conversion and vice versa. - Simai to Sdt conversion and vice versa. -[Unreleased]: https://github.com/donmai-me/MaiConverter/compare/0.14.0...HEAD +[Unreleased]: https://github.com/donmai-me/MaiConverter/compare/0.14.1...HEAD +[0.14.1]: https://github.com/donmai-me/MaiConverter/compare/0.14.0...0.14.1 [0.14.0]: https://github.com/donmai-me/MaiConverter/compare/0.13.0...0.14.0 [0.13.0]: https://github.com/donmai-me/MaiConverter/compare/0.12.0...0.13.0 diff --git a/maiconverter/cli.py b/maiconverter/cli.py index 3674f85..b34b5df 100644 --- a/maiconverter/cli.py +++ b/maiconverter/cli.py @@ -216,11 +216,11 @@ def handle_file(input_path, output_dir, command, key): file_name = os.path.splitext(os.path.basename(input_path))[0] if command == "encrypt": file_ext = os.path.splitext(input_path)[1].replace("t", "b") - output = finale_file_encrypt(key, input_path) + output = finale_file_encrypt(input_path, key) else: file_ext = os.path.splitext(input_path)[1].replace("b", "t") - output = finale_file_decrypt(key, input_path) + output = finale_file_decrypt(input_path, key) with open(os.path.join(output_dir, file_name + file_ext), "wb") as f: f.write(output) diff --git a/maiconverter/maicrypt/maifinalecrypt.py b/maiconverter/maicrypt/maifinalecrypt.py index 33270e9..f1a6d8d 100644 --- a/maiconverter/maicrypt/maifinalecrypt.py +++ b/maiconverter/maicrypt/maifinalecrypt.py @@ -26,7 +26,9 @@ def finale_decrypt( ciphertext: bytes, ) -> bytes: if not isinstance(key, bytes): - key = int(key, 0).to_bytes(0x10, "big") + key = int(key.replace(" ", ""), 0).to_bytes(0x10, "big") + if len(key) != 0x10: + raise ValueError("Invalid key length") cipher = AES.new(key, AES.MODE_CBC, iv) gzipdata = cipher.decrypt(ciphertext) @@ -49,7 +51,7 @@ def finale_encrypt( plaintext: bytes, ) -> bytes: if not isinstance(key, bytes): - key = unhexlify(key.replace(" ", "")) + key = int(key.replace(" ", ""), 0).to_bytes(0x10, "big") if len(key) != 0x10: raise ValueError("Invalid key length")