Class: Cript::Hidr
- Inherits:
-
Object
- Object
- Cript::Hidr
- Defined in:
- lib/cript/hidr.rb
Overview
Hidr can be used to obscure strings in other utf-8 strings. This is not encryption, and it’s not secure!
Constant Summary collapse
- CHARS =
{ ascii: ["\s","\t"], unicode: ["\u200B","\uFEFF"], orly: ["\u0CA0", "\u005F"] }
Class Method Summary collapse
Instance Method Summary collapse
- #e(o) ⇒ Object
- #h(m) ⇒ Object
-
#initialize(*o) ⇒ Hidr
constructor
A new instance of Hidr.
- #s(n) ⇒ Object
Constructor Details
#initialize(*o) ⇒ Hidr
Returns a new instance of Hidr.
25 26 27 28 29 |
# File 'lib/cript/hidr.rb', line 25 def initialize(*o) @o = o.last.is_a?(Hash) ? o.pop : {} @o[:b0] ||= CHARS[:ascii].first @o[:b1] ||= CHARS[:ascii].last end |
Class Method Details
.build(type) ⇒ Object
17 18 19 20 21 |
# File 'lib/cript/hidr.rb', line 17 def build(type) if CHARS.has_key?(type) new(b0: CHARS[type].first, b1: CHARS[type].last) end end |
Instance Method Details
#e(o) ⇒ Object
33 |
# File 'lib/cript/hidr.rb', line 33 def e(o);s(h(o));end |
#h(m) ⇒ Object
31 |
# File 'lib/cript/hidr.rb', line 31 def h(m);m.unpack('b*').first.split("").map{|v|v=='0'?@o[:b0]:@o[:b1]}.join;end |
#s(n) ⇒ Object
32 |
# File 'lib/cript/hidr.rb', line 32 def s(n);[n.chars.to_a.map{|y|y==@o[:b0]?'0':'1'}.join].pack('b*');end |