Skip to content

Instantly share code, notes, and snippets.

@snltd
Created May 31, 2019 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snltd/bbafeae7506efa0829d39cbd80c53324 to your computer and use it in GitHub Desktop.
Save snltd/bbafeae7506efa0829d39cbd80c53324 to your computer and use it in GitHub Desktop.
Friday challenge 2019-05-31
#!/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