dsp_blueprint_parser 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +21 -21
- data/Gemfile +15 -15
- data/Gemfile.lock +3 -3
- data/README.md +48 -46
- data/Rakefile +16 -12
- data/bin/console +15 -15
- data/dsp_blueprint_parser.gemspec +39 -37
- data/ext/md5f/extconf.rb +3 -0
- data/ext/md5f/md5f.c +311 -0
- data/lib/dsp_blueprint_parser.rb +40 -29
- data/lib/dsp_blueprint_parser/area.rb +30 -30
- data/lib/dsp_blueprint_parser/binary_reader.rb +46 -46
- data/lib/dsp_blueprint_parser/blueprint_data.rb +69 -69
- data/lib/dsp_blueprint_parser/building.rb +79 -79
- data/lib/dsp_blueprint_parser/data_sections.rb +40 -0
- data/lib/dsp_blueprint_parser/icon_layout.rb +23 -23
- data/lib/dsp_blueprint_parser/parser.rb +119 -144
- data/lib/dsp_blueprint_parser/version.rb +5 -5
- data/lib/md5f.so +0 -0
- metadata +12 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea96a27ab7a6ff6a0d8f471171bf00d895598405e3540a39e1eef500c5845441
|
4
|
+
data.tar.gz: 667b222e2fc364e6bbb3453d4593f7c024523a58655d699a8f569efa87a7cfdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d2b7fee9d4fd08748608c5a6d9920f754d7ca7ee62e57bd792a54409534ca1c880c3231c9e271f1a5a73dc4b8a3cbf47446dd9c307bc9297734ada96d9774eb
|
7
|
+
data.tar.gz: 9fe1c4414ee671bc6a296a8b872b3c583131d6531a7717a687993a3e1a21421f83c748c4c1282de9d4425722181465acfd2a41d51f74c88ec84c56a715e4812f
|
data/.rubocop.yml
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
AllCops:
|
2
|
-
TargetRubyVersion: 3.0
|
3
|
-
|
4
|
-
Style/StringLiterals:
|
5
|
-
Enabled: true
|
6
|
-
EnforcedStyle: single_quotes
|
7
|
-
|
8
|
-
Style/StringLiteralsInInterpolation:
|
9
|
-
Enabled: true
|
10
|
-
EnforcedStyle: double_quotes
|
11
|
-
|
12
|
-
Layout/LineLength:
|
13
|
-
Max: 120
|
14
|
-
|
15
|
-
Metrics/MethodLength:
|
16
|
-
Max: 30
|
17
|
-
|
18
|
-
Metrics/BlockLength:
|
19
|
-
Max: 30
|
20
|
-
|
21
|
-
Metrics/AbcSize:
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 3.0
|
3
|
+
|
4
|
+
Style/StringLiterals:
|
5
|
+
Enabled: true
|
6
|
+
EnforcedStyle: single_quotes
|
7
|
+
|
8
|
+
Style/StringLiteralsInInterpolation:
|
9
|
+
Enabled: true
|
10
|
+
EnforcedStyle: double_quotes
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 120
|
14
|
+
|
15
|
+
Metrics/MethodLength:
|
16
|
+
Max: 30
|
17
|
+
|
18
|
+
Metrics/BlockLength:
|
19
|
+
Max: 30
|
20
|
+
|
21
|
+
Metrics/AbcSize:
|
22
22
|
Enabled: false
|
data/Gemfile
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source 'https://rubygems.org'
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in dsp_blueprint_parser.gemspec
|
6
|
-
gemspec
|
7
|
-
|
8
|
-
gem 'rake', '~> 13.0'
|
9
|
-
|
10
|
-
gem 'rspec', '~> 3.0'
|
11
|
-
|
12
|
-
gem 'pry', '~> 0.14.0'
|
13
|
-
gem 'rspec-expectations', '~> 3.10.1'
|
14
|
-
gem 'rspec-its', '~> 1.3.0'
|
15
|
-
gem 'rubocop', '~> 1.7'
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in dsp_blueprint_parser.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'rake', '~> 13.0'
|
9
|
+
|
10
|
+
gem 'rspec', '~> 3.0'
|
11
|
+
|
12
|
+
gem 'pry', '~> 0.14.0'
|
13
|
+
gem 'rspec-expectations', '~> 3.10.1'
|
14
|
+
gem 'rspec-its', '~> 1.3.0'
|
15
|
+
gem 'rubocop', '~> 1.7'
|
data/Gemfile.lock
CHANGED
@@ -45,13 +45,13 @@ GEM
|
|
45
45
|
rubocop-ast (>= 1.8.0, < 2.0)
|
46
46
|
ruby-progressbar (~> 1.7)
|
47
47
|
unicode-display_width (>= 1.4.0, < 3.0)
|
48
|
-
rubocop-ast (1.
|
48
|
+
rubocop-ast (1.9.0)
|
49
49
|
parser (>= 3.0.1.1)
|
50
50
|
ruby-progressbar (1.11.0)
|
51
51
|
unicode-display_width (2.0.0)
|
52
52
|
|
53
53
|
PLATFORMS
|
54
|
-
|
54
|
+
x86_64-linux
|
55
55
|
|
56
56
|
DEPENDENCIES
|
57
57
|
dsp_blueprint_parser!
|
@@ -63,4 +63,4 @@ DEPENDENCIES
|
|
63
63
|
rubocop (~> 1.7)
|
64
64
|
|
65
65
|
BUNDLED WITH
|
66
|
-
2.2.
|
66
|
+
2.2.3
|
data/README.md
CHANGED
@@ -1,46 +1,48 @@
|
|
1
|
-
# DspBlueprintParser
|
2
|
-
|
3
|
-
Small Ruby gem to handle parsing of Dyson Sphere Program's blueprint data.
|
4
|
-
|
5
|
-
Currently the gem does not support validating the MD5 hash of the blueprint. It appears as if the DSP devs wrote their own MD5 algorithm which would need it's own Ruby port.
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'dsp_blueprint_parser'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle install
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install dsp_blueprint_parser
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
Module `DspBlueprintParser` has a single static method `parse` which takes the DSP blueprint string to be parsed.
|
26
|
-
|
27
|
-
```ruby
|
28
|
-
DspBlueprintParser.parse(str_blueprint)
|
29
|
-
```
|
30
|
-
|
31
|
-
This method returns a [BlueprintData](https://github.com/LRFalk01/DSP-Blueprint-Parser/blob/master/lib/dsp_blueprint_parser/blueprint_data.rb) object which includes the various metadata of the blueprint.
|
32
|
-
Part of the `BlueprintData` object are properties for [areas](https://github.com/LRFalk01/DSP-Blueprint-Parser/blob/master/lib/dsp_blueprint_parser/area.rb) and [buildings](https://github.com/LRFalk01/DSP-Blueprint-Parser/blob/master/lib/dsp_blueprint_parser/building.rb) which are what one would mostly be interested in further evaluating.
|
33
|
-
|
34
|
-
## Development
|
35
|
-
|
36
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
37
|
-
|
38
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
39
|
-
|
40
|
-
## Contributing
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
1
|
+
# DspBlueprintParser
|
2
|
+
|
3
|
+
Small Ruby gem to handle parsing of Dyson Sphere Program's blueprint data.
|
4
|
+
|
5
|
+
Currently the gem does not support validating the MD5 hash of the blueprint. It appears as if the DSP devs wrote their own MD5 algorithm which would need it's own Ruby port.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'dsp_blueprint_parser'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install dsp_blueprint_parser
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Module `DspBlueprintParser` has a single static method `parse` which takes the DSP blueprint string to be parsed.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
DspBlueprintParser.parse(str_blueprint)
|
29
|
+
```
|
30
|
+
|
31
|
+
This method returns a [BlueprintData](https://github.com/LRFalk01/DSP-Blueprint-Parser/blob/master/lib/dsp_blueprint_parser/blueprint_data.rb) object which includes the various metadata of the blueprint.
|
32
|
+
Part of the `BlueprintData` object are properties for [areas](https://github.com/LRFalk01/DSP-Blueprint-Parser/blob/master/lib/dsp_blueprint_parser/area.rb) and [buildings](https://github.com/LRFalk01/DSP-Blueprint-Parser/blob/master/lib/dsp_blueprint_parser/building.rb) which are what one would mostly be interested in further evaluating.
|
33
|
+
|
34
|
+
## Development
|
35
|
+
|
36
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
37
|
+
|
38
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
Running `rake compile` requires `gem install rake-compiler` to build the md5f extension.
|
43
|
+
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/LRFalk01/dsp_blueprint_parser.
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,12 +1,16 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/gem_tasks'
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
|
6
|
-
RSpec::Core::RakeTask.new(:spec)
|
7
|
-
|
8
|
-
require 'rubocop/rake_task'
|
9
|
-
|
10
|
-
RuboCop::RakeTask.new
|
11
|
-
|
12
|
-
task default: %i[spec rubocop]
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require 'rubocop/rake_task'
|
9
|
+
|
10
|
+
RuboCop::RakeTask.new
|
11
|
+
|
12
|
+
task default: %i[spec rubocop]
|
13
|
+
|
14
|
+
|
15
|
+
require 'rake/extensiontask'
|
16
|
+
Rake::ExtensionTask.new('md5f')
|
data/bin/console
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'bundler/setup'
|
5
|
-
require 'dsp_blueprint_parser'
|
6
|
-
|
7
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
-
# with your gem easier. You can also use a different console, if you like.
|
9
|
-
|
10
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
-
# require "pry"
|
12
|
-
# Pry.start
|
13
|
-
|
14
|
-
require 'irb'
|
15
|
-
IRB.start(__FILE__)
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'dsp_blueprint_parser'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
@@ -1,37 +1,39 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'lib/dsp_blueprint_parser/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = 'dsp_blueprint_parser'
|
7
|
-
spec.version = DspBlueprintParser::VERSION
|
8
|
-
spec.authors = ['Lucas Falk']
|
9
|
-
spec.email = ['LRFalk01@gmail.com']
|
10
|
-
|
11
|
-
spec.summary = 'Parse Dyson Sphere Program blueprint string'
|
12
|
-
spec.description = 'Parse Dyson Sphere Program blueprint string'
|
13
|
-
spec.homepage = 'https://github.com/LRFalk01/DSP-Blueprint-Parser'
|
14
|
-
spec.license = 'MIT'
|
15
|
-
spec.required_ruby_version = '>= 3.0'
|
16
|
-
|
17
|
-
# spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
|
18
|
-
|
19
|
-
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
-
spec.metadata['source_code_uri'] = spec.homepage
|
21
|
-
# spec.metadata['changelog_uri'] = spec.homepage
|
22
|
-
|
23
|
-
# Specify which files should be added to the gem when it is released.
|
24
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
-
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
27
|
-
end
|
28
|
-
spec.bindir = 'exe'
|
29
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
-
spec.require_paths = ['lib']
|
31
|
-
|
32
|
-
# Uncomment to register a new dependency of your gem
|
33
|
-
# spec.add_dependency "example-gem", "~> 1.0"
|
34
|
-
|
35
|
-
# For more information and examples about making a new gem, checkout our
|
36
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
37
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/dsp_blueprint_parser/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'dsp_blueprint_parser'
|
7
|
+
spec.version = DspBlueprintParser::VERSION
|
8
|
+
spec.authors = ['Lucas Falk']
|
9
|
+
spec.email = ['LRFalk01@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Parse Dyson Sphere Program blueprint string'
|
12
|
+
spec.description = 'Parse Dyson Sphere Program blueprint string'
|
13
|
+
spec.homepage = 'https://github.com/LRFalk01/DSP-Blueprint-Parser'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = '>= 3.0'
|
16
|
+
|
17
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
|
18
|
+
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
21
|
+
# spec.metadata['changelog_uri'] = spec.homepage
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
# Uncomment to register a new dependency of your gem
|
33
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
34
|
+
|
35
|
+
# For more information and examples about making a new gem, checkout our
|
36
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
37
|
+
|
38
|
+
spec.extensions = %w[ext/md5f/extconf.rb]
|
39
|
+
end
|
data/ext/md5f/extconf.rb
ADDED
data/ext/md5f/md5f.c
ADDED
@@ -0,0 +1,311 @@
|
|
1
|
+
#include<stdio.h> // define the header file
|
2
|
+
#include <stdlib.h>
|
3
|
+
#include <string.h>
|
4
|
+
#include "ruby.h"
|
5
|
+
|
6
|
+
uint A;
|
7
|
+
uint B;
|
8
|
+
uint C;
|
9
|
+
uint D;
|
10
|
+
|
11
|
+
const int S11 = 7;
|
12
|
+
const int S12 = 12;
|
13
|
+
const int S13 = 17;
|
14
|
+
const int S14 = 22;
|
15
|
+
const int S21 = 5;
|
16
|
+
const int S22 = 9;
|
17
|
+
const int S23 = 14;
|
18
|
+
const int S24 = 20;
|
19
|
+
const int S31 = 4;
|
20
|
+
const int S32 = 11;
|
21
|
+
const int S33 = 16;
|
22
|
+
const int S34 = 23;
|
23
|
+
const int S41 = 6;
|
24
|
+
const int S42 = 10;
|
25
|
+
const int S43 = 15;
|
26
|
+
const int S44 = 21;
|
27
|
+
|
28
|
+
// ugly, I know
|
29
|
+
uint ArrayLength = 0;
|
30
|
+
|
31
|
+
uint F(uint x, uint y, uint z)
|
32
|
+
{
|
33
|
+
return (uint) (((int) x & (int) y) | (~(int) x & (int) z));
|
34
|
+
}
|
35
|
+
|
36
|
+
uint G(uint x, uint y, uint z)
|
37
|
+
{
|
38
|
+
return (uint) (((int) x & (int) z) | ((int) y & ~(int) z));
|
39
|
+
}
|
40
|
+
|
41
|
+
uint H(uint x, uint y, uint z)
|
42
|
+
{
|
43
|
+
return x ^ y ^ z;
|
44
|
+
}
|
45
|
+
|
46
|
+
uint I(uint x, uint y, uint z)
|
47
|
+
{
|
48
|
+
return y ^ (x | ~z);
|
49
|
+
}
|
50
|
+
|
51
|
+
uint FF(uint a, uint b, uint c, uint d, uint mj, int s, uint ti)
|
52
|
+
{
|
53
|
+
a = a + F(b, c, d) + mj + ti;
|
54
|
+
a = a << s | a >> (32 - s);
|
55
|
+
a += b;
|
56
|
+
return a;
|
57
|
+
}
|
58
|
+
|
59
|
+
uint GG(uint a, uint b, uint c, uint d, uint mj, int s, uint ti)
|
60
|
+
{
|
61
|
+
a = a + G(b, c, d) + mj + ti;
|
62
|
+
a = a << s | a >> (32 - s);
|
63
|
+
a += b;
|
64
|
+
return a;
|
65
|
+
}
|
66
|
+
|
67
|
+
uint HH(uint a, uint b, uint c, uint d, uint mj, int s, uint ti)
|
68
|
+
{
|
69
|
+
a = a + H(b, c, d) + mj + ti;
|
70
|
+
a = a << s | a >> (32 - s);
|
71
|
+
a += b;
|
72
|
+
return a;
|
73
|
+
}
|
74
|
+
|
75
|
+
uint II(uint a, uint b, uint c, uint d, uint mj, int s, uint ti)
|
76
|
+
{
|
77
|
+
a = a + I(b, c, d) + mj + ti;
|
78
|
+
a = a << s | a >> (32 - s);
|
79
|
+
a += b;
|
80
|
+
return a;
|
81
|
+
}
|
82
|
+
|
83
|
+
void MD5_Init()
|
84
|
+
{
|
85
|
+
A = 1732584193U;
|
86
|
+
B = 4024216457U;
|
87
|
+
C = 2562383102U;
|
88
|
+
D = 271734598U;
|
89
|
+
}
|
90
|
+
|
91
|
+
uint * MD5_Append(unsigned char input[], size_t length)
|
92
|
+
{
|
93
|
+
int num1 = 1;
|
94
|
+
int num2 = length % 64;
|
95
|
+
int num3;
|
96
|
+
int num4 = 0;
|
97
|
+
if (num2 < 56)
|
98
|
+
{
|
99
|
+
num3 = 55 - num2;
|
100
|
+
num4 = length - num2 + 64;
|
101
|
+
}
|
102
|
+
else if (num2 == 56)
|
103
|
+
{
|
104
|
+
num3 = 63;
|
105
|
+
num1 = 1;
|
106
|
+
num4 = length + 8 + 64;
|
107
|
+
}
|
108
|
+
else
|
109
|
+
{
|
110
|
+
num3 = 63 - num2 + 56;
|
111
|
+
num4 = length + 64 - num2 + 64;
|
112
|
+
}
|
113
|
+
|
114
|
+
unsigned char arrayList[num3 + 9 + length];
|
115
|
+
unsigned int position = 0;
|
116
|
+
|
117
|
+
for (size_t i = 0; i < length; i++)
|
118
|
+
{
|
119
|
+
arrayList[position++] = input[i];
|
120
|
+
}
|
121
|
+
|
122
|
+
if (num1 == 1)
|
123
|
+
{
|
124
|
+
arrayList[position++] = (unsigned char) 128;
|
125
|
+
}
|
126
|
+
|
127
|
+
for (int index = 0; index < num3; ++index)
|
128
|
+
{
|
129
|
+
arrayList[position++] = (unsigned char) 0;
|
130
|
+
}
|
131
|
+
|
132
|
+
long num5 = (long) length * 8L;
|
133
|
+
unsigned char num6 = (unsigned char) ((unsigned long) num5 & (unsigned long) 255);
|
134
|
+
unsigned char num7 = (unsigned char) ((unsigned long) num5 >> 8 & (unsigned long) 255);
|
135
|
+
unsigned char num8 = (unsigned char) ((unsigned long) num5 >> 16 & (unsigned long) 255);
|
136
|
+
unsigned char num9 = (unsigned char) ((unsigned long) num5 >> 24 & (unsigned long) 255);
|
137
|
+
unsigned char num10 = (unsigned char) ((unsigned long) num5 >> 32 & (unsigned long) 255);
|
138
|
+
unsigned char num11 = (unsigned char) ((unsigned long) num5 >> 40 & (unsigned long) 255);
|
139
|
+
unsigned char num12 = (unsigned char) ((unsigned long) num5 >> 48 & (unsigned long) 255);
|
140
|
+
unsigned char num13 = (unsigned char) ((unsigned long) num5 >> 56);
|
141
|
+
arrayList[position++] = num6;
|
142
|
+
arrayList[position++] = num7;
|
143
|
+
arrayList[position++] = num8;
|
144
|
+
arrayList[position++] = num9;
|
145
|
+
arrayList[position++] = num10;
|
146
|
+
arrayList[position++] = num11;
|
147
|
+
arrayList[position++] = num12;
|
148
|
+
arrayList[position++] = num13;
|
149
|
+
|
150
|
+
ArrayLength = num4 / 4;
|
151
|
+
uint *numArray = calloc(ArrayLength, sizeof(uint));
|
152
|
+
long index1 = 0;
|
153
|
+
long index2 = 0;
|
154
|
+
for (; index1 < (long) num4; index1 += 4)
|
155
|
+
{
|
156
|
+
numArray[index2] = (uint) ((int) arrayList[index1] | ((int) arrayList[index1 + 1] << 8) | ((int) arrayList[index1 + 2] << 16) | ((int) arrayList[index1 + 3] << 24));
|
157
|
+
++index2;
|
158
|
+
}
|
159
|
+
|
160
|
+
return numArray;
|
161
|
+
}
|
162
|
+
|
163
|
+
void MD5_Trasform(uint x[])
|
164
|
+
{
|
165
|
+
for (int index = 0; index < ArrayLength; index += 16)
|
166
|
+
{
|
167
|
+
uint a = A;
|
168
|
+
uint b = B;
|
169
|
+
uint c = C;
|
170
|
+
uint d = D;
|
171
|
+
a = FF(a, b, c, d, x[index], 7, 3614090360U);
|
172
|
+
d = FF(d, a, b, c, x[index + 1], 12, 3906451286U);
|
173
|
+
c = FF(c, d, a, b, x[index + 2], 17, 606105819U);
|
174
|
+
b = FF(b, c, d, a, x[index + 3], 22, 3250441966U);
|
175
|
+
a = FF(a, b, c, d, x[index + 4], 7, 4118548399U);
|
176
|
+
d = FF(d, a, b, c, x[index + 5], 12, 1200080426U);
|
177
|
+
c = FF(c, d, a, b, x[index + 6], 17, 2821735971U);
|
178
|
+
b = FF(b, c, d, a, x[index + 7], 22, 4249261313U);
|
179
|
+
a = FF(a, b, c, d, x[index + 8], 7, 1770035416U);
|
180
|
+
d = FF(d, a, b, c, x[index + 9], 12, 2336552879U);
|
181
|
+
c = FF(c, d, a, b, x[index + 10], 17, 4294925233U);
|
182
|
+
b = FF(b, c, d, a, x[index + 11], 22, 2304563134U);
|
183
|
+
a = FF(a, b, c, d, x[index + 12], 7, 1805586722U);
|
184
|
+
d = FF(d, a, b, c, x[index + 13], 12, 4254626195U);
|
185
|
+
c = FF(c, d, a, b, x[index + 14], 17, 2792965006U);
|
186
|
+
b = FF(b, c, d, a, x[index + 15], 22, 968099873U);
|
187
|
+
a = GG(a, b, c, d, x[index + 1], 5, 4129170786U);
|
188
|
+
d = GG(d, a, b, c, x[index + 6], 9, 3225465664U);
|
189
|
+
c = GG(c, d, a, b, x[index + 11], 14, 643717713U);
|
190
|
+
b = GG(b, c, d, a, x[index], 20, 3384199082U);
|
191
|
+
a = GG(a, b, c, d, x[index + 5], 5, 3593408605U);
|
192
|
+
d = GG(d, a, b, c, x[index + 10], 9, 38024275U);
|
193
|
+
c = GG(c, d, a, b, x[index + 15], 14, 3634488961U);
|
194
|
+
b = GG(b, c, d, a, x[index + 4], 20, 3889429448U);
|
195
|
+
a = GG(a, b, c, d, x[index + 9], 5, 569495014U);
|
196
|
+
d = GG(d, a, b, c, x[index + 14], 9, 3275163606U);
|
197
|
+
c = GG(c, d, a, b, x[index + 3], 14, 4107603335U);
|
198
|
+
b = GG(b, c, d, a, x[index + 8], 20, 1197085933U);
|
199
|
+
a = GG(a, b, c, d, x[index + 13], 5, 2850285829U);
|
200
|
+
d = GG(d, a, b, c, x[index + 2], 9, 4243563512U);
|
201
|
+
c = GG(c, d, a, b, x[index + 7], 14, 1735328473U);
|
202
|
+
b = GG(b, c, d, a, x[index + 12], 20, 2368359562U);
|
203
|
+
a = HH(a, b, c, d, x[index + 5], 4, 4294588738U);
|
204
|
+
d = HH(d, a, b, c, x[index + 8], 11, 2272392833U);
|
205
|
+
c = HH(c, d, a, b, x[index + 11], 16, 1839030562U);
|
206
|
+
b = HH(b, c, d, a, x[index + 14], 23, 4259657740U);
|
207
|
+
a = HH(a, b, c, d, x[index + 1], 4, 2763975236U);
|
208
|
+
d = HH(d, a, b, c, x[index + 4], 11, 1272893353U);
|
209
|
+
c = HH(c, d, a, b, x[index + 7], 16, 4139469664U);
|
210
|
+
b = HH(b, c, d, a, x[index + 10], 23, 3200236656U);
|
211
|
+
a = HH(a, b, c, d, x[index + 13], 4, 681279174U);
|
212
|
+
d = HH(d, a, b, c, x[index], 11, 3936430074U);
|
213
|
+
c = HH(c, d, a, b, x[index + 3], 16, 3572445317U);
|
214
|
+
b = HH(b, c, d, a, x[index + 6], 23, 76029189U);
|
215
|
+
a = HH(a, b, c, d, x[index + 9], 4, 3654602809U);
|
216
|
+
d = HH(d, a, b, c, x[index + 12], 11, 3873151461U);
|
217
|
+
c = HH(c, d, a, b, x[index + 15], 16, 530742520U);
|
218
|
+
b = HH(b, c, d, a, x[index + 2], 23, 3299628645U);
|
219
|
+
a = II(a, b, c, d, x[index], 6, 4096336452U);
|
220
|
+
d = II(d, a, b, c, x[index + 7], 10, 1126891415U);
|
221
|
+
c = II(c, d, a, b, x[index + 14], 15, 2878612391U);
|
222
|
+
b = II(b, c, d, a, x[index + 5], 21, 4237533241U);
|
223
|
+
a = II(a, b, c, d, x[index + 12], 6, 1700485571U);
|
224
|
+
d = II(d, a, b, c, x[index + 3], 10, 2399980690U);
|
225
|
+
c = II(c, d, a, b, x[index + 10], 15, 4293915773U);
|
226
|
+
b = II(b, c, d, a, x[index + 1], 21, 2240044497U);
|
227
|
+
a = II(a, b, c, d, x[index + 8], 6, 1873313359U);
|
228
|
+
d = II(d, a, b, c, x[index + 15], 10, 4264355552U);
|
229
|
+
c = II(c, d, a, b, x[index + 6], 15, 2734768916U);
|
230
|
+
b = II(b, c, d, a, x[index + 13], 21, 1309151649U);
|
231
|
+
a = II(a, b, c, d, x[index + 4], 6, 4149444226U);
|
232
|
+
d = II(d, a, b, c, x[index + 11], 10, 3174756917U);
|
233
|
+
c = II(c, d, a, b, x[index + 2], 15, 718787259U);
|
234
|
+
b = II(b, c, d, a, x[index + 9], 21, 3951481745U);
|
235
|
+
A += a;
|
236
|
+
B += b;
|
237
|
+
C += c;
|
238
|
+
D += d;
|
239
|
+
}
|
240
|
+
}
|
241
|
+
|
242
|
+
unsigned char * MD5_Array(unsigned char input[], long length)
|
243
|
+
{
|
244
|
+
MD5_Init();
|
245
|
+
uint *append = MD5_Append(input, length);
|
246
|
+
MD5_Trasform(append);
|
247
|
+
uint numArray1[4] = { A, B, C, D};
|
248
|
+
|
249
|
+
unsigned char *numArray2 = calloc(4 * 4, sizeof(unsigned char));
|
250
|
+
|
251
|
+
int index1 = 0;
|
252
|
+
int index2 = 0;
|
253
|
+
while (index1 < 4)
|
254
|
+
{
|
255
|
+
numArray2[index2] = (unsigned char) (numArray1[index1] & (uint) 255);
|
256
|
+
numArray2[index2 + 1] = (unsigned char) (numArray1[index1] >> 8 & (uint) 255);
|
257
|
+
numArray2[index2 + 2] = (unsigned char) (numArray1[index1] >> 16 & (uint) 255);
|
258
|
+
numArray2[index2 + 3] = (unsigned char) (numArray1[index1] >> 24 & (uint) 255);
|
259
|
+
++index1;
|
260
|
+
index2 += 4;
|
261
|
+
}
|
262
|
+
|
263
|
+
free(append);
|
264
|
+
return numArray2;
|
265
|
+
}
|
266
|
+
|
267
|
+
unsigned char * ArrayToHexString(unsigned char input[])
|
268
|
+
{
|
269
|
+
size_t length = 16;
|
270
|
+
unsigned char *result = calloc(length * 2, sizeof(unsigned char));
|
271
|
+
|
272
|
+
for (size_t i = 0; i < length; i++)
|
273
|
+
{
|
274
|
+
sprintf(result+2*i, "%.2X", input[i]);
|
275
|
+
}
|
276
|
+
|
277
|
+
return result;
|
278
|
+
}
|
279
|
+
|
280
|
+
unsigned char * Compute(unsigned char message[], long length)
|
281
|
+
{
|
282
|
+
unsigned char * data = MD5_Array(message, length);
|
283
|
+
unsigned char * result = ArrayToHexString(data);
|
284
|
+
|
285
|
+
free(data);
|
286
|
+
return result;
|
287
|
+
}
|
288
|
+
|
289
|
+
VALUE MD5F = Qnil; /* Ruby Module */
|
290
|
+
|
291
|
+
VALUE rb_compute(VALUE self, VALUE str) {
|
292
|
+
if (RB_TYPE_P(str, T_STRING) != 1) {
|
293
|
+
return Qnil;
|
294
|
+
}
|
295
|
+
|
296
|
+
unsigned char *data = StringValuePtr(str);
|
297
|
+
long strLength = RSTRING_LEN(str);
|
298
|
+
|
299
|
+
unsigned char *hex = Compute(data, strLength);
|
300
|
+
|
301
|
+
VALUE result = rb_str_new(hex, 32);
|
302
|
+
free(hex);
|
303
|
+
|
304
|
+
return result;
|
305
|
+
}
|
306
|
+
|
307
|
+
void Init_md5f()
|
308
|
+
{
|
309
|
+
MD5F = rb_define_module("MD5F");
|
310
|
+
rb_define_module_function(MD5F, "compute", rb_compute, 1);
|
311
|
+
}
|