mystiko 0.0.1 → 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 +4 -4
- data/README.md +132 -18
- data/bin/mystiko +109 -0
- data/irbt.rb +20 -0
- data/lib/mystiko.rb +18 -3
- data/lib/mystiko/decrypt.rb +53 -0
- data/lib/mystiko/encrypt.rb +49 -0
- data/lib/mystiko/generator.rb +23 -0
- data/lib/mystiko/inputs.rb +32 -0
- data/lib/mystiko/outputs.rb +26 -0
- data/lib/mystiko/version.rb +2 -2
- data/mystiko.gemspec +7 -8
- data/mystiko.reek +112 -0
- data/rakefile.rb +5 -0
- metadata +44 -8
- data/crypto_101/part_01/README.md +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3653317c8191c6dffe9aa4679789f55914e508e0
|
4
|
+
data.tar.gz: 08d04a4d984b8b84c29a5afeff1b94b6be02bf95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a55ec569cc4f002731391e8d27a6cd03994f7bee926f3415902a07446cd3e67471eabcbfedbaccbd7f8077634e133916b450cd54005a44f60f2876156075dc4
|
7
|
+
data.tar.gz: b3fd17e8cec9de5c080808356e51d118b4051c33db7472a48924f8b130a1c2fedd64f657b84997e279d0b0986bb53d837f0b0757366e0a8bece5734d6e4c6152
|
data/README.md
CHANGED
@@ -3,20 +3,10 @@
|
|
3
3
|
The word mystikó is from the Greek language and means secret. Keeping
|
4
4
|
secrets safe from unauthorized eyes is the very core purpose of encryption.
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
This gem is only intended for educational purposes and should not be used in
|
7
|
+
serious data security applications.
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
- A look at the basic machinery common to all encryption systems.
|
12
|
-
- A look at some famous (and infamous) encryption systems used through history.
|
13
|
-
In addition to seeing how they work, we'll also take a look at how they
|
14
|
-
failed and/or went obsolete.
|
15
|
-
- The mystiko gem, written in ruby, that serves as a simple demonstration of
|
16
|
-
the principles of data encryption.
|
17
|
-
- A challenge. For as long as secret codes have existed, secret code breakers
|
18
|
-
have tried to defeat them. Coming soon, see if you can decode a secret
|
19
|
-
message created by the above ruby code. Prizes, if any, to be determined!
|
9
|
+
Any use for unlawful purposes is strictly forbidden.
|
20
10
|
|
21
11
|
## Installation
|
22
12
|
|
@@ -34,17 +24,141 @@ Or install it yourself as:
|
|
34
24
|
|
35
25
|
$ gem install mystiko
|
36
26
|
|
37
|
-
The mystiko gem itself
|
27
|
+
The mystiko gem itself is found at: ( https://rubygems.org/gems/mystiko )
|
38
28
|
|
39
29
|
## Usage
|
40
30
|
|
41
|
-
|
31
|
+
Mystikó is both a ruby gem and a command line utility. In order to work
|
32
|
+
with the encryption engine two things must be done:
|
33
|
+
|
34
|
+
- An instance must be created. This is easily done with the new method.
|
35
|
+
- Encryption is done with the encrypt method and appropriate parameters.
|
36
|
+
- Decryption is done with the decrypt method and appropriate parameters.
|
37
|
+
|
38
|
+
The parameters take the form of classical named/hashed parameters. Supported
|
39
|
+
parameters include:
|
40
|
+
|
41
|
+
- in_str: "value" -- a string of input data.
|
42
|
+
- in_file: "name" -- the name of a file of input data. Overrides in_str.
|
43
|
+
- key: "value" -- the key to use for processing
|
44
|
+
- generator: object -- a seeded, pseudo-random number generator. Overrides key.
|
45
|
+
- out_str: "value" -- the string output is appended to this string.
|
46
|
+
- out_file: "name" -- the name of a file of output data. Overrides out_str.
|
47
|
+
- window: value -- the size, in bytes, of the shuffling window.
|
48
|
+
|
49
|
+
The methods encrypt and decrypt both also return the resultant string of data.
|
50
|
+
|
51
|
+
The command line utility displays the following message if started with no
|
52
|
+
arguments or the "--help", "-h", or "-?" options.
|
53
|
+
|
54
|
+
Mystiko version 0.1.0
|
55
|
+
|
56
|
+
Usage summary:
|
57
|
+
|
58
|
+
$ mystiko <options>
|
59
|
+
|
60
|
+
--help, -h, -? # Display this help message.
|
61
|
+
--encrypt, -e # Data is to be encrypted.
|
62
|
+
--decrypt, -d # Data is to be decrypted.
|
63
|
+
--input, -i <input data> # Specify the input data string.
|
64
|
+
--read, -r <file name> # Specify the input data file name.
|
65
|
+
--write, -w <file name> # Specify the input data file name.
|
66
|
+
--key, -k <key data> # Specify the key data string.
|
67
|
+
|
68
|
+
Notes:
|
69
|
+
- A command option and a key are always required.
|
70
|
+
- Data input defaults to STDIN.
|
71
|
+
- Data output defaults to STDOUT.
|
72
|
+
- If -r is specified, -i is ignored.
|
73
|
+
- String data may be optionally enclosed in " ... "
|
74
|
+
|
75
|
+
## Princples of Operation
|
76
|
+
|
77
|
+
#### The Vernam Cypher
|
78
|
+
|
79
|
+
The mystikó gem is a modified Vernam cypher. The classic approach to
|
80
|
+
this type of cypher is to have a random string of data of the same length as
|
81
|
+
the plain text data. The two streams of data are combined using the XOR
|
82
|
+
operation. To recover the original data, the cypher data is again combined with
|
83
|
+
the random data with the XOR operation. After one use, the random data is
|
84
|
+
never reused.
|
85
|
+
|
86
|
+
This works because the XOR operator exhibits the following identity:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
(A ^ B ^ B) == A
|
90
|
+
```
|
91
|
+
This is the result of the fact that:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
(X ^ X) == 0
|
95
|
+
```
|
96
|
+
and
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
(X ^ 0) == X
|
100
|
+
```
|
101
|
+
|
102
|
+
Excepting "end run" code cracking (getting the data before/after encryption or
|
103
|
+
getting a copy of the random data) or incompetence (poor quality or reusing the
|
104
|
+
random data) this code can be shown to be unbreakable.
|
105
|
+
|
106
|
+
It is also very cumbersome to use. It requires that both parties have access to
|
107
|
+
large amounts of high quality random data that can only be used once. It
|
108
|
+
requires that random data to be kept secret and that these random data remain
|
109
|
+
synchronized.
|
110
|
+
|
111
|
+
#### The Pseudo-Random Shortcut
|
112
|
+
|
113
|
+
Given that large quantities of random data are bothersome to deal with, it was
|
114
|
+
only natural that someone would start taking short-cuts. In this case, the
|
115
|
+
one-time use random data was replaced by a pseudo-random data generator (PRNG).
|
116
|
+
This transforms the Vernam cypher from unbreakable to laughably weak. Why?
|
117
|
+
|
118
|
+
- Any PRNG used in this way, requires an initial seed value. This seed value
|
119
|
+
is effectively the key of the cypher. To crack the code, the attacker only
|
120
|
+
needs to compute the seed value.
|
121
|
+
- Many messages start with a known sequence of bytes. A header if you will.
|
122
|
+
These known bytes make it possible know what values were generated during the
|
123
|
+
encryption process. This in turn allows the internal state of the PRNG to be
|
124
|
+
modeled, greatly reducing the number of seed values that must be tested.
|
125
|
+
- Once a sequence of random values is known, it is often easy to determine
|
126
|
+
what values will follow. At this point, the code is broken.
|
127
|
+
|
128
|
+
The problem with the Vernam cypher is that it only maps input symbols to
|
129
|
+
output symbols. The order of the symbols is not changed. With one-use truly
|
130
|
+
random data, this is not a problem. Knowledge of a few random values tells
|
131
|
+
us nothing about the values to follow. With a PRNG, they tell us a very great
|
132
|
+
deal.
|
133
|
+
|
134
|
+
#### The Scrambled Vernam Cypher
|
135
|
+
|
136
|
+
To avoid the problems of the classical Vernam cypher, mystikó makes one
|
137
|
+
significant change: The PRNG not only maps input symbols to output symbols, it
|
138
|
+
also performs a controlled shuffle on those symbols.
|
139
|
+
|
140
|
+
To recover data, in addition to anti-mapping the symbols, we need to perform a
|
141
|
+
controlled anti-shuffle of the data.
|
142
|
+
|
143
|
+
This data shuffling denies any would-be attacker knowledge of the order of the
|
144
|
+
input data. Thus even with standard message headers, the content of the
|
145
|
+
original message is no longer relevant.
|
146
|
+
|
147
|
+
#### References
|
148
|
+
|
149
|
+
- One time pads and the Vernam cypher https://en.wikipedia.org/wiki/One-time_pad
|
150
|
+
- Random number generation https://en.wikipedia.org/wiki/Random_number_generation
|
151
|
+
- The Mersenne twister https://en.wikipedia.org/wiki/Mersenne_Twister
|
152
|
+
- The Random library http://ruby-doc.org/core-2.2.0/Random.html
|
153
|
+
- Testing random number generators https://en.wikipedia.org/wiki/TestU01 and
|
154
|
+
http://www.iro.umontreal.ca/~simardr/testu01/tu01.html
|
155
|
+
- Random key generator http://randomkeygen.com/ The 256 bit WEP keys work especially well.
|
42
156
|
|
43
157
|
## Contributing
|
44
158
|
|
45
|
-
Creating
|
46
|
-
|
47
|
-
|
159
|
+
Creating any encryption system is quite an undertaking. For this reason,
|
160
|
+
any input is most welcomed. There are two basic plans by which this can
|
161
|
+
be accomplished.
|
48
162
|
|
49
163
|
#### Plan A
|
50
164
|
|
data/bin/mystiko
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Standalone execution of the Mystiko gem.
|
4
|
+
#
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'mystiko'
|
8
|
+
rescue LoadError
|
9
|
+
require_relative '..\lib\mystiko'
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'getoptlong'
|
13
|
+
|
14
|
+
#Display help and exit.
|
15
|
+
def help(message=nil)
|
16
|
+
puts "Mystiko version #{Mystiko::VERSION}"
|
17
|
+
puts
|
18
|
+
|
19
|
+
if message
|
20
|
+
puts message
|
21
|
+
puts
|
22
|
+
end
|
23
|
+
|
24
|
+
puts "Usage summary:"
|
25
|
+
puts
|
26
|
+
puts "$ mystiko <options>"
|
27
|
+
puts
|
28
|
+
puts "--help, -h, -? # Display this help message."
|
29
|
+
puts "--encrypt, -e # Data is to be encrypted."
|
30
|
+
puts "--decrypt, -d # Data is to be decrypted."
|
31
|
+
puts "--input, -i <input data> # Specify the input data string."
|
32
|
+
puts "--read, -r <file name> # Specify the input data file name."
|
33
|
+
puts "--write, -w <file name> # Specify the input data file name."
|
34
|
+
puts "--key, -k <key data> # Specify the key data string."
|
35
|
+
puts
|
36
|
+
puts "Notes:"
|
37
|
+
puts " - A command option and a key are always required."
|
38
|
+
puts " - Data input defaults to STDIN."
|
39
|
+
puts " - Data output defaults to STDOUT."
|
40
|
+
puts " - If -r is specified, -i is ignored."
|
41
|
+
puts " - String data may be optionally enclosed in \" ... \" "
|
42
|
+
exit
|
43
|
+
end
|
44
|
+
|
45
|
+
#Read data from stdin.
|
46
|
+
def grab_stdin
|
47
|
+
result = ""
|
48
|
+
|
49
|
+
while (line = gets)
|
50
|
+
result << line
|
51
|
+
end
|
52
|
+
|
53
|
+
result
|
54
|
+
end
|
55
|
+
|
56
|
+
opts = GetoptLong.new(
|
57
|
+
[ "--help", "-h", "-?", GetoptLong::NO_ARGUMENT ],
|
58
|
+
[ "--encrypt", "-e", GetoptLong::NO_ARGUMENT ],
|
59
|
+
[ "--decrypt", "-d", GetoptLong::NO_ARGUMENT ],
|
60
|
+
[ "--input", "-i", GetoptLong::REQUIRED_ARGUMENT ],
|
61
|
+
[ "--read", "-r", GetoptLong::REQUIRED_ARGUMENT ],
|
62
|
+
[ "--write", "-w", GetoptLong::REQUIRED_ARGUMENT ],
|
63
|
+
[ "--key", "-k", GetoptLong::REQUIRED_ARGUMENT ],
|
64
|
+
[ "--test", "-t", GetoptLong::NO_ARGUMENT ])
|
65
|
+
|
66
|
+
options_found = false
|
67
|
+
parameters = {}
|
68
|
+
command = nil
|
69
|
+
use_stdin = use_stdout = true
|
70
|
+
|
71
|
+
begin
|
72
|
+
opts.each do |opt, arg|
|
73
|
+
case opt
|
74
|
+
when "--help"
|
75
|
+
help
|
76
|
+
when "--encrypt"
|
77
|
+
fail "Only one encrypt or decrypt may be specified." if command
|
78
|
+
command = :encrypt
|
79
|
+
when "--decrypt"
|
80
|
+
fail "Only one encrypt or decrypt may be specified." if command
|
81
|
+
command = :decrypt
|
82
|
+
when "--input"
|
83
|
+
parameters[:in_str] = arg
|
84
|
+
use_stdin = false
|
85
|
+
when "--read"
|
86
|
+
parameters[:in_file] = arg
|
87
|
+
use_stdin = false
|
88
|
+
when "--write"
|
89
|
+
parameters[:out_file] = arg
|
90
|
+
use_stdout = false
|
91
|
+
when "--key"
|
92
|
+
parameters[:key] = arg
|
93
|
+
when "--test"
|
94
|
+
parameters[:filler] = 32
|
95
|
+
end
|
96
|
+
|
97
|
+
options_found = true
|
98
|
+
end
|
99
|
+
|
100
|
+
help unless options_found
|
101
|
+
fail "A key must be specified" unless parameters[:key]
|
102
|
+
fail "Either encrypt or decrypt must be specified." unless command
|
103
|
+
parameters[:in_str] = grab_stdin if use_stdin
|
104
|
+
result = Mystiko.new.send(command, parameters)
|
105
|
+
print result if use_stdout
|
106
|
+
|
107
|
+
rescue => err
|
108
|
+
help "Error: #{err.message}"
|
109
|
+
end
|
data/irbt.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# An IRB + mystiko test bed
|
3
|
+
|
4
|
+
require 'irb'
|
5
|
+
$force_alias_read_line_module = true
|
6
|
+
require 'mini_readline'
|
7
|
+
|
8
|
+
puts "Starting an IRB console with mystiko loaded."
|
9
|
+
|
10
|
+
if ARGV[0] == 'local'
|
11
|
+
require_relative 'lib/mystiko'
|
12
|
+
puts "mystiko loaded locally: #{Mystiko::VERSION}"
|
13
|
+
|
14
|
+
ARGV.shift
|
15
|
+
else
|
16
|
+
require 'mystiko'
|
17
|
+
puts "mystiko loaded from gem: #{Mystiko::VERSION}"
|
18
|
+
end
|
19
|
+
|
20
|
+
IRB.start
|
data/lib/mystiko.rb
CHANGED
@@ -1,8 +1,23 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
+
require_relative "mystiko/encrypt"
|
4
|
+
require_relative "mystiko/decrypt"
|
5
|
+
require_relative "mystiko/generator"
|
6
|
+
require_relative "mystiko/inputs"
|
7
|
+
require_relative "mystiko/outputs"
|
3
8
|
require_relative "mystiko/version"
|
4
9
|
|
5
|
-
# The Mystiko
|
6
|
-
|
7
|
-
|
10
|
+
# The Mystiko class is where all the data encryption code resides.
|
11
|
+
class Mystiko
|
12
|
+
|
13
|
+
#Set up an encryption object.
|
14
|
+
def initialize
|
15
|
+
@filler = Random.new
|
16
|
+
end
|
17
|
+
|
18
|
+
#Get a decoy filler byte.
|
19
|
+
def filler_byte
|
20
|
+
@fill_value || @filler.rand(256)
|
21
|
+
end
|
22
|
+
|
8
23
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'English'
|
4
|
+
|
5
|
+
#* decrypt.rb -- Data decryption.
|
6
|
+
class Mystiko
|
7
|
+
|
8
|
+
#Perform data decryption
|
9
|
+
def decrypt(args={})
|
10
|
+
process_inputs(args)
|
11
|
+
setup_cypher_input
|
12
|
+
do_decryption
|
13
|
+
setup_clear_output
|
14
|
+
process_outputs(args)
|
15
|
+
end
|
16
|
+
|
17
|
+
#Get the cypher (aka encrypted) input data set up.
|
18
|
+
def setup_cypher_input
|
19
|
+
@input = @input.bytes
|
20
|
+
@offsets = (0...@window).to_a
|
21
|
+
@offset = @window
|
22
|
+
end
|
23
|
+
|
24
|
+
#Do the actual decryption work.
|
25
|
+
#<br>Endemic Code Smells
|
26
|
+
#* :reek:TooManyStatements
|
27
|
+
def do_decryption
|
28
|
+
result = Array.new(@input.length + @window, 32)
|
29
|
+
|
30
|
+
@input.each do | value |
|
31
|
+
index = @generator.rand(@window)
|
32
|
+
result[@offsets[index]] = value ^ @generator.rand(256)
|
33
|
+
|
34
|
+
@offsets.delete_at(index)
|
35
|
+
@offsets << @offset
|
36
|
+
@offset += 1
|
37
|
+
end
|
38
|
+
|
39
|
+
@output = result.pack("C*")
|
40
|
+
end
|
41
|
+
|
42
|
+
#Get the clear (aka unencrypted) output data set up.
|
43
|
+
def setup_clear_output
|
44
|
+
@offsets = @offset = nil
|
45
|
+
|
46
|
+
if /^[0-9a-z]+;/ =~ @output
|
47
|
+
@output = $POSTMATCH[0...($MATCH.to_i(36))]
|
48
|
+
else
|
49
|
+
fail "Unable to recover data."
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#* encrypt.rb -- Data encryption.
|
4
|
+
class Mystiko
|
5
|
+
|
6
|
+
#Perform data encryption
|
7
|
+
def encrypt(args={})
|
8
|
+
process_inputs(args)
|
9
|
+
setup_clear_input
|
10
|
+
do_encryption
|
11
|
+
setup_cypher_output
|
12
|
+
process_outputs(args)
|
13
|
+
end
|
14
|
+
|
15
|
+
#Get the clear (aka unencrypted) input data set up.
|
16
|
+
def setup_clear_input
|
17
|
+
temp = @input.bytes
|
18
|
+
@input = "#{temp.length.to_s(36)};".bytes + temp
|
19
|
+
@length = @input.length
|
20
|
+
@data = @input[0...@window]
|
21
|
+
|
22
|
+
(@window - (@offset = @data.length)).times do
|
23
|
+
@data << filler_byte
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
#Do the actual encryption work.
|
28
|
+
def do_encryption
|
29
|
+
result, processed = [], 0
|
30
|
+
|
31
|
+
while processed < @length
|
32
|
+
index = @generator.rand(@window)
|
33
|
+
result << (@data.delete_at(index) ^ @generator.rand(256))
|
34
|
+
|
35
|
+
@data << (@input[@offset] || filler_byte)
|
36
|
+
@offset += 1
|
37
|
+
|
38
|
+
processed += 1 if (index + processed) < @length
|
39
|
+
end
|
40
|
+
|
41
|
+
@output = result.pack("C*")
|
42
|
+
end
|
43
|
+
|
44
|
+
#Get the cypher (aka encrypted) output data set up.
|
45
|
+
def setup_cypher_output
|
46
|
+
@data = @offset = nil # Just cleanup.
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'fibonacci_rng'
|
4
|
+
require 'composite_rng'
|
5
|
+
|
6
|
+
#* generator.rb -- The internal pseudo-random number generator.
|
7
|
+
class Mystiko
|
8
|
+
|
9
|
+
#A specialized variant of the composite pseudo RNG.
|
10
|
+
class Generator < CompositeRng
|
11
|
+
|
12
|
+
#Create the default pseudo random data generator.
|
13
|
+
#<br> Endemic Code Smells
|
14
|
+
#* :reek:FeatureEnvy
|
15
|
+
def initialize(key)
|
16
|
+
parent = FibonacciRng.new(key)
|
17
|
+
child = Random.new(parent.hash_value)
|
18
|
+
super(parent, child, 31, 31)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#* inputs.rb -- Common input parameter processing.
|
4
|
+
class Mystiko
|
5
|
+
|
6
|
+
# The array of input bytes
|
7
|
+
attr_reader :input
|
8
|
+
|
9
|
+
# The sliding window size.
|
10
|
+
attr_reader :window
|
11
|
+
|
12
|
+
# The source of simulated entropy
|
13
|
+
attr_reader :generator
|
14
|
+
|
15
|
+
#Perform common input argument processing.
|
16
|
+
def process_inputs(args)
|
17
|
+
@input = ((name = args[:in_file]) && (IO.read(name, mode: "rb"))) ||
|
18
|
+
args[:in_str] ||
|
19
|
+
fail("An input must be specified.")
|
20
|
+
|
21
|
+
@generator = args[:generator] ||
|
22
|
+
((key = args[:key]) && Generator.new(key)) ||
|
23
|
+
fail("A key or generator must be specified.")
|
24
|
+
|
25
|
+
@window = args[:window] || 16
|
26
|
+
|
27
|
+
#The filler value is for testing purposes only. It should
|
28
|
+
#not be specified when secure operation is desired.
|
29
|
+
@fill_value = args[:filler]
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#* outputs.rb -- Common output parameter processing.
|
4
|
+
class Mystiko
|
5
|
+
|
6
|
+
#Access to the output instance variable
|
7
|
+
#<br>Endemic Code Smells
|
8
|
+
# :reek:Attribute -- Access needed for testing only.
|
9
|
+
attr_accessor :output
|
10
|
+
|
11
|
+
#Perform common output argument processing.
|
12
|
+
#<br>Returns
|
13
|
+
#* The output string.
|
14
|
+
def process_outputs(args)
|
15
|
+
@input = @generator = @window = @fill_value = nil # Cover our tracks.
|
16
|
+
|
17
|
+
if (name = args[:out_file])
|
18
|
+
IO.write(name, @output, mode: "wb")
|
19
|
+
elsif (out_str = args[:out_str])
|
20
|
+
out_str << @output
|
21
|
+
end
|
22
|
+
|
23
|
+
(_, @output = @output, nil)[0] # Return output and erase it.
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/lib/mystiko/version.rb
CHANGED
data/mystiko.gemspec
CHANGED
@@ -9,22 +9,21 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Peter Camilleri"]
|
10
10
|
spec.email = ["peter.c.camilleri@gmail.com"]
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
spec.summary = "A temp place holder."
|
16
|
-
spec.description = "A temp place holder. Work in progress."
|
12
|
+
spec.summary = "A simple data security system."
|
13
|
+
spec.description = "An example of a simple data security system."
|
17
14
|
|
18
15
|
spec.homepage = "http://teuthida-technologies.com/"
|
19
16
|
spec.license = "MIT"
|
20
17
|
|
21
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(tests)/}) }
|
22
|
-
spec.
|
23
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.executables = ["mystiko"]
|
24
20
|
spec.require_paths = ["lib"]
|
25
21
|
|
26
22
|
spec.platform = Gem::Platform::RUBY
|
27
|
-
spec.required_ruby_version = '>=1.
|
23
|
+
spec.required_ruby_version = '>=2.1.0'
|
24
|
+
|
25
|
+
spec.add_runtime_dependency 'fibonacci_rng', ">= 1.1.1"
|
26
|
+
spec.add_runtime_dependency 'composite_rng', ">= 0.1.0"
|
28
27
|
|
29
28
|
spec.add_development_dependency "bundler", "~> 1.11"
|
30
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/mystiko.reek
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
---
|
2
|
+
Attribute:
|
3
|
+
enabled: true
|
4
|
+
exclude: []
|
5
|
+
BooleanParameter:
|
6
|
+
enabled: true
|
7
|
+
exclude: []
|
8
|
+
ClassVariable:
|
9
|
+
enabled: true
|
10
|
+
exclude: []
|
11
|
+
ControlParameter:
|
12
|
+
enabled: true
|
13
|
+
exclude: []
|
14
|
+
DataClump:
|
15
|
+
enabled: true
|
16
|
+
exclude: []
|
17
|
+
max_copies: 2
|
18
|
+
min_clump_size: 2
|
19
|
+
DuplicateMethodCall:
|
20
|
+
enabled: true
|
21
|
+
exclude: []
|
22
|
+
max_calls: 1
|
23
|
+
allow_calls: []
|
24
|
+
FeatureEnvy:
|
25
|
+
enabled: true
|
26
|
+
exclude: []
|
27
|
+
IrresponsibleModule:
|
28
|
+
enabled: true
|
29
|
+
exclude: []
|
30
|
+
LongParameterList:
|
31
|
+
enabled: true
|
32
|
+
exclude: []
|
33
|
+
max_params: 3
|
34
|
+
overrides:
|
35
|
+
initialize:
|
36
|
+
max_params: 5
|
37
|
+
LongYieldList:
|
38
|
+
enabled: true
|
39
|
+
exclude: []
|
40
|
+
max_params: 3
|
41
|
+
NestedIterators:
|
42
|
+
enabled: true
|
43
|
+
exclude: []
|
44
|
+
max_allowed_nesting: 1
|
45
|
+
ignore_iterators: []
|
46
|
+
NilCheck:
|
47
|
+
enabled: true
|
48
|
+
exclude: []
|
49
|
+
PrimaDonnaMethod:
|
50
|
+
enabled: true
|
51
|
+
exclude: []
|
52
|
+
RepeatedConditional:
|
53
|
+
enabled: true
|
54
|
+
exclude: []
|
55
|
+
max_ifs: 2
|
56
|
+
TooManyInstanceVariables:
|
57
|
+
enabled: true
|
58
|
+
exclude: []
|
59
|
+
max_instance_variables: 9
|
60
|
+
TooManyMethods:
|
61
|
+
enabled: true
|
62
|
+
exclude: []
|
63
|
+
max_methods: 25
|
64
|
+
TooManyStatements:
|
65
|
+
enabled: true
|
66
|
+
exclude:
|
67
|
+
- initialize
|
68
|
+
max_statements: 7
|
69
|
+
UncommunicativeMethodName:
|
70
|
+
enabled: true
|
71
|
+
exclude: []
|
72
|
+
reject:
|
73
|
+
- !ruby/regexp /^[a-z]$/
|
74
|
+
- !ruby/regexp /[0-9]$/
|
75
|
+
- !ruby/regexp /[A-Z]/
|
76
|
+
accept: []
|
77
|
+
UncommunicativeModuleName:
|
78
|
+
enabled: true
|
79
|
+
exclude: []
|
80
|
+
reject:
|
81
|
+
- !ruby/regexp /^.$/
|
82
|
+
- !ruby/regexp /[0-9]$/
|
83
|
+
accept:
|
84
|
+
- Inline::C
|
85
|
+
UncommunicativeParameterName:
|
86
|
+
enabled: true
|
87
|
+
exclude: []
|
88
|
+
reject:
|
89
|
+
- !ruby/regexp /^.$/
|
90
|
+
- !ruby/regexp /[0-9]$/
|
91
|
+
- !ruby/regexp /[A-Z]/
|
92
|
+
- !ruby/regexp /^_/
|
93
|
+
accept: []
|
94
|
+
UncommunicativeVariableName:
|
95
|
+
enabled: true
|
96
|
+
exclude: []
|
97
|
+
reject:
|
98
|
+
- !ruby/regexp /^.$/
|
99
|
+
- !ruby/regexp /[0-9]$/
|
100
|
+
- !ruby/regexp /[A-Z]/
|
101
|
+
accept:
|
102
|
+
- _
|
103
|
+
UnusedParameters:
|
104
|
+
enabled: true
|
105
|
+
exclude: []
|
106
|
+
UtilityFunction:
|
107
|
+
enabled: true
|
108
|
+
exclude: []
|
109
|
+
max_helper_calls: 1
|
110
|
+
UnusedPrivateMethod:
|
111
|
+
enabled: false
|
112
|
+
exclude: []
|
data/rakefile.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mystiko
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Camilleri
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fibonacci_rng
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: composite_rng
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.0
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,10 +94,11 @@ dependencies:
|
|
66
94
|
- - ">="
|
67
95
|
- !ruby/object:Gem::Version
|
68
96
|
version: 0.4.8
|
69
|
-
description:
|
97
|
+
description: An example of a simple data security system.
|
70
98
|
email:
|
71
99
|
- peter.c.camilleri@gmail.com
|
72
|
-
executables:
|
100
|
+
executables:
|
101
|
+
- mystiko
|
73
102
|
extensions: []
|
74
103
|
extra_rdoc_files: []
|
75
104
|
files:
|
@@ -77,10 +106,17 @@ files:
|
|
77
106
|
- Gemfile
|
78
107
|
- LICENSE.txt
|
79
108
|
- README.md
|
80
|
-
-
|
109
|
+
- bin/mystiko
|
110
|
+
- irbt.rb
|
81
111
|
- lib/mystiko.rb
|
112
|
+
- lib/mystiko/decrypt.rb
|
113
|
+
- lib/mystiko/encrypt.rb
|
114
|
+
- lib/mystiko/generator.rb
|
115
|
+
- lib/mystiko/inputs.rb
|
116
|
+
- lib/mystiko/outputs.rb
|
82
117
|
- lib/mystiko/version.rb
|
83
118
|
- mystiko.gemspec
|
119
|
+
- mystiko.reek
|
84
120
|
- rakefile.rb
|
85
121
|
- reek.txt
|
86
122
|
homepage: http://teuthida-technologies.com/
|
@@ -95,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
131
|
requirements:
|
96
132
|
- - ">="
|
97
133
|
- !ruby/object:Gem::Version
|
98
|
-
version: 1.
|
134
|
+
version: 2.1.0
|
99
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
136
|
requirements:
|
101
137
|
- - ">="
|
@@ -106,6 +142,6 @@ rubyforge_project:
|
|
106
142
|
rubygems_version: 2.2.2
|
107
143
|
signing_key:
|
108
144
|
specification_version: 4
|
109
|
-
summary: A
|
145
|
+
summary: A simple data security system.
|
110
146
|
test_files: []
|
111
147
|
has_rdoc:
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# Welcome to Cyrpto 101
|
2
|
-
|
3
|
-
This series of lessons is a basic level primer on encryption. The target
|
4
|
-
audience is programmers curious about how encryption works but not in love
|
5
|
-
with pages of confusing mathematical scribblings. It is not really solid
|
6
|
-
enough to use as a basis for those wishing to delve deeply into the field
|
7
|
-
but may still serve as a starting point for such a path.
|
8
|
-
|
9
|
-
The examination of encryption will look at a number of sources.
|
10
|
-
|
11
|
-
- The theory behind how encryption works.
|
12
|
-
- An examination of actual encryption systems that are deployed in the field.
|
13
|
-
- A look at some examples of epic failures through the years.
|
14
|
-
- We will build up a simple example encryption system in the ruby language.
|
15
|
-
|
16
|
-
Keep in my that this primer will keep things on a basic level. As a result
|
17
|
-
we will avoid digging into the leading edge of security apparatus. The NSA
|
18
|
-
most certainly has nothing to fear here.
|
19
|
-
|
20
|
-
Finally, it is a goal to keep the tone light and informal. Furthermore, since
|
21
|
-
I am not particularly learned, this will _not_ be a learned dissertation.
|
22
|
-
|
23
|
-
## Encryption Basics
|
24
|
-
|
25
|
-
There are many occasions that require moving and/or storing information in a
|
26
|
-
secure manner. Some of these include:
|
27
|
-
|
28
|
-
- Protecting personal information for customers or citizens.
|
29
|
-
- Protecting financial information during business transactions.
|
30
|
-
- Protecting the secrecy during military operations.
|
31
|
-
- Protecting intellectual property from industrial espionage.
|
32
|
-
- Protecting the operation of banking systems or power grids.
|
33
|
-
- Protecting... well you get it. There's a lot that needs protecting.
|
34
|
-
|
35
|
-
So, just what does protecting mean in this context? In each case above, there
|
36
|
-
is information. That information is plainly visible to the originator of the
|
37
|
-
information. It needs to be made plainly visible to the intended recipient of
|
38
|
-
that information. It needs to be kept out of the hands who are not authorized
|
39
|
-
to possess or use that information.
|
40
|
-
|