Skip to content

Commit faf7682

Browse files
committed
park this for now
1 parent 387edb6 commit faf7682

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/library/general_library.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,4 +632,41 @@ function library.get_default_music_font_name()
632632
end
633633
end
634634

635+
--[[
636+
%crypt_musx_file_buffer
637+
638+
Symmetrical encryption/decryption for `.musx` files. Finale `.musx` files are byte-for-byte encrypted
639+
gzip archives. The archives contain xml and other data for the Finale document. This function accepts
640+
either a buffer of encrypted text and returns plaintext or accepts plaintext and returns encrypted text.
641+
642+
To decrypt a `.musx`,
643+
644+
- read the `.musx` file into a buffer using binary read mode
645+
- pass it to this function
646+
- save the return buffer as `.gz` using binary write mode
647+
648+
Reverse the process to create a `.musx` from a `.gz` file.
649+
650+
@ buffer (string) buffer of binary data containing plaintext or encrypted text of a `.musx` file.
651+
: (string) buffer of binary data containing encrypted text or plaintext corresponding to the input buffer.
652+
]]
653+
function library.crypt_musx_file_buffer(buffer)
654+
local state = 0x28006D45 -- this value was determined empirically
655+
local result = {}
656+
657+
for i = 1, #buffer do
658+
-- BSD rand()
659+
state = (state * 0x41c64e6d + 0x3039) & 0xFFFFFFFF -- Simulate 32-bit overflow
660+
local upper = state >> 16
661+
local c = upper + math.floor(upper / 255)
662+
663+
local byte = string.byte(buffer, i)
664+
byte = byte ~ (c & 0xFF) -- XOR operation on the byte
665+
666+
table.insert(result, string.char(byte))
667+
end
668+
669+
return table.concat(result)
670+
end
671+
635672
return library

0 commit comments

Comments
 (0)