Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def read_lines
- i = gets.split(' ').map(&:to_i)
- array = []
- 1.upto i[0] do
- line = gets.chomp.split(' ')
- array.push(line)
- end
- return array, i
- end
- def rotate_alphabet(n)
- alphabet = Array('A'..'Z')
- encrypted_alphabet = Hash[alphabet.zip(alphabet.rotate(n[1]))]
- end
- def caesar_shift_cipher(alphabet, lines)
- alphabet = alphabet.invert
- answer = []
- lines = lines.map{ |x| x }
- lines.each do |line|
- line = line.to_s
- crypted = line.chars.map { |a| alphabet.fetch(a, ' ') }
- crypted = crypted.reject {|x| x.empty?}
- answer.push(crypted)
- end
- answer
- end
- line = read_lines
- encryptor = rotate_alphabet(line[1])
- answer = caesar_shift_cipher(encryptor, line[0])
- puts answer.join('')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement