Module: Cryptools::Cryptanalysis
- Defined in:
- lib/cryptools.rb
Class Method Summary collapse
Class Method Details
.english_freq_count(str) ⇒ Object
71 72 73 |
# File 'lib/cryptools.rb', line 71 def english_freq_count(str) str.scan(/[ETAOIN SHRDLU]/i).length end |
.index_of_coincidence(input) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# 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 |