Gemnigma 0.0.2
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/.coveralls.yml +2 -0
- data/.gitignore +14 -0
- data/.travis.yml +17 -0
- data/Gemfile +4 -0
- data/Gemnigma.gemspec +24 -0
- data/LICENSE.txt +22 -0
- data/README.md +87 -0
- data/Rakefile +8 -0
- data/bin/Gemnigma +184 -0
- data/helpers/char_map.rb +11 -0
- data/helpers/cipher_decrypt.rb +9 -0
- data/helpers/cipher_encrypt.rb +10 -0
- data/helpers/key.rb +25 -0
- data/helpers/messages.rb +44 -0
- data/helpers/offset.rb +26 -0
- data/helpers/rotator_decrypt.rb +16 -0
- data/helpers/rotator_encrypt.rb +62 -0
- data/helpers/validate_file_arg.rb +38 -0
- data/lib/Gemnigma/crack.rb +199 -0
- data/lib/Gemnigma/decrypt.rb +64 -0
- data/lib/Gemnigma/encrypt.rb +45 -0
- data/lib/Gemnigma/helpers.rb +4 -0
- data/lib/Gemnigma/version.rb +3 -0
- data/lib/Gemnigma.rb +7 -0
- data/message.txt +1 -0
- data/spec/Gemnigma_spec.rb +55 -0
- data/spec/char_map_spec.rb +38 -0
- data/spec/cipher_decrypt_spec.rb +55 -0
- data/spec/cipher_encrypt_spec.rb +43 -0
- data/spec/crack_spec.rb +170 -0
- data/spec/decrypt_spec.rb +108 -0
- data/spec/encrypt_spec.rb +61 -0
- data/spec/key_spec.rb +48 -0
- data/spec/messages_spec.rb +161 -0
- data/spec/offset_spec.rb +62 -0
- data/spec/rotator_decrypt_spec.rb +21 -0
- data/spec/rotator_encrypt_spec.rb +130 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/validate_file_arg_spec.rb +49 -0
- data/spec/version_spec.rb +11 -0
- metadata +156 -0
@@ -0,0 +1,108 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe Gemnigma::Decrypt do
|
4
|
+
before :each do
|
5
|
+
@dec = Gemnigma::Decrypt.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be a subclass of RotatorDecrypt" do
|
9
|
+
expect(Gemnigma::Decrypt.superclass).to eql(Gemnigma::RotatorDecrypt)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be an instance of the class Decrypt" do
|
13
|
+
expect(@dec).to be_an_instance_of Gemnigma::Decrypt
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#get_cmd_args" do
|
17
|
+
it "should take no arguments" do
|
18
|
+
expect{ @dec.get_cmd_args(123) }.to raise_error(ArgumentError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should display an error message if few arguments are passed as command line arguments" do
|
22
|
+
|
23
|
+
io = double("io", puts: nil)
|
24
|
+
message = Gemnigma::Messages.new(io)
|
25
|
+
message.few_args
|
26
|
+
|
27
|
+
expect(io).to have_received(:puts).with("Not enough arguments passed in. Run Gemnigma --help for instructions on usage\nExiting...")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should display an error message if too many arguments are passed as command line arguments" do
|
31
|
+
|
32
|
+
io = double("io", puts: nil)
|
33
|
+
message = Gemnigma::Messages.new(io)
|
34
|
+
message.too_much_args
|
35
|
+
|
36
|
+
expect(io).to have_received(:puts).with("Too many arguments passed in. Run Gemnigma --help for instructions on usage\nExiting...")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#true_key?" do
|
41
|
+
it "should be a private method" do
|
42
|
+
expect{ @dec.true_key? }.to raise_error (NoMethodError)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should take one argument only" do
|
46
|
+
expect{ @dec.send(:true_key?) }.to raise_error(ArgumentError)
|
47
|
+
expect{ @dec.send(:true_key?, "41521", "32415") }.to raise_error(ArgumentError)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return true for valid keys" do
|
51
|
+
expect(@dec.send(:true_key?, "31292")).to be true
|
52
|
+
expect(@dec.send(:true_key?, "43556")).to be true
|
53
|
+
expect(@dec.send(:true_key?, "41521")).to be true
|
54
|
+
expect(@dec.send(:true_key?, "12345")).to be true
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return false for invalid keys" do
|
58
|
+
expect(@dec.send(:true_key?, "abcde")).to be false
|
59
|
+
expect(@dec.send(:true_key?, "41526a")).to be false
|
60
|
+
expect(@dec.send(:true_key?, "4152")).to be false
|
61
|
+
expect(@dec.send(:true_key?, "415216")).to be false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#true_date?" do
|
66
|
+
it "should be a private method" do
|
67
|
+
expect{ @dec.true_date?(2) }.to raise_error(NoMethodError)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should take one compulsory argument" do
|
71
|
+
expect{ @dec.send(:true_date?) }.to raise_error(ArgumentError)
|
72
|
+
expect{ @dec.send(:true_date?, 123456, 90919) }.to raise_error(ArgumentError)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should return true for valid dates" do
|
76
|
+
expect(@dec.send(:true_date?, 11015)).to be true
|
77
|
+
expect(@dec.send(:true_date?, 81015)).to be true
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should return false for invalid dates" do
|
81
|
+
expect(@dec.send(:true_date?, 110152)).to be false
|
82
|
+
expect(@dec.send(:true_date?, "hello")).to be false
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#Decrypt_file" do
|
87
|
+
it "should be a private method" do
|
88
|
+
expect{ @dec.Decrypt_file }.to raise_error (NoMethodError)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should take four arguments" do
|
92
|
+
expect { @dec.send(:decrypt_file) }.to raise_error(ArgumentError)
|
93
|
+
expect { @dec.send(:decrypt_file, "message.txt") }.to raise_error(ArgumentError)
|
94
|
+
expect { @dec.send(:decrypt_file, "message.txt", "enc.txt") }.to raise_error(ArgumentError)
|
95
|
+
expect { @dec.send(:decrypt_file, "message.txt", "enc.txt", 24515) }.to raise_error(ArgumentError)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should display a success message if file was successfully created" do
|
99
|
+
|
100
|
+
io = double("io", puts: nil)
|
101
|
+
message = Gemnigma::Messages.new(io)
|
102
|
+
message.success_message("file.txt", "94704", "81015")
|
103
|
+
|
104
|
+
expect(io).to have_received(:puts).with("\n........................................................")
|
105
|
+
expect(io).to have_received(:puts).with("\nCreated 'file.txt' with secret key 94704 and date 81015")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe Gemnigma::Encrypt do
|
4
|
+
before :each do
|
5
|
+
@enc = Gemnigma::Encrypt.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be a subclass of RotatorEncrypt" do
|
9
|
+
expect(Gemnigma::Encrypt.superclass).to eql(Gemnigma::RotatorEncrypt)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be an instance of the class Encrypt" do
|
13
|
+
expect(@enc).to be_an_instance_of Gemnigma::Encrypt
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#get_cmd_args" do
|
17
|
+
it "should take no arguments" do
|
18
|
+
expect{ @enc.get_cmd_args(123) }.to raise_error(ArgumentError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should display an error message if few arguments are passed as command line arguments" do
|
22
|
+
|
23
|
+
io = double("io", puts: nil)
|
24
|
+
message = Gemnigma::Messages.new(io)
|
25
|
+
message.few_args
|
26
|
+
|
27
|
+
expect(io).to have_received(:puts).with("Not enough arguments passed in. Run Gemnigma --help for instructions on usage\nExiting...")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should display an error message if too many arguments are passed as command line arguments" do
|
31
|
+
|
32
|
+
io = double("io", puts: nil)
|
33
|
+
message = Gemnigma::Messages.new(io)
|
34
|
+
message.too_much_args
|
35
|
+
|
36
|
+
expect(io).to have_received(:puts).with("Too many arguments passed in. Run Gemnigma --help for instructions on usage\nExiting...")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#encrypt_file" do
|
41
|
+
it "should be a private method" do
|
42
|
+
expect{ @enc.encrypt_file }.to raise_error (NoMethodError)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should take two arguments" do
|
46
|
+
expect { @enc.send(:encrypt_file) }.to raise_error(ArgumentError)
|
47
|
+
expect { @enc.send(:encrypt_file, "message.txt") }.to raise_error(ArgumentError)
|
48
|
+
expect { @enc.send(:encrypt_file, "message.txt", "file.txt", "io.txt") }.to raise_error(ArgumentError)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should display a success message if file was successfully created" do
|
52
|
+
|
53
|
+
io = double("io", puts: nil)
|
54
|
+
message = Gemnigma::Messages.new(io)
|
55
|
+
message.success_message("file.txt", "94704", "81015")
|
56
|
+
|
57
|
+
expect(io).to have_received(:puts).with("\n........................................................")
|
58
|
+
expect(io).to have_received(:puts).with("\nCreated 'file.txt' with secret key 94704 and date 81015")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/key_spec.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe Gemnigma::Key do
|
4
|
+
before :each do
|
5
|
+
@key = Gemnigma::Key.new(41521)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return Key as it's class name" do
|
9
|
+
expect(@key).to be_an_instance_of Gemnigma::Key
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#initialize" do
|
13
|
+
context "when called with parameter" do
|
14
|
+
it "should initialize a new instance with the specified key" do
|
15
|
+
key = Gemnigma::Key.new(12345)
|
16
|
+
expect(key.key).to eql(12345)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when called without parameter" do
|
21
|
+
it "should default to 41521 if no key is specified" do
|
22
|
+
key = Gemnigma::Key.new
|
23
|
+
expect(key.key).to eql(41521)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when called with wrong parameter value" do
|
28
|
+
it "should default to 41521 if key is invalid" do
|
29
|
+
key = Gemnigma::Key.new("12345")
|
30
|
+
expect(key.key).to eql(41521)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#key_map" do
|
36
|
+
it "should return an array when called" do
|
37
|
+
expect(@key.key_map.class).to eql(Array)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return an array with a length of 4" do
|
41
|
+
expect(@key.key_map.length).to eql(4)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return an array of consecutive numbers based on the key" do
|
45
|
+
expect(@key.key_map).to eql([41, 15, 52, 21])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe Gemnigma::Messages do
|
4
|
+
before :each do
|
5
|
+
@msg = Gemnigma::Messages.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be an instance of the Messages class" do
|
9
|
+
expect(@msg).to be_an_instance_of Gemnigma::Messages
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#initialize" do
|
13
|
+
it "should default to standard output as the default if no argument is supplied to new" do
|
14
|
+
is_stdout = (@msg.instance_variable_get(:@io) == STDOUT)
|
15
|
+
expect(is_stdout).to be true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should take whatever argument is passed into it as the output stream" do
|
19
|
+
msg = Gemnigma::Messages.new(StringIO.new)
|
20
|
+
expect(msg.instance_variable_get(:@io).class).to eql(StringIO)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#puts" do
|
25
|
+
it "should take one compulsory argument" do
|
26
|
+
expect{ @msg.puts }.to raise_error(ArgumentError)
|
27
|
+
expect{ @msg.puts("hello", "world") }.to raise_error(ArgumentError)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should print to the console whatever is passed into it" do
|
31
|
+
|
32
|
+
io = double("io", puts: nil)
|
33
|
+
msg = Gemnigma::Messages.new(io)
|
34
|
+
msg.puts "Hello World"
|
35
|
+
msg.puts("This is a ridiculously long message")
|
36
|
+
|
37
|
+
expect(io).to have_received(:puts).with("Hello World")
|
38
|
+
expect(io).to have_received(:puts).with("This is a ridiculously long message")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#few_args" do
|
43
|
+
it "should print to the console when few_args is called" do
|
44
|
+
|
45
|
+
io = double("io", puts: nil)
|
46
|
+
msg = Gemnigma::Messages.new(io)
|
47
|
+
msg.few_args
|
48
|
+
|
49
|
+
expect(io).to have_received(:puts).with("Not enough arguments passed in. Run Gemnigma --help for instructions on usage\nExiting...")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#too_much_args" do
|
54
|
+
it "should print to the console when too_much_args is called" do
|
55
|
+
|
56
|
+
io = double("io", puts: nil)
|
57
|
+
msg = Gemnigma::Messages.new(io)
|
58
|
+
msg.too_much_args
|
59
|
+
|
60
|
+
expect(io).to have_received(:puts).with("Too many arguments passed in. Run Gemnigma --help for instructions on usage\nExiting...")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#file_not_in_existence" do
|
65
|
+
it "should take one compulsory argument" do
|
66
|
+
expect{ @msg.file_not_in_existence }.to raise_error(ArgumentError)
|
67
|
+
expect{ @msg.file_not_in_existence("file", "new_file") }.to raise_error(ArgumentError)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should print to the console when file_not_in_existence is called" do
|
71
|
+
|
72
|
+
io = double("io", puts: nil)
|
73
|
+
msg = Gemnigma::Messages.new(io)
|
74
|
+
msg.file_not_in_existence("file.txt")
|
75
|
+
|
76
|
+
expect(io).to have_received(:puts).with("file.txt: File does not exist\nExiting...")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#file_in_existence" do
|
81
|
+
it "should take two compulsory argument" do
|
82
|
+
expect{ @msg.file_in_existence }.to raise_error(ArgumentError)
|
83
|
+
expect{ @msg.file_in_existence("file", "new_file", "another_file") }.to raise_error(ArgumentError)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should print to the console when file_in_existence is called" do
|
87
|
+
|
88
|
+
io = double("io", puts: nil)
|
89
|
+
msg = Gemnigma::Messages.new(io)
|
90
|
+
msg.file_in_existence("file.txt", "new_file.txt")
|
91
|
+
|
92
|
+
expect(io).to have_received(:puts).with("file.txt exists... Checking new_file.txt")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "#creating_new_file" do
|
97
|
+
it "should take one compulsory argument" do
|
98
|
+
expect{ @msg.creating_new_file }.to raise_error(ArgumentError)
|
99
|
+
expect{ @msg.creating_new_file("file", "new_file") }.to raise_error(ArgumentError)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should print to the console when creating_new_file is called" do
|
103
|
+
|
104
|
+
io = double("io", puts: nil)
|
105
|
+
msg = Gemnigma::Messages.new(io)
|
106
|
+
msg.creating_new_file("file.txt")
|
107
|
+
|
108
|
+
expect(io).to have_received(:puts).with("file.txt will be created, proceeding...")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#overwrite_warning" do
|
113
|
+
it "should take one compulsory argument" do
|
114
|
+
expect{ @msg.overwrite_warning }.to raise_error(ArgumentError)
|
115
|
+
expect{ @msg.overwrite_warning("file", "new_file") }.to raise_error(ArgumentError)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should print to the console when overwrite_warning is called" do
|
119
|
+
|
120
|
+
io = double("io", puts: nil)
|
121
|
+
msg = Gemnigma::Messages.new(io)
|
122
|
+
msg.overwrite_warning("file.txt")
|
123
|
+
|
124
|
+
expect(io).to have_received(:puts).with( "file.txt exists already, do you want to overwrite it? (Y) or (N): ")
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "#wrong_date" do
|
129
|
+
it "should take one compulsory argument" do
|
130
|
+
expect{ @msg.wrong_date }.to raise_error(ArgumentError)
|
131
|
+
expect{ @msg.wrong_date("12345", "09190002") }.to raise_error(ArgumentError)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should print to the console when wrong_date is called" do
|
135
|
+
|
136
|
+
io = double("io", puts: nil)
|
137
|
+
msg = Gemnigma::Messages.new(io)
|
138
|
+
msg.wrong_date("abcde")
|
139
|
+
|
140
|
+
expect(io).to have_received(:puts).with("abcde doesn't match the specified date format\nExiting...")
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "#success_message" do
|
145
|
+
it "should take three compulsory arguments" do
|
146
|
+
expect{ @msg.success_message }.to raise_error(ArgumentError)
|
147
|
+
expect{ @msg.success_message("file.txt", "new.txt") }.to raise_error(ArgumentError)
|
148
|
+
expect{ @msg.success_message("file.txt", "new.txt", "810", "105") }.to raise_error(ArgumentError)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should print to the console when success_message is called" do
|
152
|
+
|
153
|
+
io = double("io", puts: nil)
|
154
|
+
msg = Gemnigma::Messages.new(io)
|
155
|
+
msg.success_message("new.txt", "94704", "81015")
|
156
|
+
|
157
|
+
expect(io).to have_received(:puts).with("\n........................................................")
|
158
|
+
expect(io).to have_received(:puts).with("\nCreated 'new.txt' with secret key 94704 and date 81015")
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
data/spec/offset_spec.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe Gemnigma::Offset do
|
4
|
+
before :each do
|
5
|
+
@offset = Gemnigma::Offset.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return Offset as it's class name" do
|
9
|
+
expect(@offset).to be_an_instance_of Gemnigma::Offset
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#date" do
|
13
|
+
it "should return the current date" do
|
14
|
+
expect(@offset.date.asctime).to eql(Time.now.asctime)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#formatted_date" do
|
19
|
+
it "should be a private method" do
|
20
|
+
expect { @offset.formatted_date }.to raise_error(NoMethodError)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return a formatted date in the format ddmmyy" do
|
24
|
+
expect(@offset.send(:formatted_date).to_s).to match(/\d\d\d\d\d/)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#squared_date" do
|
29
|
+
it "should be a private method" do
|
30
|
+
expect { @offset.squared_date }.to raise_error(NoMethodError)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return the square of the formatted_date" do
|
34
|
+
square = @offset.send(:formatted_date) ** 2
|
35
|
+
expect(@offset.send(:squared_date)).to eql(square)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#offset" do
|
40
|
+
it "should return an array" do
|
41
|
+
expect(@offset.offset.class).to eql(Array)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return an array with a length of 4" do
|
45
|
+
expect(@offset.offset.length).to eql(4)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return an array of integers" do
|
49
|
+
expect(@offset.offset.all? {|offset| offset.class == Fixnum}).to be true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#full_date" do
|
54
|
+
it "should return an integer" do
|
55
|
+
expect(@offset.full_date.is_a? Integer).to be true
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should return an integer corresponding to date the offset is based upon" do
|
59
|
+
expect(@offset.full_date.to_s).to match(/\d\d\d\d\d/)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe Gemnigma::RotatorDecrypt do
|
4
|
+
before :each do
|
5
|
+
@rot_dec = Gemnigma::RotatorDecrypt.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be a subclass of RotatorEncrypt" do
|
9
|
+
expect(Gemnigma::RotatorDecrypt.superclass).to eql(Gemnigma::RotatorEncrypt)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#rot_decrypt" do
|
13
|
+
it "should take one parameter" do
|
14
|
+
expect{ @rot_dec.rot_decrypt }.to raise_error(ArgumentError)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return a new string" do
|
18
|
+
expect(@rot_dec.rot_decrypt("qv0.x")).not_to eql("qv0.x")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe Gemnigma::RotatorEncrypt do
|
4
|
+
before :each do
|
5
|
+
@rot_enc = Gemnigma::RotatorEncrypt.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#initialize" do
|
9
|
+
context "with one optionally defined parameter" do
|
10
|
+
it "should return an instance of RotatorEncrypt" do
|
11
|
+
rot = Gemnigma::RotatorEncrypt.new(Gemnigma::Key.new)
|
12
|
+
expect(rot).to be_an_instance_of Gemnigma::RotatorEncrypt
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should default to 41521 if an invalid key is used for initialization" do
|
16
|
+
rot = Gemnigma::RotatorEncrypt.new(21345)
|
17
|
+
expect(rot.key_map).to eql([41, 15, 52, 21])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "without parameters" do
|
22
|
+
it "should return an instance of RotatorEncrypt" do
|
23
|
+
expect(@rot_enc).to be_an_instance_of Gemnigma::RotatorEncrypt
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should default to 41521 as the key map" do
|
27
|
+
expect(@rot_enc.key_map).to eql([41, 15, 52, 21])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#char_rotation" do
|
33
|
+
it "should be a private method" do
|
34
|
+
expect{ @rot_enc.char_rotation }.to raise_error(NoMethodError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should exist as a method of the class RotatorEncrypt" do
|
38
|
+
expect(@rot_enc.private_methods.include? :char_rotation).to be true
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return an array" do
|
42
|
+
expect(@rot_enc.send(:char_rotation).class).to eql(Array)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return an array with a length of 4" do
|
46
|
+
expect(@rot_enc.send(:char_rotation).length).to eql(4)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return an array of numbers" do
|
50
|
+
expect(@rot_enc.send(:char_rotation).all? {|num| num.is_a? Integer}).to be true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#map_word_to_key" do
|
55
|
+
it "should be a private method" do
|
56
|
+
expect{ @rot_enc.map_word_to_key }.to raise_error(NoMethodError)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should take one parameter" do
|
60
|
+
expect{ @rot_enc.send(:map_word_to_key) }.to raise_error(ArgumentError)
|
61
|
+
expect{ @rot_enc.send(:map_word_to_key, "hello", "world") }.to raise_error(ArgumentError)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return an array" do
|
65
|
+
expect(@rot_enc.send(:map_word_to_key, "Hello").class).to eql(Array)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should return an array of arrays" do
|
69
|
+
expect(@rot_enc.send(:map_word_to_key, "Hello").all? {|item| item.is_a? Array}).to be true
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should return an array of arrays containing a string and a number" do
|
73
|
+
result = @rot_enc.send(:map_word_to_key, "Hello").map do |arr|
|
74
|
+
arr.all? {|item| item.class == String || item.class == Fixnum}
|
75
|
+
end
|
76
|
+
expect(result.all?).to be true
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should return an array length based on passed in word" do
|
80
|
+
expect(@rot_enc.send(:map_word_to_key, "H").length).to eql(1)
|
81
|
+
expect(@rot_enc.send(:map_word_to_key, "He").length).to eql(2)
|
82
|
+
expect(@rot_enc.send(:map_word_to_key, "Hel").length).to eql(3)
|
83
|
+
expect(@rot_enc.send(:map_word_to_key, "Hell").length).to eql(4)
|
84
|
+
expect(@rot_enc.send(:map_word_to_key, "Hello").length).to eql(5)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#rot_encrypt" do
|
89
|
+
it "should take one parameter" do
|
90
|
+
expect{ @rot_enc.rot_encrypt }.to raise_error(ArgumentError)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should return a new string" do
|
94
|
+
expect(@rot_enc.rot_encrypt("hello")).not_to eql("hello")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#get_offset" do
|
99
|
+
it "should be a private method" do
|
100
|
+
expect{ @rot_enc.get_offset }.to raise_error(NoMethodError)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should return an array" do
|
104
|
+
expect(@rot_enc.send(:get_offset)).to be_an(Array)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should return an array of integers" do
|
108
|
+
expect(@rot_enc.send(:get_offset).all? {|item| item.class == Fixnum }).to be true
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#map_key_to_offset" do
|
113
|
+
it "should be a private method" do
|
114
|
+
expect{ @rot_enc.map_key_to_offset }.to raise_error(NoMethodError)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should return an array" do
|
118
|
+
expect(@rot_enc.send(:map_key_to_offset)).to be_an(Array)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should return an array with four items" do
|
122
|
+
expect(@rot_enc.send(:map_key_to_offset).length).to eql(4)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should return a nested array" do
|
126
|
+
expect(@rot_enc.send(:map_key_to_offset).all? {|item| item.class == Array }).to be true
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "coveralls"
|
2
|
+
Coveralls.wear!
|
3
|
+
|
4
|
+
require_relative "../helpers/char_map"
|
5
|
+
require_relative "../helpers/cipher_encrypt"
|
6
|
+
require_relative "../helpers/cipher_decrypt"
|
7
|
+
require_relative "../helpers/key"
|
8
|
+
require_relative "../helpers/offset"
|
9
|
+
require_relative "../helpers/rotator_encrypt"
|
10
|
+
require_relative "../helpers/rotator_decrypt"
|
11
|
+
require_relative "../helpers/validate_file_arg"
|
12
|
+
require_relative "../helpers/messages"
|
13
|
+
require_relative "../lib/Gemnigma/encrypt"
|
14
|
+
require_relative "../lib/Gemnigma/decrypt"
|
15
|
+
require_relative "../lib/Gemnigma/crack"
|
16
|
+
require_relative "../lib/Gemnigma/version"
|
17
|
+
require_relative "../lib/Gemnigma.rb"
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe Gemnigma::ValidateFileArg do
|
4
|
+
it "should be a module" do
|
5
|
+
expect(Gemnigma::ValidateFileArg.class).to eql(Module)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should have a method validate" do
|
9
|
+
expect(Gemnigma::ValidateFileArg.instance_methods.include? :validate).to be true
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#validate" do
|
13
|
+
it "should display an error message if input file does not exist" do
|
14
|
+
|
15
|
+
io = double("io", puts: nil)
|
16
|
+
message = Gemnigma::Messages.new(io)
|
17
|
+
message.file_not_in_existence("non-existent.txt")
|
18
|
+
|
19
|
+
expect(io).to have_received(:puts).with("non-existent.txt: File does not exist\nExiting...")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should display a success message if file exists" do
|
23
|
+
|
24
|
+
io = double("io", puts: nil)
|
25
|
+
message = Gemnigma::Messages.new(io)
|
26
|
+
message.file_in_existence("message.txt", "new_file.txt")
|
27
|
+
|
28
|
+
expect(io).to have_received(:puts).with("message.txt exists... Checking new_file.txt")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should display a informing a user that a file is about to be created" do
|
32
|
+
|
33
|
+
io = double("io", puts: nil)
|
34
|
+
message = Gemnigma::Messages.new(io)
|
35
|
+
message.creating_new_file("new_file.txt")
|
36
|
+
|
37
|
+
expect(io).to have_received(:puts).with("new_file.txt will be created, proceeding...")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should display a message alerting a user that a file is already in existence" do
|
41
|
+
|
42
|
+
io = double("io", puts: nil)
|
43
|
+
message = Gemnigma::Messages.new(io)
|
44
|
+
message.overwrite_warning("new_file.txt")
|
45
|
+
|
46
|
+
expect(io).to have_received(:puts).with("new_file.txt exists already, do you want to overwrite it? (Y) or (N): ")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe "version.rb" do
|
4
|
+
it "should be a constant" do
|
5
|
+
expect(Gemnigma.constants.include? :VERSION).to be true
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return a string as it's value" do
|
9
|
+
expect(Gemnigma::VERSION.class).to eql(String)
|
10
|
+
end
|
11
|
+
end
|