Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. class Akenori
  2.  
  3. class << self
  4.  
  5. def encode(file_to_encode)
  6. i = 0
  7. File.readlines(file_to_encode).each do |line|
  8. ar = (line.gsub("\n",'').gsub(" ",'').split("\t")).drop(1)
  9. if !ar[0].nil?
  10. ar[0] = ar[0].to_i
  11. ar[1] = ar[1].to_i
  12. ar[2] = ar[2].to_i
  13. ar[3] = (ar[3].to_f * 100000).to_i
  14. ar[4] = (ar[4].to_f * 100000).to_i
  15. contents = IO.binwrite("#{file_to_encode.gsub(".txt",'.bin')}",ar.pack("LLLLL"),i+20)
  16. i += 20
  17. end
  18. end
  19. end
  20.  
  21. def decode(file_to_decode)
  22. rec = []
  23. f = File.open("#{file_to_decode.gsub(".bin",'.txt')}", "w+")
  24. float_point = 100000
  25. length = File.stat("#{file_to_decode}").size?.to_i - 20
  26. i = 0
  27. while i < length do
  28. contents = IO.binread("#{file_to_decode}",i,i+20)
  29. if i != 0
  30. 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"]
  31. ( rec << contents.unpack("LLLLL") && f << (decoded_string*",").gsub(",",'') ) if !contents.nil?
  32. end
  33. i += 20
  34. end
  35. f.close
  36. return rec
  37. end
  38.  
  39. end
  40.  
  41. end
  42.  
  43. unless ARGV.empty?
  44. if ARGV[0] == '-d'
  45. p "Decode #{ARGV[1]}"
  46. Akenori.decode(ARGV[1])
  47. elsif ARGV[0] == '-e'
  48. p "Encode #{ARGV[1]}"
  49. Akenori.encode(ARGV[1])
  50. end
  51. else
  52. p "No arguments given. Use -d filename to decode or -e filename to encode"
  53. p "Example: ruby akenori.rb -d SjSDU.bin"
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement