module Cryptools::Cryptanalysis
Public Instance Methods
english_freq_count(str)
click to toggle source
# File lib/cryptools.rb, line 71 def english_freq_count(str) str.scan(/[ETAOIN SHRDLU]/i).length end
index_of_coincidence(input)
click to toggle source
# File lib/cryptools.rb, line 56 def index_of_coincidence(input) fs = input.each_with_object(Hash.new(0)) { |word,counts| counts[word] += 1 } phiO = 0 n = input.length coin_rtext = 0.0385 fs.each { |key, f| phiO += f * (f - 1) } phiR = coin_rtext * n * (n - 1) phiO / phiR end