brewersfan1976

cipher26.rb

Oct 14th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.62 KB | None | 0 0
  1. def cipher26(message)
  2.     x = 1
  3.     y = 0
  4.     characters = Array.new
  5.     characters = ('a'..'z').to_a
  6.     output = message[0]
  7.     first_value = message[0].ord - 'a'.ord
  8.     amount = first_value
  9.    
  10.     while (x < message.length)
  11.           while (true)
  12.                 if (amount + y) % 26 == message[x].ord - 'a'.ord then
  13.                    output = output + characters[y]
  14.                    amount = amount + y
  15.                    break
  16.                 end
  17.                    
  18.                 y = y + 1
  19.           end
  20.              
  21.           x = x + 1
  22.           y = 0
  23.     end
  24.        
  25.     return output
  26. end
Advertisement
Add Comment
Please, Sign In to add comment