ratsel 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +21 -0
- data/.coveralls.yml +1 -0
- data/.travis.yml +2 -2
- data/README.md +48 -2
- data/lib/ratsel/crack.rb +20 -39
- data/lib/ratsel/decrypt.rb +3 -10
- data/lib/ratsel/encrypt.rb +23 -20
- data/lib/ratsel/helpers/accessor.rb +6 -9
- data/lib/ratsel/helpers/cipher.rb +1 -1
- data/lib/ratsel/helpers/helpers.rb +16 -3
- data/lib/ratsel/version.rb +1 -1
- data/ratsel.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d391b1a71dd2f6afb1b5766b181fd31dd1d656c
|
4
|
+
data.tar.gz: 1ce2b4a3f829f426544c2b3396b18b4e7b66b73f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 769b18c89e6932cf393107ea90b04aa37df53187546d43995ad25530287db15c6ca86778845bfc522776b569cb26e8c4f320b7ac0016731c7432c884dafe02c9
|
7
|
+
data.tar.gz: 4dfe71be8e3a4c61e068c34e127ad1cd021b861978f44762b3e53d07319cc91adcc8b3dfc139147cb3e0225985c2e425c9b12f884b8ff11d0ac676210e5537c2
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
engines:
|
2
|
+
duplications:
|
3
|
+
enabled: true
|
4
|
+
config:
|
5
|
+
languages:
|
6
|
+
ruby:
|
7
|
+
mass_threshold: 20
|
8
|
+
eslint:
|
9
|
+
enabled: true
|
10
|
+
checks:
|
11
|
+
import/extensions:
|
12
|
+
enabled: true
|
13
|
+
ratings:
|
14
|
+
paths:
|
15
|
+
- "**.rb"
|
16
|
+
exclude_paths:
|
17
|
+
- "Gemfile"
|
18
|
+
- "Gemfile.lock"
|
19
|
+
- "ratsel.gemspec"
|
20
|
+
- .gitignore
|
21
|
+
- "lib/ratsel/test.txt"
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: mCQfeXHNkBqg72S74JEtfejnZvHdXlOTP
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,50 @@
|
|
1
|
-
#
|
1
|
+
# Rätsel
|
2
2
|
[![Coverage Status](https://coveralls.io/repos/github/vynessa/ratsel/badge.svg?branch=develop)](https://coveralls.io/github/vynessa/ratsel?branch=develop)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/ratsel.svg)](https://badge.fury.io/rb/ratsel)
|
4
|
+
[![Build Status](https://travis-ci.org/vynessa/ratsel.svg?branch=develop)](https://travis-ci.org/vynessa/ratsel)
|
3
5
|
|
4
|
-
|
6
|
+
## Introduction
|
7
|
+
Rätsel is German for `Enigma`. Rätsel is an encryption tool that can take in messages, encrypt them for transmission, then decrypt messages we get from others.
|
8
|
+
|
9
|
+
### Features
|
10
|
+
<ul>
|
11
|
+
<li>Messages can be encrypted</li>
|
12
|
+
<li>Encrypted messages can be decrypted provided the encyption key and date are passed in</li>
|
13
|
+
<li>Encrypted messages can be cracked without the encryption key</li>
|
14
|
+
</ul>
|
15
|
+
|
16
|
+
## Getting started with the project
|
17
|
+
* Visit the [Wiki](https://github.com/vynessa/ratsel/wiki/Getting-Started-with-the-Project) to find out how to make use of this project.
|
18
|
+
|
19
|
+
## How to use the application
|
20
|
+
To utilize the functionality of this tool, on command line, run the following:
|
21
|
+
* To encrypt, run `encrypt <file> [<output>]`
|
22
|
+
* To decrypt, run `decrypt <encrypted-file> [<output>] <key> <date>`
|
23
|
+
* To crack, run `crack <encrypted-file> [<output>] <date>`
|
24
|
+
|
25
|
+
## Sample Encryption and Decryption
|
26
|
+
* Suppose we have a text file in a lib directory `test.txt` with the content below:
|
27
|
+
```hello hello ..end..```
|
28
|
+
* On running encrypt with our output as `new.txt`
|
29
|
+
```encrypt lib/test.txt lib/new.txt```
|
30
|
+
* The result will be
|
31
|
+
```6a43a6zv h7ow7w527q```
|
32
|
+
* Running decrypt and passing the output file, encryption key and date, we will then have:
|
33
|
+
```hello hello ..end..```
|
34
|
+
|
35
|
+
## Naming conventions
|
36
|
+
* Visit the [Wiki](https://github.com/vynessa/ratsel/wiki) to find branch, commit messages and pull request naming conventions.
|
37
|
+
## Contributing to the project
|
38
|
+
* Fork this repository to your github account
|
39
|
+
* Clone the repository - `git clone https://github.com/<your-repo-name>/ratsel.git`
|
40
|
+
* Create your feature branch - `git checkout -b your-branch-name`
|
41
|
+
* Commit your changes - `git commit -m “[Enter message]“` or `git commit` for the interactive interface
|
42
|
+
* Push to the remote branch - `git push origin your-branch-name`
|
43
|
+
* Open a pull request (See [wiki](https://github.com/vynessa/ratsel/wiki/Pull-Request-Naming-and-Description-Convention) for pull request(s) naming convention)
|
44
|
+
I look forward to your pull requests!
|
45
|
+
|
46
|
+
## License
|
47
|
+
[MIT License](https://github.com/vynessa/ratsel/blob/develop/LICENSE)
|
48
|
+
|
49
|
+
## Author
|
50
|
+
* **[Vanessa Ejikeme](https://www.linkedin.com/in/vanessa-ejikeme-68078b74/)**
|
data/lib/ratsel/crack.rb
CHANGED
@@ -1,55 +1,36 @@
|
|
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
1
|
module Ratsel
|
8
2
|
class Crack
|
9
3
|
include SendMessage
|
10
|
-
attr_reader :
|
4
|
+
attr_reader :encrypted_txt, :cracked_txt, :encryption_date, :encryption_key
|
11
5
|
|
12
|
-
def initialize(
|
6
|
+
def initialize(encrypted_txt, cracked_txt, encryption_date)
|
13
7
|
@encryption_key = nil
|
14
8
|
@encryption_date = encryption_date
|
15
|
-
@
|
9
|
+
@encrypted_txt = encrypted_txt
|
16
10
|
@cracked_txt = cracked_txt
|
17
|
-
@character_map = Cipher.character_map
|
18
11
|
end
|
19
12
|
|
20
13
|
def crack
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
offsets = Helpers.offsets_array(@encryption_date)
|
29
|
-
|
30
|
-
differences = get_differences(
|
31
|
-
|
32
|
-
|
14
|
+
last_char = '..end..'
|
15
|
+
encrypted_message = Ratsel::Accessor.read_file_text(encrypted_txt)
|
16
|
+
|
17
|
+
encrypted_message_last_4 = encrypted_message.last(4)
|
18
|
+
last_4_char = last_char.split("").last(4)
|
19
|
+
encrypted_message_last_4.rotate!(4 - (encrypted_message.size % 4))
|
20
|
+
last_4_char.rotate!(4 - (encrypted_message.size % 4))
|
21
|
+
offsets = Ratsel::Helpers.offsets_array(@encryption_date)
|
22
|
+
|
23
|
+
differences = Ratsel::Helpers.get_differences(
|
24
|
+
encrypted_message_last_4,
|
25
|
+
last_4_char,
|
33
26
|
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]))
|
27
|
+
)
|
47
28
|
|
48
|
-
|
49
|
-
|
50
|
-
end
|
29
|
+
# Get the missing key
|
30
|
+
key = Ratsel::Helpers.get_key(differences)
|
51
31
|
|
52
|
-
|
32
|
+
# Initialize Decrypt method with the missing key
|
33
|
+
Ratsel::Decrypt.new(encrypted_txt, cracked_txt, key, encryption_date).decrypt
|
53
34
|
end
|
54
35
|
end
|
55
36
|
end
|
data/lib/ratsel/decrypt.rb
CHANGED
@@ -2,7 +2,6 @@ require_relative "helpers/accessor"
|
|
2
2
|
require_relative "helpers/cipher"
|
3
3
|
require_relative "helpers/helpers"
|
4
4
|
require_relative "helpers/message"
|
5
|
-
|
6
5
|
require 'json'
|
7
6
|
|
8
7
|
module Ratsel
|
@@ -10,12 +9,8 @@ module Ratsel
|
|
10
9
|
include SendMessage
|
11
10
|
attr_reader :encryption_key, :encrypted_txt, :decrypt_txt, :character_map,
|
12
11
|
:sum_rotation_offset, :encryption_date
|
13
|
-
|
14
|
-
|
15
|
-
decrypt_txt,
|
16
|
-
encryption_key,
|
17
|
-
encryption_date
|
18
|
-
)
|
12
|
+
|
13
|
+
def initialize(encrypted_txt, decrypt_txt, encryption_key, encryption_date)
|
19
14
|
@encryption_key = encryption_key
|
20
15
|
@encrypted_txt = encrypted_txt
|
21
16
|
@decrypt_txt = decrypt_txt
|
@@ -50,9 +45,7 @@ module Ratsel
|
|
50
45
|
|
51
46
|
message(decrypt_txt, encryption_key, encryption_date)
|
52
47
|
|
53
|
-
|
54
|
-
line.write("#{decrypted_message}")
|
55
|
-
end
|
48
|
+
Accessor.write_encrypted_texts(decrypt_txt, decrypted_message)
|
56
49
|
|
57
50
|
decrypted_message
|
58
51
|
end
|
data/lib/ratsel/encrypt.rb
CHANGED
@@ -21,32 +21,35 @@ module Ratsel
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def encrypt
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
begin
|
25
|
+
message = Accessor.read_file_text(@message_txt)
|
26
|
+
encrypted_message = ''
|
27
|
+
sliced_message_array = []
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
message.each_slice(4) { |message|
|
30
|
+
sliced_message_array << message.join('')
|
31
|
+
}
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
sliced_message_array.each_with_index { |batch, index|
|
34
|
+
message_batch = batch.downcase.split('')
|
35
|
+
n = message_batch.length
|
36
|
+
|
37
|
+
n.times { |i|
|
38
|
+
char_rotate = @character_map.rotate(@character_map.index(message_batch.shift))
|
39
|
+
rotated_array = char_rotate.rotate(@sum_rotation_offset[i])
|
40
|
+
encrypted_message << rotated_array.shift
|
41
|
+
}
|
40
42
|
}
|
41
|
-
}
|
42
43
|
|
43
|
-
|
44
|
+
message(encrypted_txt, encryption_key, encryption_date)
|
45
|
+
|
46
|
+
Accessor.write_encrypted_texts(encrypted_txt, encrypted_message)
|
47
|
+
|
48
|
+
encrypted_message
|
44
49
|
|
45
|
-
|
46
|
-
|
50
|
+
rescue TypeError => e
|
51
|
+
puts "#{e}\nMake sure the characters in your text file are numbers, letters, a period, space or comma."
|
47
52
|
end
|
48
|
-
|
49
|
-
encrypted_message
|
50
53
|
end
|
51
54
|
end
|
52
55
|
end
|
@@ -3,18 +3,15 @@ module Ratsel
|
|
3
3
|
# Read text from file
|
4
4
|
def self.read_file_text(text_file)
|
5
5
|
message = ''
|
6
|
-
File.open(text_file
|
6
|
+
File.open(text_file).each { |line| message += line }
|
7
7
|
new_message = message.downcase.split('')
|
8
8
|
end
|
9
9
|
|
10
|
-
#
|
11
|
-
def self.write_encrypted_texts(
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
}
|
16
|
-
|
17
|
-
encrypted_object
|
10
|
+
# Encrypted info
|
11
|
+
def self.write_encrypted_texts(encrypted_txt, encrypted_message)
|
12
|
+
File.open(encrypted_txt, "w") do |line|
|
13
|
+
line.write("#{encrypted_message}")
|
14
|
+
end
|
18
15
|
end
|
19
16
|
end
|
20
17
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require_relative "helpers"
|
2
|
-
# require_relative "cipher"
|
3
1
|
module Ratsel
|
4
2
|
class Helpers
|
5
3
|
# Get offsets array from the date of message transmission
|
@@ -35,7 +33,22 @@ module Ratsel
|
|
35
33
|
sum_array
|
36
34
|
end
|
37
35
|
|
38
|
-
|
36
|
+
def self.get_differences(encrypted_message, end_char, offsets)
|
37
|
+
@character_map = Ratsel::Cipher.character_map
|
38
|
+
differences = []
|
39
|
+
|
40
|
+
4.times do |i|
|
41
|
+
diff = (@character_map.index(encrypted_message[i]) -
|
42
|
+
@character_map.index(end_char[i]))
|
43
|
+
|
44
|
+
diff -= offsets[i].to_i
|
45
|
+
differences[i] = diff.to_s.rjust(2, '0')
|
46
|
+
end
|
47
|
+
|
48
|
+
differences
|
49
|
+
end
|
50
|
+
|
51
|
+
# Get encryption key
|
39
52
|
def self.get_key(differences)
|
40
53
|
key_array = []
|
41
54
|
differences.each_with_index do |value, index|
|
data/lib/ratsel/version.rb
CHANGED
data/ratsel.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ratsel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vanessa Ejikeme
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
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'
|
69
83
|
description: Ratsel is used in encryption and decrypting text from a file.
|
70
84
|
email:
|
71
85
|
- vanessa.ejikeme@gmail.com
|
@@ -76,6 +90,8 @@ executables:
|
|
76
90
|
extensions: []
|
77
91
|
extra_rdoc_files: []
|
78
92
|
files:
|
93
|
+
- ".codeclimate.yml"
|
94
|
+
- ".coveralls.yml"
|
79
95
|
- ".gitignore"
|
80
96
|
- ".rspec"
|
81
97
|
- ".travis.yml"
|