Permalink
Browse files

built testing harness

  • Loading branch information...
Robert Sosinski
Robert Sosinski committed Jul 29, 2008
1 parent 1f74e5e commit cbe720dc7a06683d23a76dd6294bf09f926b8b5d
Showing with 35 additions and 7 deletions.
  1. +8 −0 Rakefile
  2. +3 −3 lib/ruby-des.rb
  3. +2 −2 lib/ruby-des/feistel.rb
  4. +4 −2 lib/ruby-des/key_schedule.rb
  5. +7 −0 test/feistel_test.rb
  6. +4 −0 test/helper.rb
  7. +7 −0 test/key_schedule_test.rb
View
@@ -0,0 +1,8 @@
+require 'rake'
+require 'rake/testtask'
+
+Rake::TestTask.new do |t|
+ t.libs << "test"
+ t.test_files = FileList['test/*_test.rb']
+ t.verbose = false
+end
View
@@ -1,7 +1,7 @@
-$:.unshift('./ruby-des')
+$:.unshift(File.dirname(__FILE__))
-require 'feistel'
-require 'key_schedule'
+require 'ruby-des/feistel'
+require 'ruby-des/key_schedule'
module RubyDES
IP = [0x3a, 0x32, 0x2a, 0x22, 0x1a, 0x12, 0x0a, 0x02,
View
@@ -57,8 +57,8 @@ class Feistel
0x07, 0x0b, 0x04, 0x01, 0x09, 0x0c, 0x0e, 0x02, 0x00, 0x06, 0x0a, 0x0d, 0x0f, 0x03, 0x05, 0x08,
0x02, 0x01, 0x0e, 0x07, 0x04, 0x0a, 0x08, 0x0d, 0x0f, 0x0c, 0x09, 0x00, 0x03, 0x05, 0x06, 0x0b]
- def self.new(half_block, sub_key, round)
-
+ def initialize(half_block, sub_key, round)
+ return [half_block, sub_key, round]
end
def run
@@ -1,4 +1,6 @@
class KeySchedule
+ attr_accessor :sub_keys
+
PC_1_L = [0x39, 0x31, 0x29, 0x21, 0x19, 0x11, 0x09,
0x01, 0x3a, 0x32, 0x2a, 0x22, 0x1a, 0x12,
0x0a, 0x02, 0x3b, 0x33, 0x2b, 0x23, 0x1b,
@@ -21,7 +23,7 @@ class KeySchedule
ROTATIONS = [1, 1, 2, 2, 2, 2, 2, 2,
1, 2, 2, 2, 2, 2, 2, 1]
- def self.create(key)
+ def initialize(key)
c = [] # c[0] is the PC_1_L permutation of the key, c[1..16] are the results of each left shift.
d = [] # d[0] is the PC_1_R permutation of the key, d[1..16] are the results of each left shift.
k = [] # k[0..15] are the sub keys created by combining c[i] with d[i] and permuting with PC_2.
@@ -47,6 +49,6 @@ def self.create(key)
k << PC_2.collect{|p| (c[i + 1] + d[i + 1])[p - 1]}
end
- return k
+ self.sub_keys = k
end
end
View
@@ -0,0 +1,7 @@
+require 'helper'
+
+class FeistelTest < Test::Unit::TestCase
+ def test_truth
+ assert true
+ end
+end
View
@@ -0,0 +1,4 @@
+$:.unshift(File.dirname(__FILE__) + "../lib")
+
+require 'test/unit'
+require 'ruby-des'
@@ -0,0 +1,7 @@
+require 'helper'
+
+class KeyScheduleTest < Test::Unit::TestCase
+ def test_truth
+ assert true
+ end
+end

0 comments on commit cbe720d

Please sign in to comment.