Permalink
Browse files

added permutations

  • Loading branch information...
Robert Sosinski
Robert Sosinski committed Jul 28, 2008
1 parent 6e43df4 commit a6a0a78880403b06060d5ef3acec12ff6ac712d3
Showing with 114 additions and 0 deletions.
  1. +28 −0 lib/ruby-des.rb
  2. +61 −0 lib/ruby-des/feistel.rb
  3. +25 −0 lib/ruby-des/key_schedule.rb
View
@@ -0,0 +1,28 @@
+$:.unshift('./ruby-des')
+
+require 'feistel'
+require 'key_schedule'
+
+module RubyDES
+ IP = [0x3a, 0x32, 0x2a, 0x22, 0x1a, 0x12, 0x0a, 0x02,
+ 0x3c, 0x34, 0x2c, 0x24, 0x1c, 0x14, 0x0c, 0x04,
+ 0x3e, 0x36, 0x2e, 0x26, 0x1e, 0x16, 0x0e, 0x06,
+ 0x40, 0x38, 0x30, 0x28, 0x20, 0x18, 0x10, 0x08,
+ 0x39, 0x31, 0x29, 0x21, 0x19, 0x11, 0x09, 0x01,
+ 0x3b, 0x33, 0x2b, 0x23, 0x1b, 0x13, 0x0b, 0x03,
+ 0x3d, 0x35, 0x2d, 0x25, 0x1d, 0x15, 0x0d, 0x05,
+ 0x3f, 0x37, 0x2f, 0x27, 0x1f, 0x17, 0x0f, 0x07]
+
+ FP = [0x28, 0x08, 0x30, 0x10, 0x38, 0x18, 0x40, 0x20,
+ 0x27, 0x07, 0x2f, 0x0f, 0x37, 0x17, 0x3f, 0x1f,
+ 0x26, 0x06, 0x2e, 0x0e, 0x36, 0x16, 0x3e, 0x1e,
+ 0x25, 0x05, 0x2d, 0x0d, 0x35, 0x15, 0x3d, 0x1d,
+ 0x24, 0x04, 0x2c, 0x0c, 0x34, 0x14, 0x3c, 0x1c,
+ 0x23, 0x03, 0x2b, 0x0b, 0x33, 0x13, 0x3b, 0x1b,
+ 0x22, 0x02, 0x2a, 0x0a, 0x32, 0x12, 0x3a, 0x1a,
+ 0x21, 0x01, 0x29, 0x09, 0x31, 0x11, 0x39, 0x19]
+
+ class Ctx
+
+ end
+end
View
@@ -0,0 +1,61 @@
+class Feistel
+ E = [0x20, 0x01, 0x02, 0x03, 0x04, 0x05,
+ 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
+ 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
+ 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
+ 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x01]
+
+ P = [0x10, 0x07, 0x14, 0x15,
+ 0x1d, 0x0c, 0x1c, 0x11,
+ 0x01, 0x0f, 0x17, 0x1a,
+ 0x05, 0x12, 0x1f, 0x0a,
+ 0x02, 0x08, 0x18, 0x0e,
+ 0x20, 0x1b, 0x03, 0x09,
+ 0x13, 0x0d, 0x1e, 0x06,
+ 0x16, 0x0b, 0x04, 0x19]
+
+ S1 = [0x0e, 0x04, 0x0d, 0x01, 0x02, 0x0f, 0x0b, 0x08, 0x03, 0x0a, 0x06, 0x0c, 0x05, 0x09, 0x00, 0x07,
+ 0x00, 0x0f, 0x07, 0x04, 0x0e, 0x02, 0x0d, 0x01, 0x0a, 0x06, 0x0c, 0x0b, 0x09, 0x05, 0x03, 0x08,
+ 0x04, 0x01, 0x0e, 0x08, 0x0d, 0x06, 0x02, 0x0b, 0x0f, 0x0c, 0x09, 0x07, 0x03, 0x0a, 0x05, 0x00,
+ 0x0f, 0x0c, 0x08, 0x02, 0x04, 0x09, 0x01, 0x07, 0x05, 0x0b, 0x03, 0x0e, 0x0a, 0x00, 0x06, 0x0d]
+
+ S2 = [0x0f, 0x01, 0x08, 0x0e, 0x06, 0x0b, 0x03, 0x04, 0x09, 0x07, 0x02, 0x0d, 0x0c, 0x00, 0x05, 0x0a,
+ 0x03, 0x0d, 0x04, 0x07, 0x0f, 0x02, 0x08, 0x0e, 0x0c, 0x00, 0x01, 0x0a, 0x06, 0x09, 0x0b, 0x05,
+ 0x00, 0x0e, 0x07, 0x0b, 0x0a, 0x04, 0x0d, 0x01, 0x05, 0x08, 0x0c, 0x06, 0x09, 0x03, 0x02, 0x0f,
+ 0x0d, 0x08, 0x0a, 0x01, 0x03, 0x0f, 0x04, 0x02, 0x0b, 0x06, 0x07, 0x0c, 0x00, 0x05, 0x0e, 0x09]
+
+ S3 = [0x0a, 0x00, 0x09, 0x0e, 0x06, 0x03, 0x0f, 0x05, 0x01, 0x0d, 0x0c, 0x07, 0x0b, 0x04, 0x02, 0x08,
+ 0x0d, 0x07, 0x00, 0x09, 0x03, 0x04, 0x06, 0x0a, 0x02, 0x08, 0x05, 0x0e, 0x0c, 0x0b, 0x0f, 0x01,
+ 0x0d, 0x06, 0x04, 0x09, 0x08, 0x0f, 0x03, 0x00, 0x0b, 0x01, 0x02, 0x0c, 0x05, 0x0a, 0x0e, 0x07,
+ 0x01, 0x0a, 0x0d, 0x00, 0x06, 0x09, 0x08, 0x07, 0x04, 0x0f, 0x0e, 0x03, 0x0b, 0x05, 0x02, 0x0c]
+
+ S4 = [0x07, 0x0d, 0x0e, 0x03, 0x00, 0x06, 0x09, 0x0a, 0x01, 0x02, 0x08, 0x05, 0x0b, 0x0c, 0x04, 0x0f,
+ 0x0d, 0x08, 0x0b, 0x05, 0x06, 0x0f, 0x00, 0x03, 0x04, 0x07, 0x02, 0x0c, 0x01, 0x0a, 0x0e, 0x09,
+ 0x0a, 0x06, 0x09, 0x00, 0x0c, 0x0b, 0x07, 0x0d, 0x0f, 0x01, 0x03, 0x0e, 0x05, 0x02, 0x08, 0x04,
+ 0x03, 0x0f, 0x00, 0x06, 0x0a, 0x01, 0x0d, 0x08, 0x09, 0x04, 0x05, 0x0b, 0x0c, 0x07, 0x02, 0x0e]
+
+ S5 = [0x02, 0x0c, 0x04, 0x01, 0x07, 0x0a, 0x0b, 0x06, 0x08, 0x05, 0x03, 0x0f, 0x0d, 0x00, 0x0e, 0x09,
+ 0x0e, 0x0b, 0x02, 0x0c, 0x04, 0x07, 0x0d, 0x01, 0x05, 0x00, 0x0f, 0x0a, 0x03, 0x09, 0x08, 0x06,
+ 0x04, 0x02, 0x01, 0x0b, 0x0a, 0x0d, 0x07, 0x08, 0x0f, 0x09, 0x0c, 0x05, 0x06, 0x03, 0x00, 0x0e,
+ 0x0b, 0x08, 0x0c, 0x07, 0x01, 0x0e, 0x02, 0x0d, 0x06, 0x0f, 0x00, 0x09, 0x0a, 0x04, 0x05, 0x03]
+
+ S6 = [0x0c, 0x01, 0x0a, 0x0f, 0x09, 0x02, 0x06, 0x08, 0x00, 0x0d, 0x03, 0x04, 0x0e, 0x07, 0x05, 0x0b,
+ 0x0a, 0x0f, 0x04, 0x02, 0x07, 0x0c, 0x09, 0x05, 0x06, 0x01, 0x0d, 0x0e, 0x00, 0x0b, 0x03, 0x08,
+ 0x09, 0x0e, 0x0f, 0x05, 0x02, 0x08, 0x0c, 0x03, 0x07, 0x00, 0x04, 0x0a, 0x01, 0x0d, 0x0b, 0x06,
+ 0x04, 0x03, 0x02, 0x0c, 0x09, 0x05, 0x0f, 0x0a, 0x0b, 0x0e, 0x01, 0x07, 0x06, 0x00, 0x08, 0x0d]
+
+ S7 = [0x04, 0x0b, 0x02, 0x0e, 0x0f, 0x00, 0x08, 0x0d, 0x03, 0x0c, 0x09, 0x07, 0x05, 0x0a, 0x06, 0x01,
+ 0x0d, 0x00, 0x0b, 0x07, 0x04, 0x09, 0x01, 0x0a, 0x0e, 0x03, 0x05, 0x0c, 0x02, 0x0f, 0x08, 0x06,
+ 0x01, 0x04, 0x0b, 0x0d, 0x0c, 0x03, 0x07, 0x0e, 0x0a, 0x0f, 0x06, 0x08, 0x00, 0x05, 0x09, 0x02,
+ 0x06, 0x0b, 0x0d, 0x08, 0x01, 0x04, 0x0a, 0x07, 0x09, 0x05, 0x00, 0x0f, 0x0e, 0x02, 0x03, 0x0c]
+
+ S8 = [0x0d, 0x02, 0x08, 0x04, 0x06, 0x0f, 0x0b, 0x01, 0x0a, 0x09, 0x03, 0x0e, 0x05, 0x00, 0x0c, 0x07,
+ 0x01, 0x0f, 0x0d, 0x08, 0x0a, 0x03, 0x07, 0x04, 0x0c, 0x05, 0x06, 0x0b, 0x00, 0x0e, 0x09, 0x02,
+ 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]
+
+
+end
@@ -0,0 +1,25 @@
+class KeySchedule
+ PC_1_L = [0x39, 0x31, 0x29, 0x21, 0x19, 0x11, 0x09,
+ 0x01, 0x3a, 0x32, 0x2a, 0x22, 0x1a, 0x12,
+ 0x0a, 0x02, 0x3b, 0x33, 0x2b, 0x23, 0x1b,
+ 0x13, 0x0b, 0x03, 0x3c, 0x34, 0x2c, 0x24]
+
+ PC_1_R = [0x3f, 0x37, 0x2f, 0x27, 0x1f, 0x17, 0x0f,
+ 0x07, 0x3e, 0x36, 0x2e, 0x26, 0x1e, 0x16,
+ 0x0e, 0x06, 0x3d, 0x35, 0x2d, 0x25, 0x1d,
+ 0x15, 0x0d, 0x05, 0x1c, 0x14, 0x0c, 0x04]
+
+ PC_2 = [0x0e, 0x11, 0x0b, 0x18, 0x01, 0x05,
+ 0x03, 0x1c, 0x0f, 0x06, 0x15, 0x0a,
+ 0x17, 0x13, 0x0c, 0x04, 0x1a, 0x08,
+ 0x10, 0x07, 0x1b, 0x14, 0x0d, 0x02,
+ 0x29, 0x34, 0x1f, 0x25, 0x2f, 0x37,
+ 0x1e, 0x28, 0x33, 0x2d, 0x21, 0x30,
+ 0x2c, 0x31, 0x27, 0x38, 0x22, 0x35,
+ 0x2e, 0x2a, 0x32, 0x24, 0x1d, 0x20]
+
+ ROTATIONS = [1, 1, 2, 2, 2, 2, 2, 2,
+ 1, 2, 2, 2, 2, 2, 2, 1]
+
+
+end

0 comments on commit a6a0a78

Please sign in to comment.