robertsosinski / ruby-des

A Ruby implementation of the Data Encryption Standard

This URL has Read+Write access

Thu Jun 25 08:11:41 -0700 2009
commit  876acb69a7a7687fd54365ebf35144fcfbe67dab
tree    72713388a575d38d6737ac830de9f91bb94128aa
parent  5c2a2f24b9f3a3745efa9a5cacf71cf1562d5e1f
name age message
file .gitignore Wed Feb 18 19:25:05 -0800 2009 ignoring vim swap files [robertsosinski]
file MIT-LICENSE Wed Feb 18 19:24:06 -0800 2009 adding license [robertsosinski]
file README Wed Feb 18 19:24:06 -0800 2009 adding license [robertsosinski]
file Rakefile Thu Jun 25 08:11:41 -0700 2009 setting default rake task [robertsosinski]
directory lib/ Mon Sep 01 22:00:27 -0700 2008 cleaned up a few things [robertsosinski]
directory test/ Sun Aug 03 17:33:34 -0700 2008 cleanup [Robert Sosinski]
README
== RubyDES

RubyDES is a full Ruby implementation of the Data Encryption Standard.  The purpose of this 
project was to allow Ruby programmers interested in cryptography a glimpse of how a robust 
cryptographic algorithm functions in a language they understand.

The best way to understand the RubyDES source code is by following along with a FIPS 46, 
which you can find at http://csrc.nist.gov/publications/fips/fips46-3/fips46-3.pdf

NOTE: DES is deprecated, and as such, you should not use this implementation in any project you 
are developing.  I highly recommend the AES, TwoFish or Serpent algorithms through the OpenSSL 
library instead.

== Running RubyDES

Using RubyDES is pretty easy.  First, construct a new data and key block.

  data = RubyDES::Block.new('mysecret')
  key  = RubyDES::Block.new('hushhush')

Then, build a new <tt>RubyDES::Ctx</tt> object and supply the data and key block.

  des = RubyDES::Ctx.new(data, key)

Finally, let it rip.

  encrypted_data = des.encrypt

You will then be returned a DES encrypted block that is completely secure against eavesdropping 
(if it were still 1997).

To decrypt an encrypted data block, just build a new <tt>RubyDES::Ctx</tt> object in similar 
fashion as before.

  un_des = RubyDES::Ctx.new(encrypted_data, key)

And run the DES with the key schedule reversed.

  decrypted_data = un_des.decrypt

You can then check to see if it all worked.

  data.bit_array.eql?(decrypted_data.bit_array)

Enjoy!

== Feedback

If you have any questions, comments or just want to talk shop about crypto, feel free to reach me 
through my website at http://www.robertsosinski.com.