Created
October 14, 2010 01:35
-
-
Save pheuter/625369 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def uncipher(str) | |
1.upto(26) do |shift| | |
key = Hash[('a'..'z').zip((97..122).collect{ |i| if (i+shift > 122) then ((i + shift) % 122) + 96 else i+shift end })].merge({' '=>' '.ord,','=>','.ord,'.'=>'.'.ord,'?'=>'?'.ord,'!'=>'!'.ord}) | |
freqs = Hash.new(0) | |
tmp = str.split('').collect { |letter| switched = (key[letter]).chr; freqs[switched] += 1; switched } | |
total = 0 | |
freqs.each { |e| total += e[1] } | |
puts tmp.join if freqs['e']/total.to_f * 100 > 7 and freqs['t']/total.to_f * 100 > 5 # Might want to eventually make more accomodating | |
end | |
end | |
uncipher(gets.chomp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment