Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def cesaer_cipher string, shift_number
- alphabet_lower = %w[a b c d e f g h i j k l m n o p q r s t u v w x y z]
- phrase_array = string.chars
- final_encode = []
- shifted_alphabet = alphabet_lower[-shift_number..-1]
- 0.upto(alphabet_lower.length - shift_number -1) do |index|
- shifted_alphabet << alphabet_lower[index]
- end
- 0.upto(phrase_array.size - 1) do |letter|
- 0.upto(alphabet_lower.size - 1) do |symbol|
- if phrase_array[letter] == alphabet_lower[symbol]
- final_encode.push(shifted_alphabet[symbol])
- break
- elsif phrase_array[letter] == alphabet_lower[symbol].capitalize
- final_encode.push(shifted_alphabet[symbol].capitalize)
- break
- else
- final_encode.push(phrase_array[symbol])
- break
- end
- end
- end
- return final_encode
- end
- cipher = cesaer_cipher 'I am going to', 3
- puts cipher
Advertisement
Add Comment
Please, Sign In to add comment