Created
January 25, 2019 02:17
-
-
Save caioertai/3178f1879b002fd00cc3af03c8c32d4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def encrypter(sentence) | |
# Create an array of the alphabet | |
alphabet = ("A".."Z").to_a | |
# Break all the sentences | |
sentence_letters = sentence.split("") | |
# Set our encription key | |
key = -3 | |
# Use map to create one sentence | |
sentence_letters.map do |letter| | |
letter_index = alphabet.index(letter) | |
letter_index.nil? ? letter : alphabet[(letter_index + key) % alphabet.size] | |
# Join back | |
end.join | |
end | |
puts encrypter("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative './encrypter.rb' | |
describe '#encrypter' do | |
it 'returns an encrypted sentence' do | |
sentence = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG" | |
expected = "QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD" | |
actual = encrypter(sentence) | |
expect(actual).to eq(expected) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment