Created
April 16, 2012 10:14
-
-
Save enukane/2397509 to your computer and use it in GitHub Desktop.
mahoyo-bgm.xp3-ogg-decoder : not working yet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fname = "m01s.ogg" | |
outfname = "unenc-m01s.ogg" | |
file = open(fname, "rb") | |
p "Processing #{fname}" | |
def decode_xor key, value | |
origin = 0 | |
offset = 1 | |
8.times do | |
if key & offset != 0 then | |
origin = origin | ((value & offset) ^ offset) | |
else | |
origin = origin | (value & offset) | |
end | |
offset = offset << 1 | |
end | |
return origin | |
end | |
ary = [] | |
5.times do | |
ary << file.getc | |
end | |
p "KEY is #{ary[4]}" | |
key = ary[4].to_i | |
ary.each do |item| | |
p "#{item} => #{decode_xor(key, item.to_i).chr}" | |
end | |
file.pos = 0 | |
p "set pos to #{file.pos}" | |
data = [] | |
while ch = file.getc | |
data << decode_xor(key, ch.to_i).chr | |
end | |
p "#{outfname} processing" | |
open(outfname, "wb") do |file| | |
data.each do |ch| | |
file.putc ch | |
end | |
end | |
p "#{outfname} done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment