Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@AaronRandall
Created July 31, 2016 21:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AaronRandall/34ace41bcadf8fe2ca2bb2e22816dcca to your computer and use it in GitHub Desktop.
Save AaronRandall/34ace41bcadf8fe2ca2bb2e22816dcca to your computer and use it in GitHub Desktop.
ciphertexts = [
"VGYURYPEDFNCEPGEWELLPVNWRDCNFGMGXQEPPRG-CBFIGLEMG",
"EQ’PMEIGQNVBAGBTFEGMSYNRKMNWEPBLWBYPSNWMQNFBDWEQVYNR-CBFIGLEMG"
]
cipher_keys = "CBFIGLEMGQPRXWYNVDUATSK"
key_mappings = "MARCELINETSUXWYOHPGVFDK"
known_keys = cipher_keys.chars
all_keys = ("A".."Z").to_a
unknown_keys = (all_keys - known_keys)
ciphertexts.each do |ciphertext|
ciphertext_before = ciphertext
ciphertext_after = ciphertext.tr(cipher_keys, key_mappings)
ciphertext_known_keys = ciphertext.tr(unknown_keys.join, "_").tr(cipher_keys, key_mappings)
puts "Ciphertext before: #{ciphertext_before}"
puts "Ciphertext after: #{ciphertext_after}"
puts "Ciphertext known keys: #{ciphertext_known_keys}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment