sofien-enigma 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: 8ceb78b02a319440274731cb7f0eb52d1c7314d8
4
+ data.tar.gz: aa377f0136710d8c622d5a5c06abe61a9334e805
5
+ SHA512:
6
+ metadata.gz: 94a8464eabc39d12f48d86ac1fcb1550c0e356937bf862c3e13efcc9e62d36b6a433163a72740901fb93bab0b3357c1803b72a91c1a89b1ead9d9bcc0e76c01a
7
+ data.tar.gz: 7720401529db2852eacb9af898b07e6f4915a48dc5b911207ad648cd9bd3127c14b1fe3796ed7c3778cf6135bbce3e73ca9726d0348722b33b7478c12aa165ac
data/.DS_Store ADDED
Binary file
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ repo_token: sXKFGHkYlZ6N3WJEGPAzYsWpFqjvy5esd
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,233 @@
1
+ AllCops:
2
+ Exclude:
3
+ - "vendor/**/*"
4
+ - "db/schema.rb"
5
+ UseCache: false
6
+ Style/CollectionMethods:
7
+ Description: Preferred collection methods.
8
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
9
+ Enabled: true
10
+ PreferredMethods:
11
+ collect: map
12
+ collect!: map!
13
+ find: detect
14
+ find_all: select
15
+ reduce: inject
16
+ Style/DotPosition:
17
+ Description: Checks the position of the dot in multi-line method calls.
18
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
19
+ Enabled: true
20
+ EnforcedStyle: trailing
21
+ SupportedStyles:
22
+ - leading
23
+ - trailing
24
+ Style/FileName:
25
+ Description: Use snake_case for source file names.
26
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
27
+ Enabled: false
28
+ Exclude: []
29
+ Style/GuardClause:
30
+ Description: Check for conditionals that can be replaced with guard clauses
31
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
32
+ Enabled: false
33
+ MinBodyLength: 1
34
+ Style/IfUnlessModifier:
35
+ Description: Favor modifier if/unless usage when you have a single-line body.
36
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
37
+ Enabled: false
38
+ MaxLineLength: 80
39
+ Style/OptionHash:
40
+ Description: Don't use option hashes when you can use keyword arguments.
41
+ Enabled: false
42
+ Style/PercentLiteralDelimiters:
43
+ Description: Use `%`-literal delimiters consistently
44
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
45
+ Enabled: false
46
+ PreferredDelimiters:
47
+ "%": "()"
48
+ "%i": "()"
49
+ "%q": "()"
50
+ "%Q": "()"
51
+ "%r": "{}"
52
+ "%s": "()"
53
+ "%w": "()"
54
+ "%W": "()"
55
+ "%x": "()"
56
+ Style/PredicateName:
57
+ Description: Check the names of predicate methods.
58
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
59
+ Enabled: true
60
+ NamePrefix:
61
+ - is_
62
+ - has_
63
+ - have_
64
+ NamePrefixBlacklist:
65
+ - is_
66
+ Exclude:
67
+ - spec/**/*
68
+ Style/RaiseArgs:
69
+ Description: Checks the arguments passed to raise/fail.
70
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
71
+ Enabled: false
72
+ EnforcedStyle: exploded
73
+ SupportedStyles:
74
+ - compact
75
+ - exploded
76
+ Style/SignalException:
77
+ Description: Checks for proper usage of fail and raise.
78
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
79
+ Enabled: false
80
+ EnforcedStyle: semantic
81
+ SupportedStyles:
82
+ - only_raise
83
+ - only_fail
84
+ - semantic
85
+ Style/SingleLineBlockParams:
86
+ Description: Enforces the names of some block params.
87
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
88
+ Enabled: false
89
+ Methods:
90
+ - reduce:
91
+ - a
92
+ - e
93
+ - inject:
94
+ - a
95
+ - e
96
+ Style/SingleLineMethods:
97
+ Description: Avoid single-line methods.
98
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
99
+ Enabled: false
100
+ AllowIfMethodIsEmpty: true
101
+ Style/StringLiterals:
102
+ Description: Checks if uses of quotes match the configured preference.
103
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
104
+ Enabled: true
105
+ EnforcedStyle: double_quotes
106
+ SupportedStyles:
107
+ - single_quotes
108
+ - double_quotes
109
+ Style/StringLiteralsInInterpolation:
110
+ Description: Checks if uses of quotes inside expressions in interpolated strings
111
+ match the configured preference.
112
+ Enabled: true
113
+ EnforcedStyle: single_quotes
114
+ SupportedStyles:
115
+ - single_quotes
116
+ - double_quotes
117
+ Style/TrailingCommaInLiteral:
118
+ Description: Checks for trailing comma in parameter lists and literals.
119
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
120
+ Enabled: false
121
+ EnforcedStyleForMultiline: no_comma
122
+ SupportedStyles:
123
+ - comma
124
+ - no_comma
125
+ Metrics/AbcSize:
126
+ Description: A calculated magnitude based on number of assignments, branches, and
127
+ conditions.
128
+ Enabled: false
129
+ Max: 15
130
+ Metrics/ClassLength:
131
+ Description: Avoid classes longer than 100 lines of code.
132
+ Enabled: false
133
+ CountComments: false
134
+ Max: 100
135
+ Metrics/ModuleLength:
136
+ CountComments: false
137
+ Max: 100
138
+ Description: Avoid modules longer than 100 lines of code.
139
+ Enabled: false
140
+ Metrics/CyclomaticComplexity:
141
+ Description: A complexity metric that is strongly correlated to the number of test
142
+ cases needed to validate a method.
143
+ Enabled: false
144
+ Max: 6
145
+ Metrics/MethodLength:
146
+ Description: Avoid methods longer than 10 lines of code.
147
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
148
+ Enabled: false
149
+ CountComments: false
150
+ Max: 10
151
+ Metrics/ParameterLists:
152
+ Description: Avoid parameter lists longer than three or four parameters.
153
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
154
+ Enabled: false
155
+ Max: 5
156
+ CountKeywordArgs: true
157
+ Metrics/PerceivedComplexity:
158
+ Description: A complexity metric geared towards measuring complexity for a human
159
+ reader.
160
+ Enabled: false
161
+ Max: 7
162
+ Lint/AssignmentInCondition:
163
+ Description: Don't use assignment in conditions.
164
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
165
+ Enabled: false
166
+ AllowSafeAssignment: true
167
+ Style/InlineComment:
168
+ Description: Avoid inline comments.
169
+ Enabled: false
170
+ Style/AccessorMethodName:
171
+ Description: Check the naming of accessor methods for get_/set_.
172
+ Enabled: false
173
+ Style/Alias:
174
+ Description: Use alias_method instead of alias.
175
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
176
+ Enabled: false
177
+ Style/Documentation:
178
+ Description: Document classes and non-namespace modules.
179
+ Enabled: false
180
+ Style/DoubleNegation:
181
+ Description: Checks for uses of double negation (!!).
182
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
183
+ Enabled: false
184
+ Style/EachWithObject:
185
+ Description: Prefer `each_with_object` over `inject` or `reduce`.
186
+ Enabled: false
187
+ Style/EmptyLiteral:
188
+ Description: Prefer literals to Array.new/Hash.new/String.new.
189
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
190
+ Enabled: false
191
+ Style/ModuleFunction:
192
+ Description: Checks for usage of `extend self` in modules.
193
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
194
+ Enabled: false
195
+ Style/OneLineConditional:
196
+ Description: Favor the ternary operator(?:) over if/then/else/end constructs.
197
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
198
+ Enabled: false
199
+ Style/PerlBackrefs:
200
+ Description: Avoid Perl-style regex back references.
201
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
202
+ Enabled: false
203
+ Style/Send:
204
+ Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
205
+ may overlap with existing methods.
206
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
207
+ Enabled: false
208
+ Style/SpecialGlobalVars:
209
+ Description: Avoid Perl-style global variables.
210
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
211
+ Enabled: false
212
+ Style/VariableInterpolation:
213
+ Description: Don't interpolate global, instance and class variables directly in
214
+ strings.
215
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
216
+ Enabled: false
217
+ Style/WhenThen:
218
+ Description: Use when x then ... for one-line cases.
219
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
220
+ Enabled: false
221
+ Lint/EachWithObjectArgument:
222
+ Description: Check for immutable argument given to each_with_object.
223
+ Enabled: true
224
+ Lint/HandleExceptions:
225
+ Description: Don't suppress exception.
226
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
227
+ Enabled: false
228
+ Lint/LiteralInCondition:
229
+ Description: Checks of literals used in conditions.
230
+ Enabled: false
231
+ Lint/LiteralInInterpolation:
232
+ Description: Checks for literals used in interpolation.
233
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
5
+ addons:
6
+ code_climate:
7
+ repo_token: a746e23f700d98a3c7fd85b48f55d84768a8ed4482d3f5c09ad818e7d033542c
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at godwin.onisofien@andela.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+ gem "simplecov", require: false, group: :test
3
+ gem "codeclimate-test-reporter", group: :test, require: nil
4
+ gem "coveralls", require: false
5
+ # Specify your gem's dependencies in enigma.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ogbara Godwin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ <a href="https://codeclimate.com/github/andela-gogbara/Enigma"><img src="https://codeclimate.com/github/andela-gogbara/Enigma/badges/gpa.svg" /></a>
2
+ <a href="https://codeclimate.com/github/andela-gogbara/Enigma/coverage"><img src="https://codeclimate.com/github/andela-gogbara/Enigma/badges/coverage.svg" /></a>
3
+ # Sofien-Enigma
4
+
5
+ Sofien-Enigma is an encryption engine built (as a gem) with ruby programming language. It follows the principles of Enigma Encryption Machine to encrypt and decrypt files. The gem also offers the feature of cracking a file.
6
+
7
+ ## Installation
8
+
9
+ To install as a gem and run as a terminal/command line program, run the following command in you terminal(command prompt for Windows)
10
+
11
+ $ gem install sofien-enigma
12
+
13
+ To use the gem in your project, add it to your gem file
14
+
15
+ gem 'sofien-enigma'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ ## Usage
22
+
23
+ This gem provides you with three command line actions, encrypt, decrypt, and crack.
24
+ When you have installed the gem, you can encrypt a file by changing to the directory that contains the file, and run any of the following commands
25
+
26
+
27
+ ### Encryption
28
+
29
+ $ encrypt <plain filename> <encrypted filename>
30
+
31
+
32
+ ### Decryption
33
+
34
+ $ decrypt <encrypted-filename> [<plain-filename>] <key> <date>
35
+
36
+ ### Cracking
37
+
38
+ $ crack <encrypted-filename> [<plain-filename>] <date>
39
+
40
+
41
+ ##Example Usage
42
+
43
+ $ encrypt message.txt encrypted.txt
44
+
45
+ =>#Created encrypted.txt with the key 51569 and date 030316
46
+
47
+ To decrypt a file named file named encrypted.txt
48
+
49
+ $ decrypt encrypted.txt decrypted.txt 51569 030316
50
+
51
+ =>#Created decrypted.txt with key 51569 and date 030316
52
+
53
+ To crack a file named encrypted.txt
54
+
55
+ $ crack encrypted.txt crack.txt 030316
56
+
57
+ =>#Created cracked.txt with key 51569 and date 030316
58
+
59
+
60
+
61
+ ## Limitations
62
+
63
+ * The character set of this gem is limited; lower case alphabets, numbers, space, comma and period characters.
64
+ * The gem generates the the key for the encryption, and does not allow user to choose their prefered digit combinations.
65
+ * The gem does not have a keys manager to help users save their keys
66
+
67
+ ## Improvement
68
+
69
+ * The character set supported by the gem will be increased
70
+ * The application should able to allow users choose their encryption key upon encrypting a file.
71
+ * The gem should be able to offer users the option of creating a text file, when they enter an invalid file name.
72
+ * The error handling will be increased to show proper error message for any error that can occur.
73
+ * Provide a key management system to store keys for easy reference.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "enigma"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/crack ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "enigma"
4
+
5
+ # # puts ENIGMATICKEYS::PossibleKeys.new("nd..", ARGV[0], ARGV[1]).get_partial_key
6
+ #
7
+ # p ENIGMA::Crack.new(ARGV[0], ARGV[1], ARGV[2]).crack_write
8
+
9
+
10
+ if ARGV.length < 2 || ARGV.length > 3
11
+ puts "Incorrect number of argument."
12
+ elsif !File.file?(ARGV[0])
13
+ puts "The input file path does not exist."
14
+ elsif ARGV.length == 3 && File.file?(ARGV[1])
15
+ puts "The output file path file already exist. Do you want to overwrite it? yes/no"
16
+ user_choice = STDIN.gets.chomp
17
+ if user_choice == "yes"
18
+ ENIGMA::Crack.new(ARGV[0], ARGV[1], ARGV[2]).crack_write
19
+ key = ENIGMA::Crack.new(ARGV[0], ARGV[1], ARGV[2]).clean_key
20
+ puts ENIGMA::Messages.success_message(ARGV[1], key, ARGV[2])
21
+ else
22
+ puts "Cant continue with cracking"
23
+ end
24
+ else
25
+ ENIGMA::Crack.new(ARGV[0], ARGV[1], ARGV[2]).crack_write
26
+ key = ENIGMA::Crack.new(ARGV[0], ARGV[1], ARGV[2]).clean_key
27
+ puts ENIGMA::Messages.success_message(ARGV[1], key, ARGV[2])
28
+ end
data/bin/decrypt ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "enigma"
4
+ # TODO: Add validation for incorrect key type or length
5
+
6
+ if ARGV.length < 3 || ARGV.length > 4
7
+ puts "Incorrect number of argument."
8
+ elsif !File.file?(ARGV[0])
9
+ puts "The input file path does not exist."
10
+ elsif ARGV.length == 4 && File.file?(ARGV[1])
11
+ puts "The output file path file already exist. Do you want to overwrite it? yes/no"
12
+ user_choice = STDIN.gets.chomp
13
+ if user_choice == "yes"
14
+ Decryption.new(ARGV[0], ARGV[1], ARGV[2], ARGV[3]).decrypt_write
15
+ puts ENIGMA::Messages.success_message(ARGV[1], ARGV[2], ARGV[3])
16
+ else
17
+ puts "Cant continue with decryption"
18
+ end
19
+ else
20
+ if ARGV.length == 4
21
+ Decryption.new(ARGV[0], ARGV[1], ARGV[2], ARGV[3]).decrypt_write
22
+ puts ENIGMA::Messages.success_message(ARGV[1], ARGV[2], ARGV[3])
23
+ end
24
+ end
data/bin/encrypt ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "enigma"
4
+
5
+ if ARGV.length < 1 || ARGV.length > 2
6
+ puts "Incorrect number of argument."
7
+ elsif !File.file?(ARGV[0])
8
+ puts "The input file path does not exist."
9
+ elsif ARGV[1] && File.file?(ARGV[1])
10
+ puts "The output file path file already exist. Do you want to overwrite it? yes/no"
11
+ user_choice = STDIN.gets.chomp
12
+ if user_choice == "yes"
13
+ new_encryption = Encryption.new(ARGV[0], ARGV[1])
14
+ new_encryption.encrypt_write
15
+ puts ENIGMA::Messages.success_message(ARGV[1], new_encryption.key, new_encryption.date_of_encryption )
16
+ else
17
+ puts "Cant continue with encryption"
18
+ end
19
+ else
20
+ new_encryption = Encryption.new(ARGV[0], ARGV[1])
21
+ new_encryption.encrypt_write
22
+ puts ENIGMA::Messages.success_message(ARGV[1], new_encryption.key, new_encryption.date_of_encryption )
23
+ end
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/crack.txt ADDED
@@ -0,0 +1 @@
1
+ hello world ..end. im trying to make a version of conways game of life using ruby. ive created a grid class with playar as an instance variable. however, when i run my code..end..
data/encrypted.txt ADDED
@@ -0,0 +1 @@
1
+ qz59xud 06xxgsy,mst6vuac7374ib8xvv42ivtgn 6x8t ouw weuj1u0yvzt ou56oztf1374i bz7st64zt00zuenytyi1,6muw9ja x53a5i.5y7v,xjatywu2,1bu,lztgj 2yk6yvi28hndychud5n8t6i b,i7fxl9x2gsy,msr
data/enigma.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "enigma/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sofien-enigma"
8
+ spec.version = Enigma::VERSION
9
+ spec.authors = ["Ogbara Godwin"]
10
+ spec.email = ["godwin.onisofien@andela.com"]
11
+
12
+ spec.summary = "Enigma encryption machine."
13
+ spec.description = "use both key and date"
14
+ spec.homepage = "https://github.com/andela-gogbara/Enigma"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "bin"
27
+ spec.executables = %w(encrypt decrypt crack)
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "pry"
34
+ end
data/lib/enigma.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "enigma/files"
2
+ require "enigma/crack"
3
+ require "enigma/crack_key"
4
+ require "enigma/enigmahelpers"
5
+ require "enigma/decryption"
6
+ require "enigma/encryption"
7
+ require "enigma/messages"
8
+ require "enigma/possible_keys"
9
+ require "enigma/validations"
10
+ require "enigma/version"
@@ -0,0 +1,43 @@
1
+ require "enigma"
2
+ module ENIGMA
3
+ class Crack
4
+ def initialize(encrypted_file, plain_file, date)
5
+ @encrypted_file = encrypted_file
6
+ @plain_file = plain_file
7
+ @date = date
8
+ @read_write = Files.new
9
+ @possible_keys = ENIGMA::PossibleKeys.new(@encrypted_file, @date)
10
+ end
11
+
12
+ def cracked_key
13
+ ENIGMA::Cracker.find_key(@possible_keys.get_partial_key("nd.."))
14
+ end
15
+
16
+ def clean_key
17
+ key = ""
18
+ cracked_key.each_with_index do |item, index|
19
+ key << item[0] if index == 0
20
+ key << item[0][1] if index > 0
21
+ end
22
+ key
23
+ end
24
+
25
+ def decrypted_text
26
+ @decrypt = Decryption.new(@encrypted_file, @plain_file, clean_key, @date)
27
+ @decrypt.decrypt(file_to_crack)
28
+ end
29
+
30
+ #
31
+ #
32
+ def crack_write
33
+ @read_write.write_file(@plain_file, decrypted_text)
34
+ # crack_success
35
+ end
36
+
37
+ #
38
+ def file_to_crack
39
+ @read_write.read_file(@encrypted_file)
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,56 @@
1
+ module ENIGMA
2
+ class Cracker
3
+ def self.find_key(partial_key)
4
+ @result = forward_check(partial_key)
5
+ @result = backwards_check(@result)
6
+ has_many = @result.any? { |element| element.size > 1 }
7
+ find_key(@result) if has_many
8
+ @result
9
+ end
10
+
11
+ def self.forward_check(partial_key)
12
+ count = 0
13
+ @new_array = []
14
+ while count < partial_key.length
15
+ forward_check_helper(partial_key, count)
16
+ count += 1
17
+ end
18
+ @new_array[partial_key.length - 1] = partial_key.last
19
+ @new_array
20
+ end
21
+
22
+ def self.forward_check_helper(partial_key, count)
23
+ @new_array[count] ||= []
24
+ partial_key[count].each_with_index do |item, _index|
25
+ next if partial_key[count + 1].nil?
26
+ partial_key[count + 1].each_with_index do |next_item, _index2|
27
+ @new_array[count] << item if item[-1] == next_item[0]
28
+ end
29
+ end
30
+ @new_array
31
+ end
32
+
33
+ def self.backwards_check(partial_key)
34
+ count = partial_key.length - 1
35
+ @new_array = []
36
+ while count >= 0
37
+ backwards_check_helper(partial_key, count)
38
+ count -= 1
39
+ end
40
+ @new_array[0] = partial_key.first
41
+ @new_array
42
+ end
43
+
44
+ def self.backwards_check_helper(partial_key, count)
45
+ @new_array[count] ||= []
46
+ partial_key[count].each_with_index do |item, _index|
47
+ next if partial_key[count - 1].nil?
48
+ partial_key[count - 1].each_with_index do |previous_item, _index2|
49
+ @new_array[count] << item if previous_item[-1] == item[0]
50
+ end
51
+ end
52
+ @new_array
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,39 @@
1
+ require "pry"
2
+ require "enigma"
3
+ class Decryption
4
+ include EnigmaHelpers
5
+ def initialize(encrypted_file, plain_file, key, offset_key)
6
+ @encrypted_file = encrypted_file
7
+ @plain_file = plain_file
8
+ @key = key
9
+ @read_write = Files.new
10
+ @offset_key = offset_key
11
+ @count = 0
12
+ @text = ""
13
+ @character_map = character_map
14
+ end
15
+
16
+ def decrypt(encrypted_text)
17
+ encrypted_text.each_byte do |each_char|
18
+ @text << @character_map[decrypt_helper(each_char, @count)]
19
+ @count += 1
20
+ end
21
+ @text
22
+ end
23
+
24
+ def decrypt_helper(each_char, _count)
25
+ (@character_map.index(each_char.chr) - get_total_rotation) % @character_map.size
26
+ end
27
+
28
+ def get_total_rotation
29
+ total_rotation(@count, @key, offset_key(date_of_encryption))
30
+ end
31
+
32
+ def decrypt_write
33
+ @read_write.write_file(@plain_file, decrypt(file_to_decript))
34
+ end
35
+
36
+ def file_to_decript
37
+ @read_write.read_file(@encrypted_file).chomp
38
+ end
39
+ end
@@ -0,0 +1,38 @@
1
+ require "enigma"
2
+ class Encryption
3
+ include EnigmaHelpers
4
+ attr_accessor :key
5
+ def initialize(plain_file, encrypted_file)
6
+ @plain_file = plain_file
7
+ @encrypted_file = encrypted_file
8
+ @count = 0
9
+ @key = generate_key
10
+ @character_map = character_map
11
+ @read_write = Files.new
12
+ end
13
+
14
+ def encrypt(plain_text)
15
+ text = ""
16
+ plain_text.each_byte do |each_char|
17
+ text << @character_map[encrypt_helper(each_char, @count)]
18
+ @count += 1
19
+ end
20
+ text
21
+ end
22
+
23
+ def encrypt_helper(each_char, _count)
24
+ (@character_map.index(each_char.chr) + get_total_rotation) % @character_map.size
25
+ end
26
+
27
+ def get_total_rotation
28
+ total_rotation(@count, @key, offset_key(date_of_encryption))
29
+ end
30
+
31
+ def encrypt_write
32
+ @read_write.write_file(@encrypted_file, encrypt(file_to_encrypt))
33
+ end
34
+
35
+ def file_to_encrypt
36
+ @read_write.read_file(@plain_file).chomp
37
+ end
38
+ end
@@ -0,0 +1,39 @@
1
+ module EnigmaHelpers
2
+ def character_map
3
+ [*"a".."z"] + [*"0".."9"] + [".", ",", " "]
4
+ end
5
+
6
+ def generate_key
7
+ [*1..9].sample(5).join("")
8
+ end
9
+
10
+ def total_rotation(count, key, offsetkey)
11
+ key_rotation(count, key) + offset_rotation(count, offsetkey)
12
+ end
13
+
14
+ def key_rotation(count, key)
15
+ shift = count % 4
16
+ key[shift..shift + 1].to_i
17
+ end
18
+
19
+ def offset_rotation(count, offsetkey)
20
+ shift = count % 4
21
+ offsetkey[shift].to_i
22
+ end
23
+
24
+ def format_month(month)
25
+ month < 10 ? "0" << month.to_s : month
26
+ end
27
+
28
+ def date_of_encryption
29
+ dd = Time.now
30
+ "#{format_month(dd.day)}#{format_month(dd.month)}#{dd.year.to_s[-2..-1]}".to_i
31
+ end
32
+
33
+ def offset_key(date_of_encryption)
34
+ date_key = date_of_encryption.to_i
35
+ date_key **= 2
36
+ date_key.to_s[-4..-1]
37
+ end
38
+ # End of module
39
+ end
@@ -0,0 +1,13 @@
1
+ class Files
2
+ def read_file(plain_text_file)
3
+ text = ""
4
+ File.open(plain_text_file).each do |line|
5
+ text << line
6
+ end
7
+ text
8
+ end
9
+
10
+ def write_file(encrypted_file, encrypted_text)
11
+ File.open(encrypted_file, "w") { |f| f.write(encrypted_text) }
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ module ENIGMA
2
+ class Messages
3
+ def argument_error
4
+ "Please enter the correct number of argument"
5
+ end
6
+
7
+ def file_type_error
8
+ "This enigma machine only works with .txt files e.g master.txt"
9
+ end
10
+
11
+ def file_not_present
12
+ "The file you are looking for does not exit"
13
+ end
14
+
15
+ def overwrite_file
16
+ "The file exist would u like to over write it"
17
+ end
18
+
19
+ def self.success_message(file_name, key, date)
20
+ "created #{file_name} with key #{key} and date #{date}"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,67 @@
1
+ require_relative "files"
2
+ require_relative "enigmahelpers"
3
+
4
+ module ENIGMA
5
+ class PossibleKeys
6
+ include EnigmaHelpers
7
+ def initialize(file_name, tday)
8
+ @tday = tday
9
+ @file_name = file_name
10
+ @read_write = Files.new
11
+ @count = 0
12
+ @file_crack = file_to_crack
13
+ @last_four = last_four_characters
14
+ @character_map = character_map
15
+ end
16
+
17
+ def get_partial_key(weakness)
18
+ @partial_key = []
19
+ weakness.each_byte do |each_char|
20
+ @partial_key[key_position(@count)] ||= []
21
+ @partial_key[key_position(@count)] = sub_key(each_char, @last_four[@count])
22
+ @count += 1
23
+ end
24
+ @partial_key
25
+ end
26
+
27
+ def sub_key(plain_char, encrypted_char)
28
+ sub_array = []
29
+ 10.times do |i|
30
+ 10.times do |j|
31
+ sub_array << "#{i}#{j}" if crack_helper?(plain_char, encrypted_char, "#{i}#{j}".to_i)
32
+ end
33
+ end
34
+ sub_array
35
+ end
36
+
37
+ def crack_helper?(plain_char, encrypted_char, test_value)
38
+ @character_map[crack_test(plain_char, test_value)] == encrypted_char
39
+ end
40
+
41
+ def crack_test(plain_char, test_value)
42
+ (@character_map.index(plain_char.chr) + (date_offset[key_position(@count)].to_i + test_value)) % @character_map.size
43
+ end
44
+
45
+ def file_to_crack
46
+ @file_crack ||= @read_write.read_file(@file_name).chomp
47
+ end
48
+
49
+ def find_rotation(_encrypted_char)
50
+ total_length = @file_crack.length - 1
51
+ ((total_length - 3) + @last_four.index(@last_four[@count])) % 4
52
+ end
53
+
54
+ def key_position(count)
55
+ find_rotation(@last_four[count])
56
+ end
57
+
58
+ def last_four_characters
59
+ @file_crack.split("").last(4).join
60
+ end
61
+
62
+ def date_offset
63
+ offset_key(@tday)
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,48 @@
1
+ # module Validations
2
+ # # def check_file_type(arguments)
3
+ # # arguments.each_with_index do |value, index|
4
+ # # return @messages.file_type_error unless value.include? ".txt"
5
+ # # break if index == 1
6
+ # # end
7
+ # # end
8
+ #
9
+ # def check_file_exitence
10
+ # @messages.file_not_present
11
+ # end
12
+ #
13
+ # def check_argument
14
+ # @messages.argument_error
15
+ # end
16
+ #
17
+ # def error_message(error_class)
18
+ # case error_class
19
+ # when "TypeError" then check_argument
20
+ # when "Errno::ENOENT" then check_file_exitence
21
+ # when "NoMethodError" then check_file_exitence
22
+ # else
23
+ # "Uknown Error"
24
+ # end
25
+ # end
26
+ #
27
+ # def is_file_present?(argument1, argument2)
28
+ # File.exist?(argument1) && File.exist?(argument2)
29
+ # end
30
+ #
31
+ # def is_valid_text_file?(argument2)
32
+ # argument2.include? ".txt"
33
+ # end
34
+ #
35
+ # def validate_decryption?(key, date_offset)
36
+ # validate_key?(key) && validate_date_offset?(date_offset)
37
+ # end
38
+ #
39
+ # def validate_key?(key)
40
+ # key.length == 5
41
+ # end
42
+ #
43
+ # def validate_date_offset?(date_offset)
44
+ # date_offset.length == 6
45
+ # end
46
+ #
47
+ # # End of file
48
+ # end
@@ -0,0 +1,3 @@
1
+ module Enigma
2
+ VERSION = "0.1.0".freeze
3
+ end
data/plain.txt ADDED
@@ -0,0 +1 @@
1
+ hello world ..end. im trying to make a version of conways game of life using ruby. ive created a grid class with playar as an instance variable. however, when i run my code..end..
data/test_crack.txt ADDED
@@ -0,0 +1 @@
1
+ gq,5nl2, o.r9qax9j
data/test_crack_1.txt ADDED
@@ -0,0 +1 @@
1
+ hello crack..end..
data/test_decrypt.txt ADDED
@@ -0,0 +1 @@
1
+ mzuid)qyoah%3771681361+)tsx,)
@@ -0,0 +1 @@
1
+ test
data/test_encrypt.txt ADDED
@@ -0,0 +1 @@
1
+ 8f bca473smfh,y7bey0
File without changes
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sofien-enigma
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ogbara Godwin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
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
+ description: use both key and date
70
+ email:
71
+ - godwin.onisofien@andela.com
72
+ executables:
73
+ - encrypt
74
+ - decrypt
75
+ - crack
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".DS_Store"
80
+ - ".coveralls.yml"
81
+ - ".gitignore"
82
+ - ".rspec"
83
+ - ".rubocop.yml"
84
+ - ".travis.yml"
85
+ - CODE_OF_CONDUCT.md
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - bin/console
91
+ - bin/crack
92
+ - bin/decrypt
93
+ - bin/encrypt
94
+ - bin/setup
95
+ - crack.txt
96
+ - encrypted.txt
97
+ - enigma.gemspec
98
+ - lib/enigma.rb
99
+ - lib/enigma/crack.rb
100
+ - lib/enigma/crack_key.rb
101
+ - lib/enigma/decryption.rb
102
+ - lib/enigma/encryption.rb
103
+ - lib/enigma/enigmahelpers.rb
104
+ - lib/enigma/files.rb
105
+ - lib/enigma/messages.rb
106
+ - lib/enigma/possible_keys.rb
107
+ - lib/enigma/validations.rb
108
+ - lib/enigma/version.rb
109
+ - plain.txt
110
+ - test_crack.txt
111
+ - test_crack_1.txt
112
+ - test_decrypt.txt
113
+ - test_decrypt_1.txt
114
+ - test_encrypt.txt
115
+ - test_encrypt_1.txt
116
+ homepage: https://github.com/andela-gogbara/Enigma
117
+ licenses:
118
+ - MIT
119
+ metadata:
120
+ allowed_push_host: https://rubygems.org
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.5.1
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Enigma encryption machine.
141
+ test_files: []