Skip to content

Instantly share code, notes, and snippets.

@fuadsaud
Created November 17, 2014 02:48
Show Gist options
  • Save fuadsaud/bd0d4de93dd3ce7bf577 to your computer and use it in GitHub Desktop.
Save fuadsaud/bd0d4de93dd3ce7bf577 to your computer and use it in GitHub Desktop.
PLAINTEXT = ARGV[0].gsub(/[^A-Za-z]/, '')
KEY = ARGV[1]
p KEY
.chars
.cycle
.take(PLAINTEXT.size)
.zip(PLAINTEXT.chars)
.reduce(Hash.new { [] }) { |acc, (key, char)| acc.merge(key => acc[key] + [char]) }
.to_a
.sort
.flat_map(&:last)
.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment