Skip to content

Instantly share code, notes, and snippets.

@itsbth
Forked from anonymous/crack.rb
Created January 3, 2012 20:18
Show Gist options
  • Save itsbth/1556713 to your computer and use it in GitHub Desktop.
Save itsbth/1556713 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
if ?A.is_a? String
ab = (?A..?Z).to_a
else
ab = (?A..?Z).map {|c| c.chr}
end
n = $<.readline.to_i
str = $<.read
puts str.split('').map {|oc| c = oc.upcase; if ab.include? c then r = ab[(ab.index(c) - n) % ab.length]; c == oc ? r : r.downcase else c end }.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment