Created
February 3, 2012 12:35
-
-
Save abstraktor/1729967 to your computer and use it in GitHub Desktop.
rotX with ruby
This file contains 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
# 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 |
This file contains 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
# when working with encryptions prior ruby 1.9, you might want *ord* anyway | |
class String | |
def ord | |
unpack("C")[0] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example wont work with Ruby < 1.9 since String has no ord() there, maybe use unpack("C")[0] instead of ord().