hce_md5 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae7c2f017e30ba9b9516f6eef5e5e40447264b5a
4
- data.tar.gz: 9f8250ca236c5b4b236f011b5448780d1e00e547
3
+ metadata.gz: ca6b329df7c2eccdd6758235f8cd74d8ae11fe57
4
+ data.tar.gz: b7580ed68869182ad6e8f443efc7ac5e94655167
5
5
  SHA512:
6
- metadata.gz: 9c31bc12505679549435706beb279e34e8f49780700ea9aa4a9305a6ecb82356481f48b07c20983cb79e1c9884882efadcbd6e4f818aad2f7e92698ad5d4f71a
7
- data.tar.gz: e94df4863479fa54f5fe182c93b528491b6c82f4e99c2c3b7f14737750cb45734ce1d6b73f5e3a67f9aec9351f385f5f3a404133039540d0e8e8ded691d59898
6
+ metadata.gz: 10eda2887e47341cb410597183536651d6d81b027196ff86e5922ac1760b46e2d76dfc1909729d15353d6170dfccfe89377a25756ba8344c266aa8b139d675e5
7
+ data.tar.gz: 113277e15fb1c808d6ad203ae5ae6770fdf71cdc11b8e3f5ad443420be837a62022c7f5d77e01f9eaaf25cc7bd741f7056da63dc92d74910559d4eea1312ff54
data/hce_md5.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  'using a one wayhash. This method of encryption is '\
15
15
  'the same that is used by radius (RFC2138) and is also '\
16
16
  'described in Applied Cryptography by Bruce Schneider '\
17
- '(p. 353 / "Karn"'
17
+ '(p. 353 / "Karn")'
18
18
  s.license = 'MIT'
19
19
 
20
20
  # s.rubyforge_project = 'hce_md5'
data/lib/hce_md5.rb CHANGED
@@ -58,7 +58,7 @@ class HCE_MD5
58
58
  ans[i - 8], ans[i - 7], ans[i - 6], ans[i - 5],
59
59
  ans[i - 4], ans[i - 3], ans[i - 2], ans[i - 1]
60
60
  ]
61
- tmparr = tmparr.collect { |val| val.to_s.chr }.join('')
61
+ tmparr = array2pack(tmparr)
62
62
  e_block = new_key(tmparr)
63
63
  end
64
64
  ans[i] = e_block[mod] ^ data[i]
@@ -85,7 +85,7 @@ class HCE_MD5
85
85
  data[i - 8], data[i - 7], data[i - 6], data[i - 5],
86
86
  data[i - 4], data[i - 3], data[i - 2], data[i - 1]
87
87
  ]
88
- tmparr = tmparr.collect { |val| val.to_s.chr }.join('')
88
+ tmparr = array2pack(tmparr)
89
89
  e_block = new_key(tmparr)
90
90
  end
91
91
  ans[i] = e_block[mod] ^ data[i]
@@ -96,6 +96,12 @@ class HCE_MD5
96
96
 
97
97
  private
98
98
 
99
+ # Turn an array into a binary packed string.
100
+
101
+ def array2pack(array)
102
+ array.compact.collect { |val| [val].pack('C*') }.join('')
103
+ end
104
+
99
105
  # Implment md5 hashing in php, though use the mhash() function
100
106
  # if it is available.
101
107
  #
@@ -2,5 +2,5 @@
2
2
 
3
3
  class HCE_MD5
4
4
  # This constant holds the HCE_MD5 version information.
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
data/spec/hce_md5_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require "codeclimate-test-reporter"
3
+ require 'codeclimate-test-reporter'
4
4
  CodeClimate::TestReporter.start
5
5
 
6
6
  require 'hce_md5'
@@ -12,14 +12,18 @@ describe HCE_MD5 do
12
12
  expect(result).to eq('text to encrypt')
13
13
  end
14
14
 
15
- it 'should encrypt & decrypt plain text' do
16
- hce = HCE_MD5.new('samplekey', 'XFileeharingPRO')
17
- result = hce.decrypt(hce.encrypt('text to encrypt'))
18
- expect(result).to eq('text to encrypt')
15
+ it 'should encrypt long line' do
16
+ hce = HCE_MD5.new('samplekey', 'samplerandom')
17
+ str = 'The quick brown fox jumps over the lazy dog'
18
+ expect(hce.encrypt(str).unpack('H*')).to eq [
19
+ 'b2be6f377b58f892f1331b7dc6b94c12' \
20
+ '335dce3978f9228058971db70879d658' \
21
+ 'ffef03be655bb26ef448be'
22
+ ]
19
23
  end
20
24
 
21
25
  it 'should encrypt & decrypt long text' do
22
- hce = HCE_MD5.new('samplekey', 'XFileeharingPRO')
26
+ hce = HCE_MD5.new('samplekey', 'samplerandom')
23
27
  str = 'The quick brown fox jumps over the lazy dog'
24
28
  result = hce.decrypt(hce.encrypt(str))
25
29
  expect(result).to eq(str)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hce_md5
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey V. Beduev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-19 00:00:00.000000000 Z
11
+ date: 2015-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -82,7 +82,7 @@ dependencies:
82
82
  version: '0'
83
83
  description: This package implements a chaining block cipher using a one wayhash.
84
84
  This method of encryption is the same that is used by radius (RFC2138) and is also
85
- described in Applied Cryptography by Bruce Schneider (p. 353 / "Karn"
85
+ described in Applied Cryptography by Bruce Schneider (p. 353 / "Karn")
86
86
  email:
87
87
  - beduev@gmail.com
88
88
  executables: []