From 56fafb320e502430ce754290e130be0ec2f99633 Mon Sep 17 00:00:00 2001 From: Dan Milne Date: Fri, 2 Dec 2011 14:20:12 +1100 Subject: [PATCH] User proper paths --- lib/component.rb | 38 ------------------------------ lib/key.rb | 56 --------------------------------------------- test/test_helper.rb | 9 +++++--- 3 files changed, 6 insertions(+), 97 deletions(-) delete mode 100644 lib/component.rb delete mode 100644 lib/key.rb diff --git a/lib/component.rb b/lib/component.rb deleted file mode 100644 index bd97c43..0000000 --- a/lib/component.rb +++ /dev/null @@ -1,38 +0,0 @@ -module HSMR - class Component - include HSMR - attr_reader :key - attr_reader :length - - def component - @key - end - - def initialize(key=nil, length=DOUBLE) - ## Should check for odd parity - if key.nil? - key = generate(length) - else - key=key.gsub(/ /,'') - #raise TypeError, "Component argument expected" unless other.is_a? Component - end - @key = key.unpack('a2'*(key.length/2)).map{|x| x.hex}.pack('c'*(key.length/2)) - @length = @key.length - @key = @key - end - -# def xor(other) -# other = Component.new(other) unless other.is_a? Component -# raise TypeError, "Component argument expected" unless other.is_a? Component -# -# @a = @key.unpack('C2'*(@key.length/2)) -# @b = other.component.unpack('C2'*(other.component.length/2)) -# -# #result = @a.zip(@b).map {|x,y| x^y}.map {|z| z.to_s(16) }.join.upcase -# result = @a.zip(@b).map {|x,y| x^y}.map {|z| z.to_s(16) }.map {|c| c.length == 1 ? '0'+c : c }.join.upcase -# -# Key.new(result) -# end - - end -end diff --git a/lib/key.rb b/lib/key.rb deleted file mode 100644 index 4920a87..0000000 --- a/lib/key.rb +++ /dev/null @@ -1,56 +0,0 @@ -module HSMR - class Key - include HSMR - - attr_reader :key - attr_reader :length - - def initialize(init=nil, length=DOUBLE) - return nil if (init.is_a? Array ) && (init.length == 0) - - init = init.first if (init.is_a? Array) && (init.length == 1) - - if init.is_a? Array - init.collect! {|c| ( (c.is_a? HSMR::Component) ? c : HSMR::Component.new(c) ) } - - raise TypeError, "Component argument expected" unless init.first.is_a? Component - - @key=HSMR::xor(init.pop, init).key - - elsif init.is_a? Component - @key = init.component - elsif init.is_a? String - key=init.gsub(/ /,'') - @key = key.unpack('a2'*(key.length/2)).map{|x| x.hex}.pack('c'*(key.length/2)) - elsif key.nil? - key = generate(length) - @key = key.unpack('a2'*(key.length/2)).map{|x| x.hex}.pack('c'*(key.length/2)) - end - @length = @key.length - end - - #def xor(other) - # other=Component.new(other) if other.is_a? String - # other=Component.new(other.to_s) if other.is_a? Key -# -# puts "other is #{other.class} - #{other.key}" -# -# raise TypeError, "Component argument expected" unless other.is_a? Component -# -# @a = @key.unpack('C2'*(@key.length/2)) -# @b = other.component.unpack('C2'*(other.length/2)) -# -# resultant = Key.new( @a.zip(@b). -# map {|x,y| x^y}. -# map {|z| z.to_s(16) }. -# map {|c| c.length == 1 ? '0'+c : c }. -# join.upcase ) -# resultant -# end -# -# def xor!(_key) -# @key = xor(_key).key -# end - - end -end diff --git a/test/test_helper.rb b/test/test_helper.rb index 3cf9a52..660d95a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,7 @@ require "test/unit" -require "./lib/hsmr" -require "./lib/key" -require "./lib/component" +#require "./lib/hsmr" +#require "./lib/hsmr/key" +#require "./lib/hsmr/component" +require "hsmr" +#require "hsmr/key" +#require "hsmr/component"