Skip to content

Instantly share code, notes, and snippets.

@benolee
Last active April 13, 2023 23:30
Show Gist options
  • Save benolee/b95cce73f80d1c78dd880fc51f376a2c to your computer and use it in GitHub Desktop.
Save benolee/b95cce73f80d1c78dd880fc51f376a2c to your computer and use it in GitHub Desktop.
require 'zlib'
module (Module.new)::Digest
ROT13 = 'a'.upto('z').zip('a'.upto('z').lazy.cycle.drop(13)).then { |r| r.concat r.map { |a| a.map(&:upcase) } }.to_h
def rot13_digest(s)
String.new(encoding: Encoding::BINARY).tap { |buffer|
Zlib
.deflate(s, Zlib::NO_COMPRESSION)
.each_char
.map { |c| ROT13[c] }
.lazy
.cycle
.then { |block|
block
.zip(block.drop(13))
.cycle
.lazy
}.tap { |stream|
buffer << stream.next.join until buffer.length == 32
}
}
end
prepend_features Kernel
end
rot13_digest File.read(__FILE__)
#=> "krmywvoerdhzvbeqrhyrmyvZobqhyzrb"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment