Skip to content

Instantly share code, notes, and snippets.

@freddyb2
Last active January 26, 2025 14:51
Show Gist options
  • Save freddyb2/f79fdca7ba9b854a889108c8a6dc4280 to your computer and use it in GitHub Desktop.
Save freddyb2/f79fdca7ba9b854a889108c8a6dc4280 to your computer and use it in GitHub Desktop.
key = ['f', 'c', 's', 'c']
message = "Gqfltwj emgj clgfv ! Aqltj rjqhjsksg ekxuaqs, ua xtwk n'feuguvwb gkwp xwj, ujts f'npxkqvjgw nw tjuwcz ugwygjtfkf qz uw efezg sqk gspwonu. Jgsfwb-aqmu f Pspygk nj 29 cntnn hqzt dg igtwy fw xtvjg rkkunqf.".downcase.chars
alphabetic_chars = ('a'..'z').to_a
index = 0
clear_message = ""
message.each do |char|
if alphabetic_chars.include?(char)
key_index = index % key.count
key_letter = key[key_index]
clear_index = char.ord-key_letter.ord
clear_letter = alphabetic_chars[clear_index]
clear_message += clear_letter.chr
index += 1
else
clear_message += char
end
end
puts clear_message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment