number_station 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12fbb0f21da5b3c4b4b30f59c3966b73f105b114598465657a00dde4602f2200
4
- data.tar.gz: 016fe96066f8a08eae780630d2049537ebe6118af9c16cb37e0b2ea0acd3dbee
3
+ metadata.gz: 87052778b344b664ebdbb4e7d9634064c5c3afa4d3b8b20e9d1ab77895c0d493
4
+ data.tar.gz: 4fe01f004ed3dae32e9f245815e0c3db2833ea63f4d3a5dbd8253021b2482d2e
5
5
  SHA512:
6
- metadata.gz: ca0a3954b8b78bef7f6b96707ba33bf5806a760cb80db3ed6e4158952163b55afd5805991c5dff381832842dc822d0c1f1558cf85b56d5cad942b3a4d57c9276
7
- data.tar.gz: f2a30d75eb9dadb26e3fdbcf277be8403ba0449e209517f4188ad10769522438852382c96103d8bb69c0991e4269a3d92676a4ccbda18458b75dba57ab9bb9a7
6
+ metadata.gz: f283b7f691d168924c99f8a388a82322dc5ea6600d1cdea14772563189bb91752243a249c716c09e7c394316c63e02061f1313822a4220f336d5cf2706ffebbc
7
+ data.tar.gz: ac8f1a34e6797f617389ab8f18e3f53ffd7c62f8498a63e434f4a8f07fa17b59fb26db402297248d4a7a5700189845238e9a24bb62e81dee4bd1224a26548c50
@@ -121,13 +121,13 @@ module NumberStation
121
121
  NumberStation.log.debug "make_one_time_pad"
122
122
 
123
123
  length = options[:length]
124
- num_pads = options[:num_pads]
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, num_pads)
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 "encrypt_message [MESSAGE --numpad NUMPAD --padpath PADPATH]", "Decrypt a message using the key: NUMPAD in one time pad PADPATH"
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}" if options[: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
- #crypto_hex_str = SecureRandom.hex(message.size)
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
- #crypto_hex_str = SecureRandom.hex(message.size)
40
- crypto_hex_str = pad_data["pads"][pad_num]
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
- #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
-
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
- #puts message == decrypted_string
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) {|i| pads[i] = SecureRandom.hex(len.to_i)}
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
@@ -20,5 +20,5 @@
20
20
  =end
21
21
 
22
22
  module NumberStation
23
- VERSION = "0.0.3"
23
+ VERSION = "0.0.4"
24
24
  end
@@ -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-12"
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.3
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-12 00:00:00.000000000 Z
11
+ date: 2018-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel