Skip to content

Instantly share code, notes, and snippets.

@namtx
Last active June 7, 2018 02:02
Show Gist options
  • Save namtx/f8571faab0e75cb6de70d6ecf8451817 to your computer and use it in GitHub Desktop.
Save namtx/f8571faab0e75cb6de70d6ecf8451817 to your computer and use it in GitHub Desktop.
adapter
class Encrypter
def initialize(key)
@key = key
end
def encrypt(reader, writer)
key_index = 0
while not reader.eof?
clear_char = reader.getc
encrypted_char = clear_char ^ @key[key_index]
writer.putc(encrypted_char)
key_index = (key_index + 1) % @key.size
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment