ratsel 0.1.0
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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +4 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/crack +15 -0
- data/bin/decrypt +15 -0
- data/bin/encrypt +15 -0
- data/bin/setup +8 -0
- data/lib/ratsel.rb +9 -0
- data/lib/ratsel/crack.rb +55 -0
- data/lib/ratsel/decrypt.rb +60 -0
- data/lib/ratsel/encrypt.rb +52 -0
- data/lib/ratsel/helpers/accessor.rb +20 -0
- data/lib/ratsel/helpers/cipher.rb +12 -0
- data/lib/ratsel/helpers/helpers.rb +76 -0
- data/lib/ratsel/helpers/message.rb +7 -0
- data/lib/ratsel/helpers/utility.rb +46 -0
- data/lib/ratsel/test.txt +1 -0
- data/lib/ratsel/version.rb +3 -0
- data/ratsel.gemspec +37 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 33bd72862b50995d74e3e2a8eb41060c4c1a1326
|
4
|
+
data.tar.gz: b27e88682a2cffb389238dc9ff6fe9eba5f187bd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 274e78b12b807439e08a3b74ad5b3c6d3c46db3a0c3aaa10153c20fe39f76a4912fb0ae7238a93a4983ba90451cf57e1a06696dc8def16138c01c4f42a682dad
|
7
|
+
data.tar.gz: 1dda2f31cf68850b01d3889d011bd9f3d85c98c39fe1408fcd285c63b6f566ab553edea690e85ca6d42406d63fefda0342feb7113d79d35fc3a18dcfdf396df9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at vanessa.ejikeme@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Vanessa Ejikeme
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Vanessa Ejikeme
|
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
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ratsel"
|
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(__FILE__)
|
data/bin/crack
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'ratsel'
|
4
|
+
|
5
|
+
if ARGV[0] && (ARGV[0] == 'help' || ARGV[0] == '--help' || ARGV[0] == '-h')
|
6
|
+
Ratsel::Utility.crack
|
7
|
+
elsif ARGV.length < 3 || ARGV.length > 3
|
8
|
+
puts "Incorrect number of arguments. See --help for the documentation"
|
9
|
+
elsif !File.file?(ARGV[0])
|
10
|
+
puts "The input file path does not exist. See --help for the documentation"
|
11
|
+
elsif ARGV.length == 3 && File.file?(ARGV[1])
|
12
|
+
puts "The output file path cannot be created, or this file already exist. See --help for the documentation"
|
13
|
+
else
|
14
|
+
Ratsel::Crack.new(ARGV[0], ARGV[1], ARGV[2]).crack
|
15
|
+
end
|
data/bin/decrypt
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'ratsel'
|
4
|
+
|
5
|
+
if ARGV[0] && (ARGV[0] == 'help' || ARGV[0] == '--help' || ARGV[0] == '-h')
|
6
|
+
Ratsel::Utility.decrypt
|
7
|
+
elsif ARGV.length < 4 || ARGV.length > 4
|
8
|
+
puts "Incorrect number of arguments. See --help for the documentation"
|
9
|
+
elsif !File.file?(ARGV[0])
|
10
|
+
puts "The input file path does not exist. See --help for the documentation"
|
11
|
+
elsif ARGV.length == 4 && File.file?(ARGV[1])
|
12
|
+
puts "The output file path cannot be created, or this file already exist. See --help for the documentation"
|
13
|
+
else
|
14
|
+
Ratsel::Decrypt.new(ARGV[0], ARGV[1], ARGV[2], ARGV[3]).decrypt
|
15
|
+
end
|
data/bin/encrypt
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'ratsel'
|
4
|
+
|
5
|
+
if ARGV[0] && (ARGV[0] == 'help' || ARGV[0] == '--help' || ARGV[0] == '-h')
|
6
|
+
Ratsel::Utility.encrypt
|
7
|
+
elsif ARGV.length < 2 || ARGV.length > 2
|
8
|
+
puts "Incorrect number of arguments. See --help for the documentation"
|
9
|
+
elsif !File.file?(ARGV[0])
|
10
|
+
puts "The input file path does not exist. See --help for the documentation"
|
11
|
+
elsif ARGV[1] && File.file?(ARGV[1])
|
12
|
+
puts "The output file path cannot be created, or this file already exist. See --help for the documentation"
|
13
|
+
else
|
14
|
+
Ratsel::Encrypt.new(ARGV[0], ARGV[1]).encrypt
|
15
|
+
end
|
data/bin/setup
ADDED
data/lib/ratsel.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require "ratsel/version"
|
2
|
+
require "ratsel/encrypt"
|
3
|
+
require "ratsel/decrypt"
|
4
|
+
require "ratsel/crack"
|
5
|
+
require "ratsel/helpers/accessor"
|
6
|
+
require "ratsel/helpers/cipher"
|
7
|
+
require "ratsel/helpers/helpers"
|
8
|
+
require "ratsel/helpers/message"
|
9
|
+
require "ratsel/helpers/utility"
|
data/lib/ratsel/crack.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative "helpers/accessor"
|
2
|
+
require_relative "helpers/cipher"
|
3
|
+
require_relative "helpers/helpers"
|
4
|
+
require_relative "helpers/message"
|
5
|
+
require_relative "decrypt"
|
6
|
+
|
7
|
+
module Ratsel
|
8
|
+
class Crack
|
9
|
+
include SendMessage
|
10
|
+
attr_reader :decrypted_txt, :cracked_txt, :encryption_date, :encryption_key
|
11
|
+
|
12
|
+
def initialize(decrypted_txt, cracked_txt, encryption_date)
|
13
|
+
@encryption_key = nil
|
14
|
+
@encryption_date = encryption_date
|
15
|
+
@decrypted_txt = decrypted_txt
|
16
|
+
@cracked_txt = cracked_txt
|
17
|
+
@character_map = Cipher.character_map
|
18
|
+
end
|
19
|
+
|
20
|
+
def crack
|
21
|
+
end_char = '..end..'
|
22
|
+
decrypted_message = Accessor.read_file_text(decrypted_txt)
|
23
|
+
|
24
|
+
decrypted_message_4 = decrypted_message.last(4)
|
25
|
+
decrypted_message_4.rotate!(4 - (decrypted_message.size % 4))
|
26
|
+
end_char_4 = end_char.split("").last(4)
|
27
|
+
end_char_4.rotate!(4 - (decrypted_message.size % 4))
|
28
|
+
offsets = Helpers.offsets_array(@encryption_date).join('')
|
29
|
+
|
30
|
+
differences = get_differences(
|
31
|
+
decrypted_message_4,
|
32
|
+
decrypted_message_4,
|
33
|
+
offsets
|
34
|
+
)
|
35
|
+
|
36
|
+
key = Helpers.get_key(differences)
|
37
|
+
puts key
|
38
|
+
Decrypt.new(decrypted_txt, cracked_txt, key, encryption_date).decrypt
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_differences(decrypted_message, end_char, offsets)
|
42
|
+
differences = []
|
43
|
+
|
44
|
+
4.times do |i|
|
45
|
+
diff = (@character_map.index(decrypted_message[i]) -
|
46
|
+
@character_map.index(end_char[i]))
|
47
|
+
|
48
|
+
diff -= offsets[i].to_i
|
49
|
+
differences[i] = diff.to_s.rjust(2, '0')
|
50
|
+
end
|
51
|
+
|
52
|
+
differences
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require_relative "helpers/accessor"
|
2
|
+
require_relative "helpers/cipher"
|
3
|
+
require_relative "helpers/helpers"
|
4
|
+
require_relative "helpers/message"
|
5
|
+
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
module Ratsel
|
9
|
+
class Decrypt
|
10
|
+
include SendMessage
|
11
|
+
attr_reader :encryption_key, :encrypted_txt, :decrypt_txt, :character_map,
|
12
|
+
:sum_rotation_offset, :encryption_date
|
13
|
+
def initialize(
|
14
|
+
encrypted_txt,
|
15
|
+
decrypt_txt,
|
16
|
+
encryption_key,
|
17
|
+
encryption_date
|
18
|
+
)
|
19
|
+
@encryption_key = encryption_key
|
20
|
+
@encrypted_txt = encrypted_txt
|
21
|
+
@decrypt_txt = decrypt_txt
|
22
|
+
@character_map = Cipher.character_map
|
23
|
+
@encryption_date = encryption_date
|
24
|
+
@offsets_array = Helpers.offsets_array(@encryption_date)
|
25
|
+
@rotation_array = Helpers.rotation_array(@encryption_key)
|
26
|
+
@sum_rotation_offset = Helpers.sum_rotation_offset(@offsets_array, @rotation_array)
|
27
|
+
end
|
28
|
+
|
29
|
+
def decrypt
|
30
|
+
decrypted_message = ''
|
31
|
+
sliced_encrypted_array = []
|
32
|
+
sum_rotation_offset = @sum_rotation_offset.map { |n| -n.abs }
|
33
|
+
@encrypted_message = Accessor.read_file_text(@encrypted_txt)
|
34
|
+
|
35
|
+
@encrypted_message.each_slice(4) { |message|
|
36
|
+
sliced_encrypted_array << message.join('')
|
37
|
+
}
|
38
|
+
|
39
|
+
sliced_encrypted_array.each_with_index { |batch, index|
|
40
|
+
encrypted_batch = batch.downcase.split('')
|
41
|
+
|
42
|
+
n = encrypted_batch.length
|
43
|
+
|
44
|
+
n.times { |i|
|
45
|
+
char_rotate = @character_map.rotate(@character_map.index(encrypted_batch.shift))
|
46
|
+
rotated_array = char_rotate.rotate(sum_rotation_offset[i])
|
47
|
+
decrypted_message << rotated_array.shift
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
message(decrypt_txt, encryption_key, encryption_date)
|
52
|
+
|
53
|
+
File.open(decrypt_txt, "a") do |line|
|
54
|
+
line.write("#{decrypted_message}")
|
55
|
+
end
|
56
|
+
|
57
|
+
decrypted_message
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative "helpers/accessor"
|
2
|
+
require_relative "helpers/cipher"
|
3
|
+
require_relative "helpers/helpers"
|
4
|
+
require_relative "helpers/message"
|
5
|
+
|
6
|
+
module Ratsel
|
7
|
+
class Encrypt
|
8
|
+
include SendMessage
|
9
|
+
attr_reader :message_txt, :encrypted_txt, :encryption_date, :character_map, :encryption_key,
|
10
|
+
:offsets_array, :rotation_array, :sum_rotation_offset
|
11
|
+
|
12
|
+
def initialize(message_txt, encrypted_txt)
|
13
|
+
@message_txt = message_txt
|
14
|
+
@encrypted_txt = encrypted_txt
|
15
|
+
@encryption_date = Time.now.strftime("%d%m%y")
|
16
|
+
@character_map = Cipher.character_map
|
17
|
+
@encryption_key = (1..5).map { (1..9).to_a[rand(9)] }.join
|
18
|
+
@offsets_array = Helpers.offsets_array(@encryption_date)
|
19
|
+
@rotation_array = Helpers.rotation_array(@encryption_key)
|
20
|
+
@sum_rotation_offset = Helpers.sum_rotation_offset(@offsets_array, @rotation_array)
|
21
|
+
end
|
22
|
+
|
23
|
+
def encrypt
|
24
|
+
message = Accessor.read_file_text(@message_txt)
|
25
|
+
encrypted_message = ''
|
26
|
+
sliced_message_array = []
|
27
|
+
|
28
|
+
message.each_slice(4) { |message|
|
29
|
+
sliced_message_array << message.join('')
|
30
|
+
}
|
31
|
+
|
32
|
+
sliced_message_array.each_with_index { |batch, index|
|
33
|
+
message_batch = batch.downcase.split('')
|
34
|
+
n = message_batch.length
|
35
|
+
|
36
|
+
n.times { |i|
|
37
|
+
char_rotate = @character_map.rotate(@character_map.index(message_batch.shift))
|
38
|
+
rotated_array = char_rotate.rotate(@sum_rotation_offset[i])
|
39
|
+
encrypted_message << rotated_array.shift
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
message(encrypted_txt, encryption_key, encryption_date)
|
44
|
+
|
45
|
+
File.open(encrypted_txt, "a") do |line|
|
46
|
+
line.write("#{encrypted_message}")
|
47
|
+
end
|
48
|
+
|
49
|
+
encrypted_message
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Ratsel
|
2
|
+
class Accessor
|
3
|
+
# Read text from file
|
4
|
+
def self.read_file_text(text_file)
|
5
|
+
message = ''
|
6
|
+
File.open(text_file, 'rb').each { |line| message += line }
|
7
|
+
new_message = message.downcase.split('')
|
8
|
+
end
|
9
|
+
|
10
|
+
# Encryted info
|
11
|
+
def self.write_encrypted_texts(text_file)
|
12
|
+
encrypted_object = []
|
13
|
+
File.open(text_file).each { |line|
|
14
|
+
encrypted_object << line
|
15
|
+
}
|
16
|
+
|
17
|
+
encrypted_object
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Ratsel
|
2
|
+
class Cipher
|
3
|
+
def self.character_map
|
4
|
+
['a', 'b', 'c', 'd', 'e',
|
5
|
+
'f', 'g', 'h', 'i', 'j', 'k',
|
6
|
+
'l', 'm', 'n', 'o', 'p', 'q',
|
7
|
+
'r', 's', 't', 'u', 'v', 'w',
|
8
|
+
'x', 'y', 'z', '1', '2', '3', '4', '5',
|
9
|
+
'6', '7', '8', '9', ' ', '.', ',']
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require_relative "helpers"
|
2
|
+
# require_relative "cipher"
|
3
|
+
module Ratsel
|
4
|
+
class Helpers
|
5
|
+
# Get offsets array from the date of message transmission
|
6
|
+
def self.offsets_array(date)
|
7
|
+
offsets_array = []
|
8
|
+
date_square = date.to_i ** 2
|
9
|
+
new_str = date_square.to_s.reverse
|
10
|
+
new_str = new_str.slice!(0..3).reverse.split('')
|
11
|
+
|
12
|
+
new_str.each { |str| offsets_array << str.to_i }
|
13
|
+
|
14
|
+
offsets_array
|
15
|
+
end
|
16
|
+
|
17
|
+
# Get offsets from generated key
|
18
|
+
def self.rotation_array(key)
|
19
|
+
key_rotor_array = []
|
20
|
+
key_array = key.split('')
|
21
|
+
|
22
|
+
4.times { key_rotor_array << (key_array.shift + key_array[0]).to_i }
|
23
|
+
|
24
|
+
key_rotor_array
|
25
|
+
end
|
26
|
+
|
27
|
+
# Sum of A - n rotation and A - n offsets
|
28
|
+
def self.sum_rotation_offset(offsets, rotation_array)
|
29
|
+
sum_array = []
|
30
|
+
@offsets_array = offsets
|
31
|
+
@rotation_array = rotation_array
|
32
|
+
|
33
|
+
4.times { sum_array << @offsets_array.shift + @rotation_array.shift }
|
34
|
+
|
35
|
+
sum_array
|
36
|
+
end
|
37
|
+
|
38
|
+
# Get key
|
39
|
+
def self.get_key(differences)
|
40
|
+
key_array = []
|
41
|
+
differences.each_with_index do |value, index|
|
42
|
+
break if index == differences.size - 1
|
43
|
+
first_value = value
|
44
|
+
second_value = differences[index + 1]
|
45
|
+
|
46
|
+
compare(index, first_value, second_value, key_array, differences)
|
47
|
+
end
|
48
|
+
|
49
|
+
"%d%d%d%d" % [
|
50
|
+
differences[0],
|
51
|
+
differences[1][-1],
|
52
|
+
differences[2][-1],
|
53
|
+
differences[3][-1]
|
54
|
+
]
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def self.compare(index, first_value, second_value, key_array, differences)
|
59
|
+
until first_value.to_i >= 100 || key_array[index]
|
60
|
+
until second_value.to_i >= 100 || key_array[index]
|
61
|
+
if first_value[1] == second_value[0]
|
62
|
+
differences[index] = first_value
|
63
|
+
differences[index + 1] = second_value
|
64
|
+
key_array[index] = true
|
65
|
+
else
|
66
|
+
second_value = (second_value.to_i + Ratsel::Cipher.character_map.size).to_s
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
second_value = differences[index + 1]
|
71
|
+
first_value = (first_value.to_i + Ratsel::Cipher.character_map.size).to_s
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Ratsel
|
2
|
+
class Utility
|
3
|
+
def self.encrypt
|
4
|
+
puts(<<-HERE)
|
5
|
+
Encrypting a message file
|
6
|
+
|
7
|
+
Usage:
|
8
|
+
encrypt <file> [<output>]
|
9
|
+
|
10
|
+
Options:
|
11
|
+
<file>\t\t The path to the input file to be encrypted.
|
12
|
+
<output>\t The path to the output file to save the encrypted text.
|
13
|
+
HERE
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.decrypt
|
17
|
+
puts(<<-HERE)
|
18
|
+
Decrypting an encrypted message file
|
19
|
+
|
20
|
+
Usage:
|
21
|
+
decrypt <encrypted-file> [<output>] <key> <date>
|
22
|
+
|
23
|
+
Options:
|
24
|
+
<encrypted-file>\t The path to the input encrypted file to be decrypted.
|
25
|
+
<output>\t The path to the output file to save the plain text.
|
26
|
+
<key>\t\t The key used to encrypt the file.
|
27
|
+
<date>\t The encryption date in DDMMYY format (eg. 221117)
|
28
|
+
HERE
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.crack
|
32
|
+
puts(<<-HERE)
|
33
|
+
Cracking a message file encrypted with Ratsel, given that you are a spy\n
|
34
|
+
who knows the \"encryption date\"
|
35
|
+
|
36
|
+
Usage:
|
37
|
+
crack <encrypted-file> [<output>] <date>
|
38
|
+
|
39
|
+
Options:
|
40
|
+
<encrypted-file>\t The path to the encrypted file to be decrypted.
|
41
|
+
<output>\t The path to the output file used in saving the resulting plain text.
|
42
|
+
<date>\t\t The encryption date in DDMMYY format (eg. 221117).
|
43
|
+
HERE
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/ratsel/test.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
hello hello ..end..
|
data/ratsel.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "ratsel/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ratsel"
|
8
|
+
spec.version = Ratsel::VERSION
|
9
|
+
spec.authors = ["Vanessa Ejikeme"]
|
10
|
+
spec.email = ["vanessa.ejikeme@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "An encryption engine"
|
13
|
+
spec.description = "Ratsel is used in encryption and decrypting text from a file."
|
14
|
+
spec.homepage = "https://github.com/vynessa/ratsel"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing 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 " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "bin"
|
30
|
+
spec.executables = %w(encrypt decrypt crack)
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_development_dependency "coveralls", '~> 0'
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ratsel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vanessa Ejikeme
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-07 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.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
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: coveralls
|
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: Ratsel is used in encryption and decrypting text from a file.
|
70
|
+
email:
|
71
|
+
- vanessa.ejikeme@gmail.com
|
72
|
+
executables:
|
73
|
+
- encrypt
|
74
|
+
- decrypt
|
75
|
+
- crack
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- ".gitignore"
|
80
|
+
- ".rspec"
|
81
|
+
- ".travis.yml"
|
82
|
+
- CODE_OF_CONDUCT.md
|
83
|
+
- Gemfile
|
84
|
+
- LICENSE
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- bin/console
|
89
|
+
- bin/crack
|
90
|
+
- bin/decrypt
|
91
|
+
- bin/encrypt
|
92
|
+
- bin/setup
|
93
|
+
- lib/ratsel.rb
|
94
|
+
- lib/ratsel/crack.rb
|
95
|
+
- lib/ratsel/decrypt.rb
|
96
|
+
- lib/ratsel/encrypt.rb
|
97
|
+
- lib/ratsel/helpers/accessor.rb
|
98
|
+
- lib/ratsel/helpers/cipher.rb
|
99
|
+
- lib/ratsel/helpers/helpers.rb
|
100
|
+
- lib/ratsel/helpers/message.rb
|
101
|
+
- lib/ratsel/helpers/utility.rb
|
102
|
+
- lib/ratsel/test.txt
|
103
|
+
- lib/ratsel/version.rb
|
104
|
+
- ratsel.gemspec
|
105
|
+
homepage: https://github.com/vynessa/ratsel
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata:
|
109
|
+
allowed_push_host: https://rubygems.org
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.6.14
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: An encryption engine
|
130
|
+
test_files: []
|