Skip to content

Instantly share code, notes, and snippets.

@elcortez
Created April 11, 2019 16:42
Show Gist options
  • Select an option

  • Save elcortez/5d4cf7932422203150146564b2e848ab to your computer and use it in GitHub Desktop.

Select an option

Save elcortez/5d4cf7932422203150146564b2e848ab to your computer and use it in GitHub Desktop.
def encrypt(text)
alphabet = ("A".."Z").to_a
text.split(' ').map do |word|
word.split('').map do |letter|
position = alphabet.index(letter)
new_position = position - 3
alphabet[new_position]
end.join('')
end.join(' ')
end
p encrypt("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG")
p encrypt("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG") == "QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment