number_station 0.0.3 → 0.0.4
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87052778b344b664ebdbb4e7d9634064c5c3afa4d3b8b20e9d1ab77895c0d493
|
4
|
+
data.tar.gz: 4fe01f004ed3dae32e9f245815e0c3db2833ea63f4d3a5dbd8253021b2482d2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f283b7f691d168924c99f8a388a82322dc5ea6600d1cdea14772563189bb91752243a249c716c09e7c394316c63e02061f1313822a4220f336d5cf2706ffebbc
|
7
|
+
data.tar.gz: ac8f1a34e6797f617389ab8f18e3f53ffd7c62f8498a63e434f4a8f07fa17b59fb26db402297248d4a7a5700189845238e9a24bb62e81dee4bd1224a26548c50
|
data/lib/number_station/cli.rb
CHANGED
@@ -121,13 +121,13 @@ module NumberStation
|
|
121
121
|
NumberStation.log.debug "make_one_time_pad"
|
122
122
|
|
123
123
|
length = options[:length]
|
124
|
-
|
124
|
+
numpads = options[:numpads]
|
125
125
|
path = options[:path]
|
126
126
|
NumberStation.log.debug "length: #{length}" if options[:length]
|
127
127
|
NumberStation.log.debug "numpads: #{numpads}" if options[:numpads]
|
128
128
|
NumberStation.log.debug "path: #{path}" if options[:path]
|
129
129
|
|
130
|
-
NumberStation.make_otp(path, length,
|
130
|
+
NumberStation.make_otp(path, length, numpads)
|
131
131
|
end
|
132
132
|
|
133
133
|
|
@@ -161,7 +161,7 @@ module NumberStation
|
|
161
161
|
|
162
162
|
|
163
163
|
# decrypt message with a pad
|
164
|
-
desc "
|
164
|
+
desc "decrypt_message [MESSAGE --numpad NUMPAD --padpath PADPATH]", "Decrypt a message using the key: NUMPAD in one time pad PADPATH"
|
165
165
|
long_desc <<-DECRYPT_MESSAGE_LONG_DESC
|
166
166
|
Encrypt a message using key NUMPAD in one-time-pad PADPATH
|
167
167
|
Parameters:\n
|
@@ -180,7 +180,7 @@ module NumberStation
|
|
180
180
|
numpad = options[:numpad]
|
181
181
|
padpath = options[:padpath]
|
182
182
|
|
183
|
-
NumberStation.log.debug "message: #{message}"
|
183
|
+
NumberStation.log.debug "message: #{message}"
|
184
184
|
NumberStation.log.debug "numpad: #{numpad}" if options[:numpad]
|
185
185
|
NumberStation.log.debug "padpath: #{padpath}" if options[:padpath]
|
186
186
|
|
@@ -24,11 +24,8 @@ require "json"
|
|
24
24
|
module NumberStation
|
25
25
|
|
26
26
|
def self.decrypt_message(message, pad_path, pad_num)
|
27
|
-
message = message || "This is a secret message"
|
28
27
|
NumberStation.log.debug "message length: #{message.size}"
|
29
28
|
message_byte_array = message.scan(/.{1}/).each_slice(2).map { |f, l| (Integer(f,16) << 4) + Integer(l,16) }
|
30
|
-
#message.unpack('U*')
|
31
|
-
#NumberStation.log.debug "#{message_byte_array.inspect}"
|
32
29
|
|
33
30
|
begin
|
34
31
|
pad_data = JSON.parse(File.read(pad_path))
|
@@ -36,35 +33,17 @@ module NumberStation
|
|
36
33
|
raise e
|
37
34
|
end
|
38
35
|
|
39
|
-
|
40
|
-
crypto_hex_str = pad_data["pads"][pad_num]
|
41
|
-
|
36
|
+
crypto_hex_str = pad_data["pads"][pad_num]["key"]
|
42
37
|
NumberStation.log.debug "message length less than pad length: #{message.size <= crypto_hex_str.size}"
|
43
38
|
|
44
|
-
#puts crypto_hex_str
|
45
39
|
crypto_byte_array = crypto_hex_str.scan(/.{1}/).each_slice(2).map { |f, l| (Integer(f,16) << 4) + Integer(l,16) }
|
46
|
-
#puts crypto_byte_array.inspect
|
47
|
-
|
48
|
-
#encrypted_byte_array = []
|
49
|
-
#message_byte_array.each_with_index do |i, index|
|
50
|
-
# encrypted_byte_array << (i ^ crypto_byte_array[index])
|
51
|
-
#end
|
52
|
-
#puts encrypted_byte_array.inspect
|
53
|
-
|
54
|
-
#encrypted_byte_str = encrypted_byte_array.each.map {|i| i.to_s(16)}.join
|
55
|
-
#encrypted_byte_array_two = encrypted_byte_str.scan(/.{1}/).each_slice(2).map { |f, l| (Integer(f,16) << 4) + Integer(l,16) }
|
56
40
|
|
57
41
|
decrypted_byte_array = []
|
58
42
|
message_byte_array.each_with_index do |i, index|
|
59
43
|
decrypted_byte_array << (i ^ crypto_byte_array[index])
|
60
44
|
end
|
61
|
-
#puts decrypted_byte_array.inspect
|
62
45
|
|
63
46
|
decrypted_string = decrypted_byte_array.pack('U*').force_encoding('utf-8')
|
64
|
-
#puts decrypted_string
|
65
|
-
|
66
|
-
#puts message == decrypted_string
|
67
|
-
|
68
47
|
return decrypted_string
|
69
48
|
end
|
70
49
|
|
@@ -24,11 +24,8 @@ require "json"
|
|
24
24
|
module NumberStation
|
25
25
|
|
26
26
|
def self.encrypt_message(message, pad_path, pad_num)
|
27
|
-
puts message
|
28
|
-
message = message || "This is a secret message"
|
29
27
|
NumberStation.log.debug "message length: #{message.size}"
|
30
28
|
message_byte_array = message.unpack('U*')
|
31
|
-
#NumberStation.log.debug "#{message_byte_array.inspect}"
|
32
29
|
|
33
30
|
begin
|
34
31
|
pad_data = JSON.parse(File.read(pad_path))
|
@@ -36,34 +33,39 @@ module NumberStation
|
|
36
33
|
raise e
|
37
34
|
end
|
38
35
|
|
39
|
-
|
40
|
-
|
36
|
+
unless pad_data["pads"][pad_num]["consumed"]
|
37
|
+
crypto_hex_str = pad_data["pads"][pad_num]["key"]
|
38
|
+
NumberStation.log.debug "Marking key as consumed"
|
39
|
+
pad_data["pads"][pad_num]["epoch_date"] = Time.now.to_i
|
40
|
+
pad_data["pads"][pad_num]["consumed"] = true
|
41
|
+
f = File.open(pad_path, "w")
|
42
|
+
f.write(pad_data.to_json)
|
43
|
+
f.close
|
44
|
+
else
|
45
|
+
msg = "Warning pad #{pad_num} has been consumed on #{Time.at(pad_data["pads"][pad_num]["epoch_date"])}"
|
46
|
+
NumberStation.log.error msg
|
47
|
+
exit
|
48
|
+
end
|
41
49
|
|
42
50
|
NumberStation.log.debug "message length less than pad length: #{message.size <= crypto_hex_str.size}"
|
43
|
-
|
44
|
-
#puts crypto_hex_str
|
45
51
|
crypto_byte_array = crypto_hex_str.scan(/.{1}/).each_slice(2).map { |f, l| (Integer(f,16) << 4) + Integer(l,16) }
|
46
|
-
#puts crypto_byte_array.inspect
|
47
52
|
|
48
53
|
encrypted_byte_array = []
|
49
54
|
message_byte_array.each_with_index do |i, index|
|
50
55
|
encrypted_byte_array << (i ^ crypto_byte_array[index])
|
51
56
|
end
|
52
|
-
|
53
|
-
|
54
|
-
encrypted_byte_str = encrypted_byte_array.each.map {|i| i.to_s(16)}.join
|
55
|
-
#encrypted_byte_array_two = encrypted_byte_str.scan(/.{1}/).each_slice(2).map { |f, l| (Integer(f,16) << 4) + Integer(l,16) }
|
56
|
-
|
57
|
-
#decrypted_byte_array = []
|
58
|
-
#encrypted_byte_array_two.each_with_index do |i, index|
|
59
|
-
# decrypted_byte_array << (i ^ crypto_byte_array[index])
|
60
|
-
#end
|
61
|
-
#puts decrypted_byte_array.inspect
|
62
|
-
|
63
|
-
#decrypted_string = decrypted_byte_array.pack('U*').force_encoding('utf-8')
|
64
|
-
#puts decrypted_string
|
57
|
+
|
58
|
+
encrypted_byte_str = encrypted_byte_array.map { |n| '%02X' % (n & 0xFF) }.join.downcase
|
65
59
|
|
66
|
-
|
60
|
+
begin
|
61
|
+
f_name = "#{pad_data["id"]}_#{pad_num}_#{Time.now.to_i}.txt"
|
62
|
+
NumberStation.log.debug "Writing encrypted message to file #{f_name}"
|
63
|
+
f = File.open(f_name, "w")
|
64
|
+
f.write(encrypted_byte_str)
|
65
|
+
f.close
|
66
|
+
rescue Exception => e
|
67
|
+
raise e
|
68
|
+
end
|
67
69
|
|
68
70
|
return encrypted_byte_str
|
69
71
|
end
|
@@ -20,6 +20,7 @@
|
|
20
20
|
=end
|
21
21
|
require "securerandom"
|
22
22
|
require "json"
|
23
|
+
require "time"
|
23
24
|
|
24
25
|
module NumberStation
|
25
26
|
def self.make_otp(pad_path, length, num_pads)
|
@@ -33,7 +34,13 @@ module NumberStation
|
|
33
34
|
file_name = File.join(path, "one_time_pad_#{id}.json")
|
34
35
|
NumberStation.log.debug "file_name: #{file_name}"
|
35
36
|
|
36
|
-
0.upto(num.to_i - 1)
|
37
|
+
0.upto(num.to_i - 1) do |i|
|
38
|
+
pads[i] = {
|
39
|
+
"key"=>SecureRandom.hex(len.to_i),
|
40
|
+
"epoch_date"=>nil,
|
41
|
+
"consumed"=>false
|
42
|
+
}
|
43
|
+
end
|
37
44
|
one_time_pads = {
|
38
45
|
:id=> id,
|
39
46
|
:pads=> pads
|
data/number_station.gemspec
CHANGED
@@ -26,7 +26,7 @@ require "number_station/version"
|
|
26
26
|
Gem::Specification.new do |spec|
|
27
27
|
spec.name = "number_station"
|
28
28
|
spec.version = NumberStation::VERSION
|
29
|
-
spec.date = "2018-10-
|
29
|
+
spec.date = "2018-10-23"
|
30
30
|
spec.authors = ["David Kirwan"]
|
31
31
|
spec.email = ["davidkirwanirl@gmail.com"]
|
32
32
|
spec.license = "GPL 3.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: number_station
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Kirwan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|