Skip to content

Commit

Permalink
Fix finale encrypt/decrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
donmai-me committed Nov 14, 2021
1 parent b28321f commit 2e74224
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions maiconverter/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions maiconverter/maicrypt/maifinalecrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")

Expand Down

0 comments on commit 2e74224

Please sign in to comment.