Created
May 31, 2019 16:24
-
-
Save snltd/bbafeae7506efa0829d39cbd80c53324 to your computer and use it in GitHub Desktop.
Friday challenge 2019-05-31
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
#!/usr/bin/env ruby | |
class String | |
def index | |
ord > 96 ? ord - 96 : ord - 64 | |
end | |
def shift_by(other) | |
caser = ord > 96 ? :downcase : :upcase | |
i = self.index - other.index + 1 | |
i +=26 if i < 0 | |
((i + 64).chr).send(caser) | |
end | |
end | |
message = 'DDaQuoKsukIhlwCzhySkmkosyTriVnjxzgNvysDMjDhFxzdhltbDTuoydmFnvozhtbh' | |
key = 'SALAD'.tr('[A-S]', '[D-V]') * 20 | |
puts message.each_char.map.with_index { |l, i| l.shift_by(key[i]) }.join | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment