Skip to content

Commit

Permalink
replaced run method with encrypt and decrypt method
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Sosinski committed Aug 4, 2008
1 parent c548abc commit d64038a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Then, build a new <tt>RubyDES::Ctx</tt> object and supply the data and key block

Finally, let it rip.

encrypted_data = des.run(:encrypt)
encrypted_data = des.encrypt

You will then be returned a DES encrypted block that is completely secure against eavesdropping
(if it were still 1997).
Expand All @@ -36,7 +36,7 @@ fashion as before.

And run the DES with the key schedule reversed.

decrypted_data = un_des.run(:decrypt)
decrypted_data = un_des.decrypt

You can then check to see if it all worked.

Expand Down
10 changes: 10 additions & 0 deletions lib/ruby-des.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ def initialize(data, key)
@key = key
end

def encrypt
self.run(:encrypt)
end

def decrypt
self.run(:decrypt)
end

protected

def run(operation)
l = [] # l[0] is the IP_1_L permutation of the data block, l[1..16] are the results of each round of encryption.
r = [] # r[0] is the IP_1_R permutation of the data block, r[1..16] are the results of each round of encryption.
Expand Down
4 changes: 2 additions & 2 deletions test/ctx_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def setup
end

def test_run
encrypted = RubyDES::Ctx.new(@data, @key).run(:encrypt)
encrypted = RubyDES::Ctx.new(@data, @key).encrypt

assert_equal ctx(:encrypted_bit_array), encrypted.bit_array

decrypted = RubyDES::Ctx.new(encrypted, @key).run(:decrypt)
decrypted = RubyDES::Ctx.new(encrypted, @key).decrypt

assert_equal ctx(:decrypted_bit_array), decrypted.bit_array
end
Expand Down

0 comments on commit d64038a

Please sign in to comment.