Popularity
0.2
Declining
Activity
0.0
Stable
0
2
0

Description

Easy encoding encoding is a tool that allows you to encode and decode data via: - Huffman encoding; - Shannon-Fano encoding.

Monthly Downloads: 207
Programming language: Ruby
License: MIT License
Tags: Encryption     Security     Projects    
Latest version: v0.0.1

easy_encoding alternatives and similar gems

Based on the "Encryption" category.
Alternatively, view easy_encoding alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of easy_encoding or a related project?

Add another 'Encryption' Gem

README

easy_encoding

Build Status

Easy encoding encoding is a tool that allows you to encode and decode data via:

  • Huffman encoding;
  • Shannon-Fano encoding.

Installation

Add this line to your application's Gemfile:

gem 'easy_encoding'

And then execute:

$ bundle

Or install it yourself as:

$ gem install easy_encoding

Configuration

You can configure symbol for left and right node of tree.

EasyEncoding.configure do |config|
  config.right_node_symbol = '0'
  config.left_node_symbol = '1'
end

Usage

Huffman coding

Using with string:

huffman = EasyEncoding::Huffman.new('code')
huffman.frequencies            #=> {:e=>0.25, :d=>0.25, :o=>0.25, :c=>0.25}
huffman.char_codes             #=> {:c=>"00", :o=>"01", :d=>"10", :e=>"11"}

Using with frequencies:

huffman = EasyEncoding::Huffman.new({ x7: 0.42, x3: 0.28, x5: 0.1, x6: 0.1, x4: 0.05, x2: 0.03, x1: 0.02 })
huffman.frequencies            #=> {:x7=>0.42, :x3=>0.28, :x6=>0.1, :x5=>0.1, :x4=>0.05, :x2=>0.03, :x1=>0.02}
huffman.char_codes             #=> {:x7=>"1", :x3=>"01", :x5=>"0000", :x6=>"0001", :x4=>"0011", :x2=>"00100", :x1=>"00101"}

Shannon-Fano coding

Using with string:

shannon_fano = EasyEncoding::ShannonFano.new('Code')
shannon_fano.frequencies       #=> {"e"=>0.25, "d"=>0.25, "o"=>0.25, "c"=>0.25}
shannon_fano.char_codes        #=> {"e"=>"11", "d"=>"10", "o"=>"01", "c"=>"00"}

Using with frequencies:

shannon_fano = EasyEncoding::ShannonFano.new({ x7: 0.42, x3: 0.28, x5: 0.1, x6: 0.1, x4: 0.05, x2: 0.03, x1: 0.02 })
shannon_fano.frequencies       #=> {:x7=>0.42, :x3=>0.28, :x5=>0.1, :x6=>0.1, :x4=>0.05, :x2=>0.03, :x1=>0.02}
shannon_fano.char_codes        #=> {:x7=>"1", :x3=>"01", :x6=>"0011", :x5=>"0010", :x4=>"0001", :x2=>"00001", :x1=>"00000"}

Contributing

See CONTRIBUTING.md.

License

The gem is available as open source under the terms of the MIT License.


*Note that all licence references and agreements mentioned in the easy_encoding README section above are relevant to that project's source code only.