obfuscated_morse_code 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 +3 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +21 -0
- data/README.md +79 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/obfuscate_morse_code.exe +8 -0
- data/bin/setup +8 -0
- data/lib/obfuscated_morse_code/dictionary.rb +42 -0
- data/lib/obfuscated_morse_code/file_parser.rb +17 -0
- data/lib/obfuscated_morse_code/morse_code_translator.rb +49 -0
- data/lib/obfuscated_morse_code/version.rb +5 -0
- data/lib/obfuscated_morse_code.rb +14 -0
- data/obfuscated_morse_code.gemspec +39 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 32c9c499c9a98131edcd41623d80622f3488864b36702a3d67802f8b77dffc69
|
4
|
+
data.tar.gz: ee2bcc70a3f15fbc7bda4be6cb5126c23124c9ea622f46689e174b63488ee4fd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d9dec4c43179740cca5e2c514f4ba7bcd693b1c09dd0a7c3208cc737b750c57d61941759844de0b0a2088d7b7acfa726bb897d651c477fa235dba69ba5468a5b
|
7
|
+
data.tar.gz: ac6b0e55efb414ac7fa44de8ca5471828b0ebd9c9b76d319b8745055b2dfa04dd5240aa19bcf4b77fe90fd559a19b824bb0dac15c60bd2056ef161e0156cc2ab
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
obfuscated_morse_code (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.0)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
jaro_winkler (1.5.4)
|
12
|
+
parallel (1.19.1)
|
13
|
+
parser (2.6.5.0)
|
14
|
+
ast (~> 2.4.0)
|
15
|
+
rainbow (3.0.0)
|
16
|
+
rake (10.5.0)
|
17
|
+
rspec (3.9.0)
|
18
|
+
rspec-core (~> 3.9.0)
|
19
|
+
rspec-expectations (~> 3.9.0)
|
20
|
+
rspec-mocks (~> 3.9.0)
|
21
|
+
rspec-core (3.9.0)
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-expectations (3.9.0)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.9.0)
|
26
|
+
rspec-mocks (3.9.0)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.9.0)
|
29
|
+
rspec-support (3.9.0)
|
30
|
+
rubocop (0.77.0)
|
31
|
+
jaro_winkler (~> 1.5.1)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 2.6)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
ruby-progressbar (~> 1.7)
|
36
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
37
|
+
ruby-progressbar (1.10.1)
|
38
|
+
unicode-display_width (1.6.0)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
ruby
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
bundler (~> 1.16)
|
45
|
+
obfuscated_morse_code!
|
46
|
+
rake (~> 10.0)
|
47
|
+
rspec (~> 3.0)
|
48
|
+
rubocop (~> 0.77.0)
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
1.16.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Martin Svoboda
|
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,79 @@
|
|
1
|
+
# ObfuscatedMorseCode
|
2
|
+
|
3
|
+
Translates messages into Morse Code and then obfuscates them following these rules:
|
4
|
+
|
5
|
+
> Replace the number of consecutive dots with a number, and replace the number of consecutive dashes with the letter of the alphabet at that position. E.g. S = ... = 3, Q = --.- = b1a, F = ..-. = 2a1.
|
6
|
+
|
7
|
+
### Morse Code Dictionary
|
8
|
+
|
9
|
+
International Morse Code
|
10
|
+
- A .-
|
11
|
+
- B -...
|
12
|
+
- C -.-.
|
13
|
+
- D -..
|
14
|
+
- E .
|
15
|
+
- F ..-.
|
16
|
+
- G --.
|
17
|
+
- H ....
|
18
|
+
- I ..
|
19
|
+
- J .---
|
20
|
+
- K -.-
|
21
|
+
- L .-..
|
22
|
+
- M --
|
23
|
+
- N -.
|
24
|
+
- O ---
|
25
|
+
- P .--.
|
26
|
+
- Q --.-
|
27
|
+
- R .-.
|
28
|
+
- S ...
|
29
|
+
- T -
|
30
|
+
- U ..-
|
31
|
+
- V ...-
|
32
|
+
- W .--
|
33
|
+
- X -..-
|
34
|
+
- Y -.--
|
35
|
+
- Z --..
|
36
|
+
- 0 -----
|
37
|
+
- 1 .----
|
38
|
+
- 2 ..---
|
39
|
+
- 3 ...--
|
40
|
+
- 4 ....-
|
41
|
+
- 5 .....
|
42
|
+
- 6 -....
|
43
|
+
- 7 --...
|
44
|
+
- 8 ---..
|
45
|
+
- 9 ----.
|
46
|
+
- Fullstop .-.-.-
|
47
|
+
- Comma --..--
|
48
|
+
|
49
|
+
## Installation
|
50
|
+
|
51
|
+
Add this line to your application's Gemfile:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
gem 'obfuscated_morse_code'
|
55
|
+
```
|
56
|
+
|
57
|
+
And then execute:
|
58
|
+
|
59
|
+
$ bundle
|
60
|
+
|
61
|
+
Or install it yourself as:
|
62
|
+
|
63
|
+
$ gem install obfuscated_morse_code
|
64
|
+
|
65
|
+
## Usage
|
66
|
+
|
67
|
+
You can use this gem from your terminal by running:
|
68
|
+
|
69
|
+
```bash
|
70
|
+
obfuscated_morse_code file_name.txt
|
71
|
+
```
|
72
|
+
|
73
|
+
## Development
|
74
|
+
|
75
|
+
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.
|
76
|
+
|
77
|
+
## License
|
78
|
+
|
79
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'obfuscated_morse_code'
|
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__)
|
data/bin/setup
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
MORSE_CODE = {
|
4
|
+
'A' => '.-',
|
5
|
+
'B' => '-...',
|
6
|
+
'C' => '-.-.',
|
7
|
+
'D' => '-..',
|
8
|
+
'E' => '.',
|
9
|
+
'F' => '..-.',
|
10
|
+
'G' => '--.',
|
11
|
+
'H' => '....',
|
12
|
+
'I' => '..',
|
13
|
+
'J' => '.---',
|
14
|
+
'K' => '-.-',
|
15
|
+
'L' => '.-..',
|
16
|
+
'M' => '--',
|
17
|
+
'N' => '-.',
|
18
|
+
'O' => '---',
|
19
|
+
'P' => '.--.',
|
20
|
+
'Q' => '--.-',
|
21
|
+
'R' => '.-.',
|
22
|
+
'S' => '...',
|
23
|
+
'T' => '-',
|
24
|
+
'U' => '..-',
|
25
|
+
'V' => '...-',
|
26
|
+
'W' => '.--',
|
27
|
+
'X' => '-..-',
|
28
|
+
'Y' => '-.--',
|
29
|
+
'Z' => '--..',
|
30
|
+
'0' => '-----',
|
31
|
+
'1' => '.----',
|
32
|
+
'2' => '..---',
|
33
|
+
'3' => '...--',
|
34
|
+
'4' => '....-',
|
35
|
+
'5' => '.....',
|
36
|
+
'6' => '-....',
|
37
|
+
'7' => '--...',
|
38
|
+
'8' => '---..',
|
39
|
+
'9' => '----.',
|
40
|
+
'.' => '.-.-.-',
|
41
|
+
',' => '--..--'
|
42
|
+
}.freeze
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ObfuscatedMorseCode
|
2
|
+
class FileParser
|
3
|
+
attr_reader :file_path
|
4
|
+
|
5
|
+
FileNotFoundError = Class.new(StandardError)
|
6
|
+
|
7
|
+
def initialize(file_path)
|
8
|
+
@file_path = file_path
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse
|
12
|
+
File.open(file_path).reduce([], &:<<).map(&:strip)
|
13
|
+
rescue Errno::ENOENT
|
14
|
+
raise FileNotFoundError, "Couldn't locate file: '#{file_path}'"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'obfuscated_morse_code/dictionary'
|
4
|
+
|
5
|
+
module ObfuscatedMorseCode
|
6
|
+
class MorseCodeTranslator
|
7
|
+
attr_reader :letter_separator, :word_separator
|
8
|
+
|
9
|
+
def initialize(letter_separator: '|', word_separator: '/')
|
10
|
+
@letter_separator = letter_separator
|
11
|
+
@word_separator = word_separator
|
12
|
+
end
|
13
|
+
|
14
|
+
def translate(sentences)
|
15
|
+
sentences.map do |sentence|
|
16
|
+
letters = sentence.split('')
|
17
|
+
translate_letters(letters)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def translate_letters(letters)
|
24
|
+
translated_letters = ''
|
25
|
+
letters.each_with_index do |letter, i|
|
26
|
+
next_letter = letters[i + 1]
|
27
|
+
translated_letters += translate_letter(letter)
|
28
|
+
unless letter == ' '
|
29
|
+
translated_letters += word_separator_for(next_letter)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
translated_letters
|
33
|
+
end
|
34
|
+
|
35
|
+
def translate_letter(letter)
|
36
|
+
return '' if letter == ' '
|
37
|
+
raise ArgumentError, "cannot translate character #{letter}" unless MORSE_CODE.key?(letter)
|
38
|
+
|
39
|
+
MORSE_CODE[letter]
|
40
|
+
end
|
41
|
+
|
42
|
+
def word_separator_for(next_letter)
|
43
|
+
return word_separator if next_letter == ' '
|
44
|
+
return '' if next_letter.nil?
|
45
|
+
|
46
|
+
letter_separator
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'obfuscated_morse_code/version'
|
4
|
+
require 'obfuscated_morse_code/file_parser'
|
5
|
+
require 'obfuscated_morse_code/morse_code_translator'
|
6
|
+
|
7
|
+
module ObfuscatedMorseCode
|
8
|
+
def self.morse_code(file_path)
|
9
|
+
parsed_text = FileParser.new(file_path).parse
|
10
|
+
MorseCodeTranslator.new.translate(parsed_text).join("\n")
|
11
|
+
rescue FileParser::FileNotFoundError => e
|
12
|
+
puts e.message
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'obfuscated_morse_code/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'obfuscated_morse_code'
|
9
|
+
spec.version = ObfuscatedMorseCode::VERSION
|
10
|
+
spec.authors = ['Martin Svoboda']
|
11
|
+
spec.email = ['svobom57@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Provides a terminal utility for generating obfuscated morse code.'
|
14
|
+
spec.homepage = 'https://github.com/svobom57'
|
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['homepage_uri'] = spec.homepage
|
21
|
+
else
|
22
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
23
|
+
'public gem pushes.'
|
24
|
+
end
|
25
|
+
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
29
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
30
|
+
end
|
31
|
+
spec.bindir = 'exe'
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ['lib']
|
34
|
+
|
35
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
36
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
37
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
38
|
+
spec.add_development_dependency 'rubocop', '~> 0.77.0'
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: obfuscated_morse_code
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Martin Svoboda
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-12 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.77.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.77.0
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- svobom57@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/obfuscate_morse_code.exe
|
85
|
+
- bin/setup
|
86
|
+
- lib/obfuscated_morse_code.rb
|
87
|
+
- lib/obfuscated_morse_code/dictionary.rb
|
88
|
+
- lib/obfuscated_morse_code/file_parser.rb
|
89
|
+
- lib/obfuscated_morse_code/morse_code_translator.rb
|
90
|
+
- lib/obfuscated_morse_code/version.rb
|
91
|
+
- obfuscated_morse_code.gemspec
|
92
|
+
homepage: https://github.com/svobom57
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata:
|
96
|
+
homepage_uri: https://github.com/svobom57
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.7.9
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Provides a terminal utility for generating obfuscated morse code.
|
117
|
+
test_files: []
|