Skip to content

Instantly share code, notes, and snippets.

@abstraktor
Created February 3, 2012 12:35
Show Gist options
  • Save abstraktor/1729967 to your computer and use it in GitHub Desktop.
Save abstraktor/1729967 to your computer and use it in GitHub Desktop.
rotX with ruby
# when you guessed a letter
# rotate("ammi://zbmanu.vhf/tulmktdmhk", "h".ord - "a".ord)
def rotate(str, num)
str.chars.map{|c| (c.ord<97) ? c: ((c.ord+num - 97)%26 + 97).chr}.join("")
end
# when working with encryptions prior ruby 1.9, you might want *ord* anyway
class String
def ord
unpack("C")[0]
end
end
@cmur2
Copy link

cmur2 commented Feb 3, 2012

Example wont work with Ruby < 1.9 since String has no ord() there, maybe use unpack("C")[0] instead of ord().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment