Class: Complicode::Generators::AsciiSums

Inherits:
Object
  • Object
show all
Defined in:
lib/complicode/generators/ascii_sums.rb

Class Method Summary collapse

Class Method Details

.call(encrypted_data, partials_count) ⇒ Struct

Parameters:

  • encrypted_data (String)
  • partials_count (Integer)

Returns:

  • (Struct)

9
10
11
12
13
14
15
16
# File 'lib/complicode/generators/ascii_sums.rb', line 9

def self.call(encrypted_data, partials_count)
  Struct.new(:total, :partials).new(0, Array.new(partials_count, 0)).tap do |sums|
    encrypted_data.each_byte.with_index do |byte, index|
      sums.total += byte
      sums.partials[index % partials_count] += byte
    end
  end
end