A Source contains attributes of a sequence of bytes, called symbols.
The entropy of the probability distribution.
The frequency distribution of symbols.
The length of the given sequence of symbols.
The empirical probability distribution of symbols.
Analyze sequence generated by `symbols.each_byte'.
# File source.rb, line 9 def initialize(symbols) freq = @frequencies = Hash.new(0) prob = @probabilities = Hash.new symbols.each_byte { |symbol| freq[symbol.chr] += 1 } @length = freq.values.reduce(:+) freq.each { |symbol, n| prob[symbol] = n / @length.to_f } @entropy = prob.values.inject(0){ |sum, p| sum - p * Math.log2(p) } end