Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Akenori
- class << self
- def encode(file_to_encode)
- i = 0
- File.readlines(file_to_encode).each do |line|
- ar = (line.gsub("\n",'').gsub(" ",'').split("\t")).drop(1)
- if !ar[0].nil?
- ar[0] = ar[0].to_i
- ar[1] = ar[1].to_i
- ar[2] = ar[2].to_i
- ar[3] = (ar[3].to_f * 100000).to_i
- ar[4] = (ar[4].to_f * 100000).to_i
- contents = IO.binwrite("#{file_to_encode.gsub(".txt",'.bin')}",ar.pack("LLLLL"),i+20)
- i += 20
- end
- end
- end
- def decode(file_to_decode)
- rec = []
- f = File.open("#{file_to_decode.gsub(".bin",'.txt')}", "w+")
- float_point = 100000
- length = File.stat("#{file_to_decode}").size?.to_i - 20
- i = 0
- while i < length do
- contents = IO.binread("#{file_to_decode}",i,i+20)
- if i != 0
- decoded_string = [contents.unpack("LLLLL")[0],"\t",contents.unpack("LLLLL")[1],"\t",contents.unpack("LLLLL")[2],"\t",'%.5f' % (contents.unpack("LLLLL")[3].to_f/float_point),"\t",'%.5f' % (contents.unpack("LLLLL")[4].to_f/float_point),"\n"]
- ( rec << contents.unpack("LLLLL") && f << (decoded_string*",").gsub(",",'') ) if !contents.nil?
- end
- i += 20
- end
- f.close
- return rec
- end
- end
- end
- unless ARGV.empty?
- if ARGV[0] == '-d'
- p "Decode #{ARGV[1]}"
- Akenori.decode(ARGV[1])
- elsif ARGV[0] == '-e'
- p "Encode #{ARGV[1]}"
- Akenori.encode(ARGV[1])
- end
- else
- p "No arguments given. Use -d filename to decode or -e filename to encode"
- p "Example: ruby akenori.rb -d SjSDU.bin"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement