ExkPasswd.Transform.Substitution (ExkPasswd v0.1.1)

View Source

Character substitution transformation (leetspeak-style).

This transform replaces characters with symbols or numbers:

  • a@
  • e3
  • i!
  • o0
  • s$

Modes

  • :none - No substitutions
  • :always - Always apply substitutions (deterministic, no entropy)
  • :random - Randomly apply per word (adds 1 bit entropy per word)

Examples

subs = %{"e" => "3", "o" => "0"}
transform = %ExkPasswd.Transform.Substitution{map: subs, mode: :always}
ExkPasswd.Transform.apply(transform, "hello", config)
#=> "h3ll0"

transform = %ExkPasswd.Transform.Substitution{map: subs, mode: :random}
ExkPasswd.Transform.apply(transform, "hello", config)
#=> "h3ll0" or "hello" (random)

Summary

Functions

Calculate how many substitutable characters exist in a word.

Returns the default character substitution map.

Types

mode()

@type mode() :: :none | :always | :random

t()

@type t() :: %ExkPasswd.Transform.Substitution{
  map: %{required(String.t()) => String.t()},
  mode: mode()
}

Functions

count_substitutable(word, substitutions)

@spec count_substitutable(String.t(), map()) :: non_neg_integer()

Calculate how many substitutable characters exist in a word.

Useful for entropy calculations and analysis.

Parameters

  • word - The word to analyze
  • substitutions - Map of character substitutions

Returns

Count of substitutable characters.

Examples

iex> ExkPasswd.Transform.Substitution.count_substitutable("hello", %{
...>   "e" => "3",
...>   "l" => "1",
...>   "o" => "0"
...> })
4

default_substitutions()

@spec default_substitutions() :: map()

Returns the default character substitution map.

Examples

iex> subs = ExkPasswd.Transform.Substitution.default_substitutions()
...> Map.get(subs, "e")
"3"