Skip to content

Instantly share code, notes, and snippets.

@louismullie
Last active December 20, 2015 16:29
Show Gist options
  • Save louismullie/6161933 to your computer and use it in GitHub Desktop.
Save louismullie/6161933 to your computer and use it in GitHub Desktop.
# Results:
# +------------+--------------+------------+
# | Type | Uncompressed | Compressed |
# +------------+--------------+------------+
# | Plaintext | 649779 | 251901 |
# | Ciphertext | 649792 | 625780 |
# +------------+--------------+------------+
require 'openssl'
require 'zlib'
require 'terminal-table'
def gzip(string)
wio = StringIO.new("w")
w_gz = Zlib::GzipWriter.new(wio)
w_gz.write(string)
w_gz.close
wio.string
end
aes = OpenSSL::Cipher::Cipher.new("AES-256-CBC")
aes.encrypt
aes.random_key
aes.random_iv
plaintext = File.read('WutheringHeights.txt')
ciphertext = aes.update(plaintext)
ciphertext << aes.final
table = Terminal::Table.new(
headings: ['Type', 'Uncompressed', 'Compressed'],
rows: [
['Plaintext', plaintext.length, gzip(plaintext).length],
['Ciphertext', ciphertext.length, gzip(ciphertext).length]
]
)
puts table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment