Reputation: 102
Can anyone help me to write a method which takes 2 parameters (one string and one number). the method should return the string encrypted with the given number.
For Example:
My String: ABCDE My Number: 3 Output Should Be: DEFGH
Note: String and Number are not constant.
Upvotes: 0
Views: 73
Reputation: 6255
s = "ABCDE"
n = 3
s.chars.map{|ch| (ch.ord + n).chr}.join
# => "DEFGH"
Upvotes: 4