Skip to content

Instantly share code, notes, and snippets.

@whitehat101
Created August 22, 2016 22:07
Show Gist options
  • Save whitehat101/30525b7478b01f609352b3833188ef28 to your computer and use it in GitHub Desktop.
Save whitehat101/30525b7478b01f609352b3833188ef28 to your computer and use it in GitHub Desktop.
Print all 26 iterations of Carsar's Chiper for a string
# some credit: https://gist.github.com/matugm/db363c7131e6af27716c
# Print all 26 iterations of Carsar's Chiper for a string
def caesar_cipher(string, shift = 1)
alphabet = Array('a'..'z')
non_caps = Hash[alphabet.zip(alphabet.rotate(-shift))]
alphabet = Array('A'..'Z')
caps = Hash[alphabet.zip(alphabet.rotate(-shift))]
encrypter = non_caps.merge(caps)
string.chars.map { |c| encrypter.fetch(c, c) }.join
end
def crack str
(1..26).each do |n|
puts "#{'%2d:'%n} #{caesar_cipher str, n}"
end
end
# crack "xc bpzxcv iwt exirw ndj"
# 1: wb aoywbu hvs dwhqv mci
# 2: va znxvat gur cvgpu lbh
# 3: uz ymwuzs ftq bufot kag
# 4: ty xlvtyr esp atens jzf
# 5: sx wkusxq dro zsdmr iye
# 6: rw vjtrwp cqn yrclq hxd
# 7: qv uisqvo bpm xqbkp gwc
# 8: pu thrpun aol wpajo fvb
# 9: ot sgqotm znk vozin eua
# 10: ns rfpnsl ymj unyhm dtz
# 11: mr qeomrk xli tmxgl csy
# 12: lq pdnlqj wkh slwfk brx
# 13: kp ocmkpi vjg rkvej aqw
# 14: jo nbljoh uif qjudi zpv
# 15: in making the pitch you ***
# 16: hm lzjhmf sgd ohsbg xnt
# 17: gl kyigle rfc ngraf wms
# 18: fk jxhfkd qeb mfqze vlr
# 19: ej iwgejc pda lepyd ukq
# 20: di hvfdib ocz kdoxc tjp
# 21: ch guecha nby jcnwb sio
# 22: bg ftdbgz max ibmva rhn
# 23: af escafy lzw haluz qgm
# 24: ze drbzex kyv gzkty pfl
# 25: yd cqaydw jxu fyjsx oek
# 26: xc bpzxcv iwt exirw ndj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment