Hello,
I have prepared the following code (it works for even string
size for example “mamala”). I want 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. The data stored in tmp is invalid. Why?