m0rse_c0de 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/hashes/hashes.rb +37 -0
- data/lib/m0rse.rb +97 -0
- data/lib/sound/beeps/dah.wav +0 -0
- data/lib/sound/beeps/dit.wav +0 -0
- data/lib/sound/sound.rb +14 -0
- data/lib/teacher/teacher.rb +60 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9eb1fb3219850819528a0bd49f8a99e3e936e53e8c7379f9668ca8b5fb9cf3b2
|
4
|
+
data.tar.gz: 0bbc27f020c3d92e6da368c1a6092b187c885d885f07ef12ed4edf889a59266b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d01a7092562bad0ed4b8126b93168328be518ae50f5ef44f365dc2b46bba0e241a350dd6a70ed24b1c1e65f206cf289c877819128122531f997c4d3b4e23536c
|
7
|
+
data.tar.gz: bddeb55b32e50761640b3101145dd4f0d1403d7d20139a05819547263ed3ba650be54e69cceeb51cff54389800b5b7258b80a26df5778fbef3a381141e271277
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
#Required hash for translation
|
4
|
+
|
5
|
+
module Translation
|
6
|
+
@@asciitomorse = {'a' => '.-', 'b' => '-...',
|
7
|
+
'c' => '-.-.', 'd' => '-..', 'e' => '.',
|
8
|
+
'f' => '..-.', 'g' => '--.', 'h' => '....',
|
9
|
+
'i' => '..', 'j' => '.---', 'k' => '-.-',
|
10
|
+
'l' => '.-..', 'm' => '--', 'n' => '-.',
|
11
|
+
'o' => '---', 'p' => '.--.', 'q' => '--.-',
|
12
|
+
'r' => '.-.', 's' => '...', 't' => '-',
|
13
|
+
'u' => '..-', 'v' => '...-', 'w' => '.--',
|
14
|
+
'x'=> '-..-', 'y' => '-.--', 'z' => '--..',
|
15
|
+
'1' => '.----', '2' => '..---', '3' => '...--',
|
16
|
+
'4' => '....-', '5' => '.....', '6' => '-....',
|
17
|
+
'7' => '--...', '8' => '---..', '9' => '----.',
|
18
|
+
'0' => '-----', ', ' => '--..--', '.' => '.-.-.-',
|
19
|
+
'?' => '..--..', '/' => '-..-.', '-' => '-....-', ' ' => '\\'}
|
20
|
+
|
21
|
+
@@morsetoascii = {'.-' => 'a', '-...' => 'b',
|
22
|
+
'-.-.' => 'c', '-..' => 'd', '.' => 'e',
|
23
|
+
'..-.' => 'f', '--.' => 'g', '....' => 'h',
|
24
|
+
'..' => 'i', '.---' => 'j', '-.-' => 'k',
|
25
|
+
'.-..' => 'l', '--' => 'm', '-.' => 'n',
|
26
|
+
'---' => 'o', '.--.' => 'p', '--.-' => 'q',
|
27
|
+
'.-.' => 'r', '...' => 's', '-' => 't',
|
28
|
+
'..-' => 'u', '...-' => 'v', '.--' => 'w',
|
29
|
+
'-..-'=> 'x', '-.--' => 'y', '--..' => 'z',
|
30
|
+
'.----' => '1', '..---' => '2', '...--' => '3',
|
31
|
+
'....-' => '4', '.....' => '5', '-....' => '6',
|
32
|
+
'--...' => '7', '---..' => '8', '----.' => '9',
|
33
|
+
'-----' => '0', '--..--' => ',', '.-.-.-' => '.',
|
34
|
+
'..--..' => '?', '-..-.' => '/', '-....-' => '-', '\\' => ' '}
|
35
|
+
|
36
|
+
|
37
|
+
end
|
data/lib/m0rse.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require_relative './hashes/hashes.rb'
|
2
|
+
begin
|
3
|
+
require_relative './sound/sound.rb'
|
4
|
+
rescue
|
5
|
+
puts "Morse.play method won't work for #{RUBY_PLATFORM}"
|
6
|
+
end
|
7
|
+
require_relative './teacher/teacher.rb'
|
8
|
+
|
9
|
+
include Translation
|
10
|
+
include Te4cher
|
11
|
+
begin
|
12
|
+
include Beeper
|
13
|
+
rescue
|
14
|
+
end
|
15
|
+
|
16
|
+
module M0rse
|
17
|
+
|
18
|
+
class Morse
|
19
|
+
|
20
|
+
def self.text_to_morse(text_)
|
21
|
+
morse_ = []
|
22
|
+
text_.downcase!
|
23
|
+
for char in text_.split(//)
|
24
|
+
morse_.append @@asciitomorse[char]
|
25
|
+
end
|
26
|
+
result_ = morse_.join(' ')
|
27
|
+
return result_
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def self.morse_to_text(morse_)
|
32
|
+
text_ = []
|
33
|
+
for char in morse_.split(/ /)
|
34
|
+
text_.append @@morsetoascii[char]
|
35
|
+
end
|
36
|
+
result_ = text_.join('')
|
37
|
+
return result_
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def self.morse_to_binary(morse_)
|
42
|
+
text_ = self.morse_to_text(morse_)
|
43
|
+
result_ = text_.unpack('B*')[0]
|
44
|
+
return result_
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.binary_to_morse(binary_)
|
48
|
+
text_ = Array(binary_).pack('B*')
|
49
|
+
result_ = self.text_to_morse(text_)
|
50
|
+
return result_
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.morse_to_hex(morse_)
|
54
|
+
text_ = self.morse_to_text(morse_)
|
55
|
+
result_ = text_.unpack('H*')[0]
|
56
|
+
return result_
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.hex_to_morse(hex_)
|
60
|
+
text_ = Array(hex_).pack('H*')
|
61
|
+
result_ = self.text_to_morse(text_)
|
62
|
+
return result_
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.file_to_morse(filename_)
|
66
|
+
file_ = File.open(filename_, 'r+')
|
67
|
+
text_ = file_.readlines.map(&:chomp).join()
|
68
|
+
result_ = self.text_to_morse(text_)
|
69
|
+
file_.close()
|
70
|
+
File.open("#{filename_}-Morsed", "w").write(result_)
|
71
|
+
end
|
72
|
+
begin
|
73
|
+
def self.play(text_)
|
74
|
+
morse_ = self.text_to_morse(text_)
|
75
|
+
for sign in morse_.split(//)
|
76
|
+
if sign == '.'
|
77
|
+
Beeper.dit
|
78
|
+
elsif sign == '-'
|
79
|
+
Beeper.dah
|
80
|
+
elsif sign == ' '
|
81
|
+
sleep(0.375)
|
82
|
+
elsif sign == '\\'
|
83
|
+
sleep(0.875)
|
84
|
+
end
|
85
|
+
end; "completed"
|
86
|
+
end
|
87
|
+
rescue
|
88
|
+
ensure
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.teach
|
92
|
+
Teacher.main
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
Binary file
|
Binary file
|
data/lib/sound/sound.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
|
2
|
+
module Te4cher
|
3
|
+
class Teacher
|
4
|
+
|
5
|
+
def self.start_practice
|
6
|
+
@words = ['Ruby', 'Red', 'Awesome', 'Burzum', 'Help', 'Blood', 'Emergency', 'Death', 'Morse', 'SOS', 'SQL', 'Wreck', 'Ship', 'You', 'Us', 'America', 'Boat', 'Hello', 'Amazed', 'Python', 'Life', 'acme', 'antiseptically', 'boudoir', 'cesium', 'circumscribing', 'collegians', 'confessionals', 'erectly', 'finagler', 'hostelries', 'howdah', 'impetigo', 'lampposts', 'lisle', 'mestizos', 'overcooked', 'slippage', 'slouchiest', 'strumpet', 'terabyte', 'transfiguration', 'twill', 'undersold', 'unsheathed', 'whelps', 'adlumidine', 'alinasal', 'aramina', 'begreen', 'bembixes', 'boundly', 'cannibalean', 'chondrinous', 'colickiest', 'cullas', 'hartake', 'interchangings', 'marquito', 'miscegenationists', 'peremption', 'quesitive', 'ragnarok', 'reconciliated', 'sepsine', 'sickless', 'sigillaria', 'staphyledema', 'undelible', 'unruth', 'yaourti', 'avoid', 'bottle', 'briefly', 'bug', 'dedicated', 'establish', 'everything', 'goes', 'harm', 'inferior', 'killed', 'leader', 'noticed', 'quicker', 'recovered', 'reflects', 'retain', 'self', 'should', 'signal', 'simultaneously', 'stayed', 'tomorrow', 'virtue', 'weird', 'adlumidine', 'alinasal', 'aramina', 'begreen', 'bembixes', 'boundly', 'cannibalean', 'chondrinous', 'colickiest', 'cullas', 'hartake', 'interchangings', 'marquito', 'miscegenationists', 'peremption', 'quesitive', 'ragnarok', 'reconciliated', 'sepsine', 'sickless', 'sigillaria', 'staphyledema', 'undelible', 'unruth', 'yaourti'] #todo: complete
|
7
|
+
|
8
|
+
puts "PRACTICE MODE STARTED"
|
9
|
+
|
10
|
+
while true
|
11
|
+
random_word = @words.sample.upcase!
|
12
|
+
correct_answer = Morse.text_to_morse(random_word)
|
13
|
+
puts "translate ---> #{random_word}"
|
14
|
+
print 'Your answer: '
|
15
|
+
user_answer = gets.chomp.strip
|
16
|
+
if user_answer == correct_answer
|
17
|
+
puts 'Correct! Moving to the next word...'
|
18
|
+
sleep(2)
|
19
|
+
else
|
20
|
+
puts "Wrong! The correct answer was: #{correct_answer}, moving to the next word..."
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.show_hashes
|
26
|
+
for char, morse in @@asciitomorse
|
27
|
+
print char, ' --> ', morse, ' '
|
28
|
+
end; 'Morse Alphabet'
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def self.main
|
33
|
+
greeting = '''
|
34
|
+
|
35
|
+
Welcome to teaching mode! If you want to practice: enter input PRACTICE,
|
36
|
+
if you want to view the Morse alphabet input ALPHABET.
|
37
|
+
|
38
|
+
'''
|
39
|
+
|
40
|
+
puts greeting
|
41
|
+
|
42
|
+
@choice = gets.chomp
|
43
|
+
|
44
|
+
if @choice == 'PRACTICE'
|
45
|
+
self.start_practice
|
46
|
+
|
47
|
+
elsif @choice == 'ALPHABET'
|
48
|
+
self.show_hashes
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: m0rse_c0de
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Burzum
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: win32-sound
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.6.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.6.2
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/hashes/hashes.rb
|
34
|
+
- lib/m0rse.rb
|
35
|
+
- lib/sound/beeps/dah.wav
|
36
|
+
- lib/sound/beeps/dit.wav
|
37
|
+
- lib/sound/sound.rb
|
38
|
+
- lib/teacher/teacher.rb
|
39
|
+
homepage:
|
40
|
+
licenses: []
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubygems_version: 3.0.3
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: A gem for translation from hex, binary, text to morse and vice versa; it
|
61
|
+
additionally can teach you Morse, play a text to Morse code and translate a file
|
62
|
+
to Morse. (playing morse code is for windows only :( )
|
63
|
+
test_files: []
|