From: Adam Mulan Date: 2011-11-30T02:59:21+09:00 Subject: Ruby and ASCII matrix Hello, I have prepared the following code (it almost works for even size strings). I wanna create 2-chars vectors from ASCII codes and push them on the stack, then proceed by algebra functions (Hill cipher). I don't want use encryption library, because it's academic exercise (I can use any language). #!/usr/bin/env ruby require 'matrix' print "Message: " msg = gets.chomp # stack with matrices stack = [] # make matrix with column i = 0 column = [0, 0] msg.each_byte do |char| # create two-element vector column[0] = char if i == 0 if i == 1 column[1] = char # put vector on stack puts "Input data: #{column[0]}, #{column[1]}" tmp = Matrix[column[0], column[1]] puts "Output data: #{tmp[0,0]} #{tmp[0,1]}" stack.push(tmp) i = 0 next end i += 1 end The output data is invalid, i don't store input data in tmp Matrix class variable. Why? -- Posted via http://www.ruby-forum.com/.