Skip to content

Instantly share code, notes, and snippets.

@barangerbenjamin
Created October 10, 2019 16:42
Show Gist options
  • Save barangerbenjamin/af12136b37270640a3f545a847bbd3eb to your computer and use it in GitHub Desktop.
Save barangerbenjamin/af12136b37270640a3f545a847bbd3eb to your computer and use it in GitHub Desktop.
def acronymize(string)
string.split(" ").map { |word| word[0].upcase }.join
end
def encrypt(text)
alphabet = ('A'..'Z').to_a
new_string = ""
text.chars.each do |letter|
if alphabet.include?(letter)
letter_index = alphabet.index(letter)
new_string += alphabet[letter_index - 3]
else
new_string += letter
end
end
new_string
end
puts 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