Last active
April 13, 2023 23:30
-
-
Save benolee/b95cce73f80d1c78dd880fc51f376a2c to your computer and use it in GitHub Desktop.
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
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