ruby <3
def decrypt_caesar_cipher(s, shift) decrypter = (?a..?z).cycle.lazy.then { @1.zip(@1.drop(26 - shift)).take(26).to_h } decrypter.default_proc = -> { @1.fetch(@2.downcase, nil)&.upcase || @2 } s.each_char.inject('') { @1 + decrypter[@2] } end def brute_force_caesar_cipher(s) 0...26 |> to_h { [@1, decrypt_caesar_cipher(s, @1)] } end p decrypt_caesar_cipher('dwwdfn iurp wkh zrrgv dw gdzq', 3) pp brute_force_caesar_cipher('dwwdfn iurp wkh zrrgv dw gdzq')
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
ruby <3