unveiler 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/unveiler +62 -11
- data/lib/unveiler.rb +6 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a0a0cd10d2fb7c824ca8f8fe7e1c0faacb6a3e4
|
4
|
+
data.tar.gz: e348cd099894106a3335fa21940adb4ef269fab4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94d770ff5573c8f2fbbe7d6f343f500fd7d96ed1661513ee581d05af1b210b7b22a897dfb5650c841416d3f4900183edff1c250813362ce2672dde87d30a35df
|
7
|
+
data.tar.gz: 0fd8072c8a75354e13621fc7123f7dca7f458389fa3d2c574d6559a0c91890f1003dbc65b3f795d4c36723b0c60c8f5e385b6e419873015f6267de97ab8e256c
|
data/bin/unveiler
CHANGED
@@ -6,15 +6,25 @@ require 'unveiler'
|
|
6
6
|
#
|
7
7
|
# +input+:: File to be encoded
|
8
8
|
# +output+:: File to write encoded data to
|
9
|
-
# +
|
10
|
-
|
9
|
+
# +type+:: Specifies whether the data is a file name or a string
|
10
|
+
# +value+:: File name or string data
|
11
|
+
def encode(input, output, type, value)
|
12
|
+
puts 'Starting encoding! This may take some time...'
|
13
|
+
start_time = Time.now
|
14
|
+
|
15
|
+
data = value if type == 'string'
|
16
|
+
data = read_file(value) if type == 'file'
|
17
|
+
|
11
18
|
begin
|
12
19
|
target = read_file(input)
|
13
20
|
data = Unveiler.encode(target, data)
|
14
21
|
write_file(output, data)
|
15
22
|
rescue
|
16
|
-
puts
|
23
|
+
puts $!.message
|
17
24
|
end
|
25
|
+
|
26
|
+
time_elapsed = (Time.now - start_time).round(3)
|
27
|
+
puts "Encoding completed in #{time_elapsed} seconds!"
|
18
28
|
end
|
19
29
|
|
20
30
|
# Decodes the provided input file and saves the decoded data to the output
|
@@ -23,6 +33,9 @@ end
|
|
23
33
|
# +input+:: File to be decoded
|
24
34
|
# +output+:: File to write decoded data to
|
25
35
|
def decode(input, output)
|
36
|
+
puts 'Starting decoding! This may take some time...'
|
37
|
+
start_time = Time.now
|
38
|
+
|
26
39
|
begin
|
27
40
|
target = read_file(input)
|
28
41
|
data = Unveiler.decode(target)
|
@@ -30,6 +43,9 @@ def decode(input, output)
|
|
30
43
|
rescue
|
31
44
|
puts $!.message
|
32
45
|
end
|
46
|
+
|
47
|
+
time_elapsed = (Time.now - start_time).round(3)
|
48
|
+
puts "Decoding completed in #{time_elapsed} seconds!"
|
33
49
|
end
|
34
50
|
|
35
51
|
# Reads data from the specified file.
|
@@ -48,20 +64,55 @@ end
|
|
48
64
|
|
49
65
|
# Prints unveiler usage examples.
|
50
66
|
def usage
|
51
|
-
puts
|
52
|
-
puts
|
53
|
-
puts
|
67
|
+
puts "Usage Guide:"
|
68
|
+
puts "Short\tLong\t\tDescription"
|
69
|
+
puts "-e\t--encode\tEncodes the specified input file"
|
70
|
+
puts "-d\t--decode\tDecodes the specified input file"
|
71
|
+
puts "-i\t--input\t\tFile to read from"
|
72
|
+
puts "-o\t--output\tFile to write to"
|
73
|
+
puts "-s\t--string\tSpecify a string of data (following, in quotes)"
|
74
|
+
puts "-f\t--file\t\tSpecify a file to load data from"
|
75
|
+
exit
|
54
76
|
end
|
55
77
|
|
56
78
|
# Parses ARGV to ensure the correct parameters are given.
|
57
79
|
def parse_argv
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
80
|
+
command = ''
|
81
|
+
data_type = ''
|
82
|
+
data_value = ''
|
83
|
+
input_file = ''
|
84
|
+
output_file = ''
|
85
|
+
|
86
|
+
begin
|
87
|
+
ARGV.length.times do |i|
|
88
|
+
if ARGV[i] == '-e' || ARGV[i] == '--encode'
|
89
|
+
command = 'encode'
|
90
|
+
elsif ARGV[i] == '-d' || ARGV[i] == '--decode'
|
91
|
+
command = 'decode'
|
92
|
+
elsif ARGV[i] == '-i' || ARGV[i] == '--input'
|
93
|
+
input_file = ARGV[i + 1]
|
94
|
+
elsif ARGV[i] == '-o' || ARGV[i] == '--output'
|
95
|
+
output_file = ARGV[i + 1]
|
96
|
+
elsif ARGV[i] == '-s' || ARGV[i] == '--string'
|
97
|
+
data_type = 'string'
|
98
|
+
data_value = ARGV[i + 1]
|
99
|
+
elsif ARGV[i] == '-f' || ARGV[i] == '--file'
|
100
|
+
data_type = 'file'
|
101
|
+
data_value = ARGV[i + 1]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
rescue
|
63
105
|
usage
|
64
106
|
end
|
107
|
+
|
108
|
+
usage if command == '' || input_file == '' || output_file == ''
|
109
|
+
usage if command == 'encode' && (data_type == '' || data_value == '')
|
110
|
+
|
111
|
+
if command == 'encode'
|
112
|
+
encode(input_file, output_file, data_type, data_value)
|
113
|
+
elsif command == 'decode'
|
114
|
+
decode(input_file, output_file)
|
115
|
+
end
|
65
116
|
end
|
66
117
|
|
67
118
|
ARGV.empty? ? usage : parse_argv
|
data/lib/unveiler.rb
CHANGED
@@ -88,6 +88,7 @@ class Unveiler
|
|
88
88
|
#
|
89
89
|
# +bytes+:: Array of bytes to be processed
|
90
90
|
def self.process_bytes(bytes)
|
91
|
+
eof = '010001010100111101000110' # binary "EOF"
|
91
92
|
bits = ''
|
92
93
|
|
93
94
|
8.times do |index|
|
@@ -96,20 +97,16 @@ class Unveiler
|
|
96
97
|
bits += byte[7 - index]
|
97
98
|
|
98
99
|
# Check whether a full byte has been read
|
99
|
-
if bits.length % 8 == 0
|
100
|
-
|
101
|
-
|
100
|
+
if bits.length % 8 == 0 && bits.length >= 24
|
101
|
+
if bits[-24..-1] == eof
|
102
|
+
# Convert bits to array of bytes
|
103
|
+
data = bits.scan(/.{8}/)
|
102
104
|
|
103
|
-
if data.length >= 3
|
104
105
|
# Convert bytes to a UTF-8 string
|
105
106
|
data.map!{|b| byte = b.to_i(2)}
|
106
107
|
data = data.pack('C*').force_encoding('utf-8')
|
107
|
-
len = data.length
|
108
108
|
|
109
|
-
|
110
|
-
# Return the UTF-8 string, excluding 'EOF'
|
111
|
-
return data[0..len - 3]
|
112
|
-
end
|
109
|
+
return data[0..data.length - 3]
|
113
110
|
end
|
114
111
|
end
|
115
112
|
end
|