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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33bd72862b50995d74e3e2a8eb41060c4c1a1326
4
- data.tar.gz: b27e88682a2cffb389238dc9ff6fe9eba5f187bd
3
+ metadata.gz: 1d391b1a71dd2f6afb1b5766b181fd31dd1d656c
4
+ data.tar.gz: 1ce2b4a3f829f426544c2b3396b18b4e7b66b73f
5
5
  SHA512:
6
- metadata.gz: 274e78b12b807439e08a3b74ad5b3c6d3c46db3a0c3aaa10153c20fe39f76a4912fb0ae7238a93a4983ba90451cf57e1a06696dc8def16138c01c4f42a682dad
7
- data.tar.gz: 1dda2f31cf68850b01d3889d011bd9f3d85c98c39fe1408fcd285c63b6f566ab553edea690e85ca6d42406d63fefda0342feb7113d79d35fc3a18dcfdf396df9
6
+ metadata.gz: 769b18c89e6932cf393107ea90b04aa37df53187546d43995ad25530287db15c6ca86778845bfc522776b569cb26e8c4f320b7ac0016731c7432c884dafe02c9
7
+ data.tar.gz: 4dfe71be8e3a4c61e068c34e127ad1cd021b861978f44762b3e53d07319cc91adcc8b3dfc139147cb3e0225985c2e425c9b12f884b8ff11d0ac676210e5537c2
@@ -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"
@@ -0,0 +1 @@
1
+ repo_token: mCQfeXHNkBqg72S74JEtfejnZvHdXlOTP
@@ -1,5 +1,5 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
3
  - 2.4.1
5
- before_install: gem install bundler -v 1.15.4
4
+ after_success:
5
+ - cat ./coverage/lcov.info
data/README.md CHANGED
@@ -1,4 +1,50 @@
1
- # Ratsel
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
- Ratsel is German for `Enigma`
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/)**
@@ -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 :decrypted_txt, :cracked_txt, :encryption_date, :encryption_key
4
+ attr_reader :encrypted_txt, :cracked_txt, :encryption_date, :encryption_key
11
5
 
12
- def initialize(decrypted_txt, cracked_txt, encryption_date)
6
+ def initialize(encrypted_txt, cracked_txt, encryption_date)
13
7
  @encryption_key = nil
14
8
  @encryption_date = encryption_date
15
- @decrypted_txt = decrypted_txt
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
- 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,
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
- diff -= offsets[i].to_i
49
- differences[i] = diff.to_s.rjust(2, '0')
50
- end
29
+ # Get the missing key
30
+ key = Ratsel::Helpers.get_key(differences)
51
31
 
52
- differences
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
@@ -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
- def initialize(
14
- encrypted_txt,
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
- File.open(decrypt_txt, "a") do |line|
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
@@ -21,32 +21,35 @@ module Ratsel
21
21
  end
22
22
 
23
23
  def encrypt
24
- message = Accessor.read_file_text(@message_txt)
25
- encrypted_message = ''
26
- sliced_message_array = []
24
+ begin
25
+ message = Accessor.read_file_text(@message_txt)
26
+ encrypted_message = ''
27
+ sliced_message_array = []
27
28
 
28
- message.each_slice(4) { |message|
29
- sliced_message_array << message.join('')
30
- }
29
+ message.each_slice(4) { |message|
30
+ sliced_message_array << message.join('')
31
+ }
31
32
 
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
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
- message(encrypted_txt, encryption_key, encryption_date)
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
- File.open(encrypted_txt, "a") do |line|
46
- line.write("#{encrypted_message}")
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, 'rb').each { |line| message += line }
6
+ File.open(text_file).each { |line| message += line }
7
7
  new_message = message.downcase.split('')
8
8
  end
9
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
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
@@ -5,7 +5,7 @@ module Ratsel
5
5
  'f', 'g', 'h', 'i', 'j', 'k',
6
6
  'l', 'm', 'n', 'o', 'p', 'q',
7
7
  'r', 's', 't', 'u', 'v', 'w',
8
- 'x', 'y', 'z', '1', '2', '3', '4', '5',
8
+ 'x', 'y', 'z', '0', '1', '2', '3', '4', '5',
9
9
  '6', '7', '8', '9', ' ', '.', ',']
10
10
  end
11
11
  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
- # Get key
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|
@@ -1,3 +1,3 @@
1
1
  module Ratsel
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -34,4 +34,5 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency "rake", "~> 10.0"
35
35
  spec.add_development_dependency "rspec", "~> 3.0"
36
36
  spec.add_development_dependency "coveralls", '~> 0'
37
+ spec.add_development_dependency "simplecov", '~> 0'
37
38
  end
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.0
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: 2017-12-07 00:00:00.000000000 Z
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"