hce_md5 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ae7c2f017e30ba9b9516f6eef5e5e40447264b5a
4
+ data.tar.gz: 9f8250ca236c5b4b236f011b5448780d1e00e547
5
+ SHA512:
6
+ metadata.gz: 9c31bc12505679549435706beb279e34e8f49780700ea9aa4a9305a6ecb82356481f48b07c20983cb79e1c9884882efadcbd6e4f818aad2f7e92698ad5d4f71a
7
+ data.tar.gz: e94df4863479fa54f5fe182c93b528491b6c82f4e99c2c3b7f14737750cb45734ce1d6b73f5e3a67f9aec9351f385f5f3a404133039540d0e8e8ded691d59898
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ .env
2
+ .vagrant
3
+ .yardoc
4
+ coverage
5
+ doc
6
+ Gemfile.lock
7
+ perf/results
8
+ tmp/
9
+ .idea
10
+ .replica
11
+ TODO
12
+ .DS_Store
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ # This is the configuration used to check the rubocop source code.
2
+
3
+
4
+ Style/Encoding:
5
+ Enabled: true
6
+
7
+ ClassAndModuleCamelCase:
8
+ Enabled: false
9
+
10
+ MethodLength:
11
+ Enabled: false
12
+
13
+ Metrics/AbcSize:
14
+ Enabled: false
15
+
16
+ Documentation:
17
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - ruby-head
5
+ - jruby
6
+ - jruby-head
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Sergey V. Beduev
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ HCE_MD5 [![Build Status](https://travis-ci.org/bsv9/hce_md5.svg)](https://travis-ci.org/bsv9/hce_md5) [![Test Coverage](https://codeclimate.com/github/bsv9/hce_md5/badges/coverage.svg)](https://codeclimate.com/github/bsv9/hce_md5/coverage) [![Code Climate](https://codeclimate.com/github/bsv9/hce_md5/badges/gpa.svg)](https://codeclimate.com/github/bsv9/hce_md5)
2
+ ========
3
+
4
+ Class to emulate Perl's Crypt::HCE_MD5 module
5
+
6
+ The MIME Functions are tested and work symmetrically with the
7
+ Crypt::HCE_MD5 package (0.45) (without the KEYBUG Flag ..).
8
+ Shamelessly stolen from Eric Estabrooks, eric@urbanrage.com
9
+
10
+ Crypt::HCE_MD5 package:
11
+ This package implements a chaining block cipher using a one way
12
+ hash. This method of encryption is the same that is used by radius
13
+ (RFC2138) and is also described in Applied Cryptography by Bruce
14
+ Schneider (p. 353 / "Karn").
15
+
16
+ The idea is the the two sides have a shared secret that supplies one
17
+ of the keys and a randomly generated block of bytes provides the
18
+ second key. The random key is passed in cleartext between the two
19
+ sides.
20
+
21
+ Installation
22
+ ------------
23
+
24
+ Add to your Gemfile:
25
+
26
+ ```ruby
27
+ gem 'hce_md5'
28
+ ```
29
+
30
+ Usage
31
+ -----
32
+
33
+ Encryption:
34
+
35
+ ```ruby
36
+ require 'hce_md5'
37
+ hce = HCE_MD5.new('samplekey', 'randomkey')
38
+ hce.encrypt('text to encrypt')
39
+ ```
40
+
41
+ Decryption:
42
+
43
+ ```ruby
44
+ require 'hce_md5'
45
+ hce = HCE_MD5.new('samplekey', 'randomkey')
46
+ hce.decrypt(encrypted_text)
47
+ ```
48
+
49
+
50
+ License
51
+ -------
52
+
53
+ Copyright (c) 2015 Sergey V. Beduev
54
+
55
+ Permission is hereby granted, free of charge, to any person obtaining
56
+ a copy of this software and associated documentation files (the
57
+ "Software"), to deal in the Software without restriction, including
58
+ without limitation the rights to use, copy, modify, merge, publish,
59
+ distribute, sublicense, and/or sell copies of the Software, and to
60
+ permit persons to whom the Software is furnished to do so, subject to
61
+ the following conditions:
62
+
63
+ The above copyright notice and this permission notice shall be
64
+ included in all copies or substantial portions of the Software.
65
+
66
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
67
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
68
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
69
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
70
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
71
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
72
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ spec.rspec_opts = ['--color', '--backtrace']
9
+ end
10
+
11
+ task default: :spec
data/hce_md5.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
4
+ require 'hce_md5/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'hce_md5'
8
+ s.version = HCE_MD5::VERSION
9
+ s.authors = ['Sergey V. Beduev']
10
+ s.email = ['beduev@gmail.com']
11
+ s.homepage = 'http://github.com/bsv9/hce_md5'
12
+ s.summary = 'Class to emulate Perl\'s Crypt::HCE_MD5 module'
13
+ s.description = 'This package implements a chaining block cipher '\
14
+ 'using a one wayhash. This method of encryption is '\
15
+ 'the same that is used by radius (RFC2138) and is also '\
16
+ 'described in Applied Cryptography by Bruce Schneider '\
17
+ '(p. 353 / "Karn"'
18
+ s.license = 'MIT'
19
+
20
+ # s.rubyforge_project = 'hce_md5'
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.require_paths = ['lib']
25
+
26
+ s.add_development_dependency 'rake'
27
+ s.add_development_dependency 'rspec'
28
+ s.add_development_dependency 'yard'
29
+ s.add_development_dependency 'rubocop'
30
+ s.add_development_dependency 'codeclimate-test-reporter'
31
+ end
data/lib/hce_md5.rb ADDED
@@ -0,0 +1,115 @@
1
+ # encoding: utf-8
2
+
3
+ require 'hce_md5/version'
4
+ require 'digest'
5
+
6
+ ##
7
+ # Class to emulate Perl's Crypt::HCE_MD5 module
8
+ #
9
+ # The MIME Functions are tested and work symmetrically with the
10
+ # Crypt::HCE_MD5 package (0.45) (without the KEYBUG Flag ..).
11
+ #
12
+ # Shamelessly stolen from Eric Estabrooks, eric@urbanrage.com
13
+ # Crypt::HCE_MD5 package:
14
+ #
15
+ # This package implements a chaining block cipher using a one way
16
+ # hash. This method of encryption is the same that is used by radius
17
+ # (RFC2138) and is also described in Applied Cryptography by Bruce
18
+ # Schneider (p. 353 / "Karn").
19
+ #
20
+ # Two interfaces are provided in the package. The first is straight
21
+ # block encryption/decryption the second does base64 mime
22
+ # encoding/decoding of the encrypted/decrypted blocks.
23
+ #
24
+ # The idea is the the two sides have a shared secret that supplies one
25
+ # of the keys and a randomly generated block of bytes provides the
26
+ # second key. The random key is passed in cleartext between the two
27
+ # sides.
28
+ class HCE_MD5
29
+ # Creates a HCE_MD5 object.
30
+ #
31
+ # @param key [String] The shared secret key
32
+ # @param random [String, nil] The randomly generated key
33
+ def initialize(key, random = nil)
34
+ @key = key
35
+ if random.nil?
36
+ # srand((double)microtime() * 32767)
37
+ random = rand(32_767)
38
+ random = [random].pack('i*')
39
+ end
40
+ @rand = random
41
+ end
42
+
43
+ # Encrypt a block of data.
44
+ #
45
+ # @param data [String] The data to encrypt.
46
+ # @return [String] The encrypted binary data.
47
+ def encrypt(data)
48
+ data = data.unpack('C*')
49
+ ans = []
50
+ ans1 = []
51
+ e_block = new_key(@rand)
52
+ data.each_index do |i|
53
+ mod = i % 16
54
+ if (mod == 0) && (i > 15)
55
+ tmparr = [
56
+ ans[i - 16], ans[i - 15], ans[i - 14], ans[i - 13],
57
+ ans[i - 12], ans[i - 11], ans[i - 10], ans[i - 9],
58
+ ans[i - 8], ans[i - 7], ans[i - 6], ans[i - 5],
59
+ ans[i - 4], ans[i - 3], ans[i - 2], ans[i - 1]
60
+ ]
61
+ tmparr = tmparr.collect { |val| val.to_s.chr }.join('')
62
+ e_block = new_key(tmparr)
63
+ end
64
+ ans[i] = e_block[mod] ^ data[i]
65
+ ans1[i] = ans[i].chr
66
+ end
67
+ ans1.join('')
68
+ end
69
+
70
+ # Decrypt a block of data.
71
+ #
72
+ # @param data [String] The data to decrypt.
73
+ # @return [String] The decrypted binary data.
74
+ def decrypt(data)
75
+ data = data.unpack('C*')
76
+ ans = []
77
+ ans1 = []
78
+ e_block = new_key(@rand)
79
+ data.each_index do |i|
80
+ mod = i % 16
81
+ if (mod == 0) && (i > 15)
82
+ tmparr = [
83
+ data[i - 16], data[i - 15], data[i - 14], data[i - 13],
84
+ data[i - 12], data[i - 11], data[i - 10], data[i - 9],
85
+ data[i - 8], data[i - 7], data[i - 6], data[i - 5],
86
+ data[i - 4], data[i - 3], data[i - 2], data[i - 1]
87
+ ]
88
+ tmparr = tmparr.collect { |val| val.to_s.chr }.join('')
89
+ e_block = new_key(tmparr)
90
+ end
91
+ ans[i] = e_block[mod] ^ data[i]
92
+ ans1[i] = ans[i].chr
93
+ end
94
+ ans1.join('')
95
+ end
96
+
97
+ private
98
+
99
+ # Implment md5 hashing in php, though use the mhash() function
100
+ # if it is available.
101
+ #
102
+ # @param str [String] The string to hash.
103
+ # @return [String] The md5 mhash of the string.
104
+ def binmd5(str)
105
+ Digest::MD5.digest(str)
106
+ end
107
+
108
+ # Generate a new key for a new encryption block.
109
+ #
110
+ # @param round [String] The basis for the key.
111
+ # @return [String] The new key.
112
+ def new_key(round)
113
+ binmd5("#{@key}#{round}").unpack('C*')
114
+ end
115
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ class HCE_MD5
4
+ # This constant holds the HCE_MD5 version information.
5
+ VERSION = '0.1.0'
6
+ end
data/sftp-config.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ // The tab key will cycle through the settings when first created
3
+ // Visit http://wbond.net/sublime_packages/sftp/settings for help
4
+ // sftp, ftp or ftps
5
+ "type": "sftp",
6
+
7
+ "save_before_upload": true,
8
+ "upload_on_save": true,
9
+ "sync_down_on_open": false,
10
+ "sync_skip_deletes": false,
11
+ "confirm_downloads": false,
12
+ "confirm_sync": false,
13
+ "confirm_overwrite_newer": false,
14
+
15
+ // "host": "78.47.12.90",
16
+ "host": "188.164.249.147",
17
+ "user": "shaman",
18
+ //"password": "password",
19
+ "port": "22777",
20
+
21
+ // "remote_path": "/home/shaman/adtrace.newlayout",
22
+ "remote_path": "/home/shaman/hce_md5",
23
+ "ignore_regexes": [
24
+ "\\.sublime-(project|workspace)", "sftp-config(-alt\\d?)?\\.json",
25
+ "sftp-settings\\.json", "/venv/", "\\.svn", "\\.hg", "\\.git",
26
+ "\\.bzr", "_darcs", "CVS", "\\.DS_Store", "Thumbs\\.db", "desktop\\.ini", "/tmp/cache","/tmp/download", "/tmp/pids", "/log/"
27
+ ],
28
+ //"file_permissions": "664",
29
+ //"dir_permissions": "775",
30
+
31
+ //"extra_list_connections": 0,
32
+ "default_line_ending": "unix",
33
+
34
+ "connect_timeout": 30,
35
+ //"keepalive": 120,
36
+ //"ftp_passive_mode": true,
37
+ //"ssh_key_file": "~/.ssh/id_rsa",
38
+ //"sftp_flags": ["-F", "/path/to/ssh_config"],
39
+
40
+ //"preserve_modification_times": false,
41
+ //"remote_time_offset_in_hours": 0,
42
+ //"remote_encoding": "utf-8",
43
+ //"remote_locale": "C",
44
+ }
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require "codeclimate-test-reporter"
4
+ CodeClimate::TestReporter.start
5
+
6
+ require 'hce_md5'
7
+
8
+ describe HCE_MD5 do
9
+ it 'should generate random key' do
10
+ hce = HCE_MD5.new('samplekey')
11
+ result = hce.decrypt(hce.encrypt('text to encrypt'))
12
+ expect(result).to eq('text to encrypt')
13
+ end
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')
19
+ end
20
+
21
+ it 'should encrypt & decrypt long text' do
22
+ hce = HCE_MD5.new('samplekey', 'XFileeharingPRO')
23
+ str = 'The quick brown fox jumps over the lazy dog'
24
+ result = hce.decrypt(hce.encrypt(str))
25
+ expect(result).to eq(str)
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hce_md5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergey V. Beduev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: codeclimate-test-reporter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This package implements a chaining block cipher using a one wayhash.
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"
86
+ email:
87
+ - beduev@gmail.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rubocop.yml"
94
+ - ".travis.yml"
95
+ - Gemfile
96
+ - LICENSE
97
+ - README.md
98
+ - Rakefile
99
+ - hce_md5.gemspec
100
+ - lib/hce_md5.rb
101
+ - lib/hce_md5/version.rb
102
+ - sftp-config.json
103
+ - spec/hce_md5_spec.rb
104
+ homepage: http://github.com/bsv9/hce_md5
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.5.1
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Class to emulate Perl's Crypt::HCE_MD5 module
128
+ test_files: []
129
+ has_rdoc: