hidr 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - jruby-19mode
6
+ - rbx-2.1.1
7
+ script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hidr.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrew Tongen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Hidr
2
+
3
+ Hide your strings!
4
+
5
+ [![Build Status](https://travis-ci.org/atongen/hidr.png)](https://travis-ci.org/atongen/hidr)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'hidr'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install hidr
20
+
21
+ ## Usage
22
+
23
+ Hidr allows you to obscure strings in other strings by facilitating a two-way conversion
24
+ between a string and a binary version of that string.
25
+
26
+ The resulting binary characters can be any two charaters. By default it uses a space and a tab.
27
+
28
+ ```ruby
29
+ h = hidr::Hidr.new(b0: 'a', b1: 'z')
30
+ result = h.hide('Wow!')
31
+ ```
32
+
33
+ After running this code, result will contain "zzzazazazzzzazzazzzazzzazaaaazaa".
34
+
35
+ It comes with a few commonly used mappings already setup: ascii, unicode, orly.
36
+ Call the class method of the same name to get these hidrs.
37
+
38
+ You can use Hidr from bash with the `hidr` executable. For example:
39
+
40
+ ```
41
+ % echo Some important stuff | bin/hidr -h
42
+ 110010101111011010110110101001100000010010010110101101100000111011110110010011100010111010000110011101100010111000000100110011100010111010101110011001100110011001010000
43
+ ```
44
+
45
+ or even
46
+
47
+ ```
48
+ % echo Some important stuff | bin/hidr -h | bin/hidr -s
49
+ Some important stuff
50
+ ```
51
+
52
+ Type `hidr --help` after gem installation for usage.
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/hidr ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) &&
5
+ !$LOAD_PATH.include?(lib)
6
+ require 'hidr/hidr_command'
7
+ Hidr::HidrCommand.new(ARGV).run!
data/hidr.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hidr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hidr"
8
+ spec.version = Hidr::VERSION
9
+ spec.authors = ["Andrew Tongen"]
10
+ spec.email = ["atongen@gmail.com"]
11
+ spec.description = %q{Hide your strings!}
12
+ spec.summary = %q{Convert strings to and from a binary representation}
13
+ spec.homepage = "https://github.com/atongen/hidr"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
data/lib/hidr.rb ADDED
@@ -0,0 +1,23 @@
1
+ require "hidr/version"
2
+ require "hidr/hidr"
3
+
4
+ # Hidr can be used to obscure strings in other utf-8 strings.
5
+ # This is not encryption, it's obfuscation.
6
+ module Hidr
7
+ CHARS = {
8
+ binary: ["0", "1"],
9
+ ascii: ["\s","\t"],
10
+ unicode: ["\u200B","\uFEFF"],
11
+ orly: ["\u0CA0", "\u005F"],
12
+ niceday: ["\s", "\u263A"]
13
+ }
14
+
15
+ class << self
16
+ def build(type)
17
+ if CHARS.has_key?(type)
18
+ ::Hidr::Hidr.new(b0: CHARS[type].first, b1: CHARS[type].last)
19
+ end
20
+ end
21
+ CHARS.keys.each { |key| class_eval("def #{key}; build(:#{key}); end") }
22
+ end
23
+ end
data/lib/hidr/hidr.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'hidr/impl'
2
+
3
+ module Hidr
4
+ class Hidr
5
+ include Impl
6
+
7
+ def initialize(*o)
8
+ @o = o.last.is_a?(Hash) ? o.pop : {}
9
+ @o[:b0] ||= ::Hidr::CHARS[:ascii].first
10
+ @o[:b1] ||= ::Hidr::CHARS[:ascii].last
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,136 @@
1
+ require 'hidr'
2
+ require 'optparse'
3
+
4
+ module Hidr
5
+ class HidrCommand
6
+
7
+ attr_reader :options
8
+
9
+ def initialize(argv)
10
+ @argv = argv.dup
11
+
12
+ @options = {
13
+ mode: nil,
14
+ infile: '-',
15
+ outfile: '-',
16
+ force: false,
17
+ b0: '0',
18
+ b1: '1',
19
+ debug: false
20
+ }
21
+
22
+ parse!
23
+ end
24
+
25
+ def run!
26
+ validate_mode
27
+ hidr = build_hidr
28
+ data = read_data
29
+ get_writer do |writer|
30
+ if @options[:mode] == 'hide'
31
+ writer.print hidr.hide(data)
32
+ else
33
+ writer.print hidr.show(data)
34
+ end
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def parser
41
+ @parser ||= OptionParser.new do |opts|
42
+ opts.banner = "Usage: hidr [options]"
43
+
44
+ opts.separator ""
45
+ opts.separator "Mode:"
46
+ opts.on("-h", "--hide", "hide mode") { @options[:mode] = 'hide' }
47
+ opts.on("-s", "--show", "show mode") { @options[:mode] = 'show' }
48
+
49
+ opts.separator ""
50
+ opts.separator "Bits:"
51
+ opts.on("-0", "--zero CHAR", "zero char (default: '#{@options[:b0]}')") { |char| @options[:b0] = char }
52
+ opts.on("-1", "--one CHAR", "one char (default: '#{@options[:b1]}')") { |char| @options[:b1] = char }
53
+ opts.on("-b", "--builtin BUILTIN", "built-in binary set (overrides zero and one, options: #{::Hidr::CHARS.keys.join(', ')})") { |builtin| @options[:builtin] = builtin.to_s.strip.to_sym }
54
+
55
+ opts.separator ""
56
+ opts.separator "Files:"
57
+ opts.on("-i", "--infile FILE", "infile (default: '#{@options[:infile]}')") { |file| @options[:infile] = file }
58
+ opts.on("-o", "--outfile FILE", "outfile (default: '#{@options[:outfile]}')") { |file| @options[:outfile] = file }
59
+ opts.on("-f", "--force", "force overwrite outfile (default: #{@options[:force]})") { @options[:force] = true }
60
+
61
+ opts.separator ""
62
+ opts.separator "Common options:"
63
+
64
+ opts.on_tail("-D", "--debug", "Set debugging on") { @options[:debug] = true }
65
+ opts.on_tail("-H", "--help", "Show this message") { puts opts; exit }
66
+ opts.on_tail('-v', '--version', "Show version") { puts Hidr::VERSION; exit }
67
+ end
68
+ end
69
+
70
+ def parse!
71
+ parser.parse!(@argv)
72
+ end
73
+
74
+ # run methods
75
+
76
+ def validate_mode
77
+ unless %w{ hide show }.include?(@options[:mode])
78
+ STDERR.puts "Mode (show or hide) is required."
79
+ exit 1
80
+ end
81
+ end
82
+
83
+ def build_hidr
84
+ if @options[:builtin]
85
+ if ::Hidr::CHARS.keys.include?(@options[:builtin])
86
+ ::Hidr.send(@options[:builtin])
87
+ else
88
+ STDERR.puts "Invalid builtin: #{@options[:builtin]}"
89
+ exit 1
90
+ end
91
+ else
92
+ ::Hidr::Hidr.new(b0: @options[:b0], b1: @options[:b1])
93
+ end
94
+ end
95
+
96
+ def read_data
97
+ if @options[:infile] == '-'
98
+ # requires ARGV clear
99
+ STDIN.read
100
+ elsif File.file?(@options[:infile])
101
+ File.read(@options[:infile])
102
+ else
103
+ STDERR.puts "Invalid infile: #{@options[:infile]}"
104
+ exit 1
105
+ end
106
+ end
107
+
108
+ def get_writer
109
+ begin
110
+ if @options[:outfile] == '-'
111
+ writer = STDOUT
112
+ elsif File.file?(@options[:outfile])
113
+ if @options[:force]
114
+ writer = File.open(@options[:outfile], 'wb')
115
+ else
116
+ STDERR.puts "Not overwriting file without force"
117
+ exit 1
118
+ end
119
+ else
120
+ writer = File.open(@options[:outfile], 'wb')
121
+ end
122
+
123
+ yield(writer)
124
+ rescue => e
125
+ STDERR.puts "Error writing data: #{e}"
126
+ exit 1
127
+ ensure
128
+ # clean-up
129
+ if writer && @options[:outfile] != '-'
130
+ writer.close
131
+ end
132
+ end
133
+ end
134
+
135
+ end
136
+ end
data/lib/hidr/impl.rb ADDED
@@ -0,0 +1,12 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Hidr::Impl provides methods that convert a string
4
+ # to and from a binary representation.
5
+ module Hidr
6
+ module Impl
7
+ def h(m);m.unpack('b*').first.split("").map{|v|v=='0'?@o[:b0]:@o[:b1]}.join;end
8
+ def s(n);[n.chars.to_a.map{|y|y==@o[:b0]?'0':'1'}.join].pack('b*');end
9
+ def e(o);s(h(o));end
10
+ { hide: :h, show: :s, echo: :e }.each { |k,v| alias_method k, v }
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Hidr
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ require 'hidr/hidr_command'
3
+
4
+ describe Hidr::HidrCommand do
5
+
6
+ subject(:cmd) { Hidr::HidrCommand.new(args.split(" ")) }
7
+ let(:args) { nil }
8
+
9
+ context 'parse' do
10
+ context 'hide' do
11
+ let(:args) { "-h -0 a -1 b -i /tmp/in.txt -o /tmp/out.txt -f -D" }
12
+
13
+ it 'should parse hide options' do
14
+ cmd.options[:mode].should eql('hide')
15
+ cmd.options[:b0].should eql('a')
16
+ cmd.options[:b1].should eql('b')
17
+ cmd.options[:infile].should eql('/tmp/in.txt')
18
+ cmd.options[:outfile].should eql('/tmp/out.txt')
19
+ cmd.options[:force].should be_true
20
+ cmd.options[:debug].should be_true
21
+ end
22
+ end
23
+
24
+ context 'show' do
25
+ let(:args) { "-s -0 a -1 b -i /tmp/in.txt -o /tmp/out.txt -f -D" }
26
+
27
+ it 'should parse show options' do
28
+ cmd.options[:mode].should eql('show')
29
+ cmd.options[:b0].should eql('a')
30
+ cmd.options[:b1].should eql('b')
31
+ cmd.options[:infile].should eql('/tmp/in.txt')
32
+ cmd.options[:outfile].should eql('/tmp/out.txt')
33
+ cmd.options[:force].should be_true
34
+ cmd.options[:debug].should be_true
35
+ end
36
+ end
37
+
38
+ context 'builtin' do
39
+ let(:args) { "-s -b orly -i /tmp/in.txt -o /tmp/out.txt -f -D" }
40
+
41
+ it 'should recognize built-in hidrs' do
42
+ hidr = cmd.send(:build_hidr)
43
+ opts = hidr.instance_variable_get(:@o)
44
+ opts[:b0].should eql("\u0CA0")
45
+ opts[:b1].should eql("\u005F")
46
+ end
47
+ end
48
+ end
49
+ end
data/spec/hidr_spec.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hidr do
4
+ let(:hidr) { nil }
5
+ let(:ascii) { SecureRandom.base64(10240) }
6
+ let(:bytes) { SecureRandom.random_bytes(10240) }
7
+
8
+ context "ascii out" do
9
+ let(:hidr) { Hidr.ascii }
10
+
11
+ it 'should echo ascii' do
12
+ hidr.echo(ascii).should eql(ascii)
13
+ end
14
+
15
+ it 'should echo bytes' do
16
+ hidr.echo(bytes).should eql(bytes)
17
+ end
18
+ end
19
+
20
+ context "unicode out" do
21
+ let(:hidr) { Hidr.unicode }
22
+
23
+ it 'should echo ascii' do
24
+ hidr.echo(ascii).should eql(ascii)
25
+ end
26
+
27
+ it 'should echo bytes' do
28
+ hidr.echo(bytes).should eql(bytes)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'hidr'
5
+ require 'securerandom'
6
+
7
+ RSpec.configure do |config|
8
+ # some (optional) config here
9
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hidr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Tongen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Hide your strings!
63
+ email:
64
+ - atongen@gmail.com
65
+ executables:
66
+ - hidr
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .rspec
72
+ - .travis.yml
73
+ - Gemfile
74
+ - LICENSE.txt
75
+ - README.md
76
+ - Rakefile
77
+ - bin/hidr
78
+ - hidr.gemspec
79
+ - lib/hidr.rb
80
+ - lib/hidr/hidr.rb
81
+ - lib/hidr/hidr_command.rb
82
+ - lib/hidr/impl.rb
83
+ - lib/hidr/version.rb
84
+ - spec/hidr_command_spec.rb
85
+ - spec/hidr_spec.rb
86
+ - spec/spec_helper.rb
87
+ homepage: https://github.com/atongen/hidr
88
+ licenses:
89
+ - MIT
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 1.8.23
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Convert strings to and from a binary representation
112
+ test_files:
113
+ - spec/hidr_command_spec.rb
114
+ - spec/hidr_spec.rb
115
+ - spec/spec_helper.rb
116
+ has_rdoc: