Class: SafeDb::ToolBelt::Amalgam

Inherits:
Object
  • Object
show all
Defined in:
lib/modules/cryptology/amalgam.rb

Overview

This class knows how to amalgamate passwords, keys and string data in a manner that is the cryptographical equivalent of synergy.

The amalgamated keys are synergially (cryptographically) greater than the sum of their parts.

Class Method Summary collapse

Class Method Details

.passwords(human_password, machine_password, mix_ratio) ⇒ String

Amalgamate the two parameter passwords in a manner that is the cryptographical equivalent of synergy. The amalgamated keys are synergially greater than the sum of their parts.

– Get a viable machine password taking into account the human – password length and the specified mix_ratio.

Parameters:

  • human_password (String)

    the password originating from a human

  • machine_key (String)

    a machine engineered ascii password (key)

Returns:

  • (String)

    the union of the two parameter passwords

Raises:

  • (ArgumentError)

    when the size of the two passwords and the mix ratio do not conform to the constraint imposed by the below equation which must hold true. machine password length = human password length * mix_ratio - 1



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/modules/cryptology/amalgam.rb', line 34

def self.passwords human_password, machine_password, mix_ratio

  size_error_msg = "Human pass length times mix_ratio must equal machine pass length."
  lengths_are_perfect = human_password.length * mix_ratio == machine_password.length
  raise ArgumentError.new size_error_msg unless lengths_are_perfect

  machine_passwd_chunk = 0
  amalgam_passwd_index = 0
  amalgamated_password = ""

  human_password.each_char do |passwd_char|

    amalgamated_password[amalgam_passwd_index] = passwd_char
    amalgam_passwd_index += 1

    for i in 0..(mix_ratio-1) do
      machine_pass_index = machine_passwd_chunk * mix_ratio + i
      amalgamated_password[amalgam_passwd_index] = machine_password[machine_pass_index]
      amalgam_passwd_index += 1
    end

    machine_passwd_chunk += 1

  end

  return amalgamated_password

end