Dir['e*.msg'].each do |msg_filename| file_msg = File.new(msg_filename, "rb") file_output= File.new(msg_filename + ".txt", "wb") file_msg.pos = 0x4A byte = file_msg.getc while byte != nil if byte == 0x03 len = file_msg.getc if len > 0 text = "" cipher = file_msg.read(len) key = 0x77 text << (cipher[0] ^ key) for i in 1..cipher.length-1 key = (key + ((i-1)*0x10 + 0x7)) % 0x100 if cipher[i] != key text << (cipher[i] ^ key) end end file_output.write(text + "\n") end end byte = file_msg.getc end file_msg.close file_output.close end