Skip to content

Instantly share code, notes, and snippets.

@Freaky
Created June 5, 2015 04:41
Show Gist options
  • Save Freaky/d05c67c9b42713c772c3 to your computer and use it in GitHub Desktop.
Save Freaky/d05c67c9b42713c772c3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'openssl'
wordfile = ARGV.first || '/usr/share/dict/words'
ct = STDIN.read.unpack('m*').first
iv = ct[0..15]
ct = ct[16..-1]
cipher = OpenSSL::Cipher.new('AES-256-CBC')
digest = OpenSSL::Digest.new('sha256')
File.readlines(wordfile).map(&:chomp).each do |pw|
cipher.decrypt
cipher.key = digest.digest(pw)
cipher.iv = iv
cipher.padding = 0
pt = cipher.update(ct) + cipher.final
cipher.reset
if pt =~ /\A[[:ascii:]]*\000*\z/
puts "Password: #{pw}"
puts "Plaintext: #{pt}"
exit
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment