pgp_wordlist v0.3.0 PgpWordlist View Source

Toolset for working with the PGP word list. Allows converting hex to / from words.

The word list itself belongs to PGP Corporation.

Link to this section Summary

Functions

Converts a 2 digit hex string (with uppercase letters) and even / odd position into a word on the PGP word list.

Converts an even length hex string to list of words

Converts a word to a hex based on the PGP word list.

Converts a list of words to hex based on the PGP word list

Link to this section Functions

Link to this function

hex_to_word(hex, pos)

View Source
hex_to_word(String.t(), non_neg_integer()) ::
  {:ok, String.t()} | {:error, String.t()}

Converts a 2 digit hex string (with uppercase letters) and even / odd position into a word on the PGP word list.

pos is the 0-based index of the hex. There are two words assigned to each hex value with pos determining which word to use based on if it is even or odd.

Examples

iex> PgpWordlist.hex_to_word("00", 0)
{:ok, "aardvark"}
iex> PgpWordlist.hex_to_word("00", 1)
{:ok, "adroitness"}
iex> PgpWordlist.hex_to_word("00", 2)
{:ok, "aardvark"}
iex> PgpWordlist.hex_to_word("FF", 0)
{:ok, "Zulu"}
iex> PgpWordlist.hex_to_word("FF", 1)
{:ok, "Yucatan"}
iex> PgpWordlist.hex_to_word("FF", 33)
{:ok, "Yucatan"}
iex> PgpWordlist.hex_to_word("1", 1)
{:error, "Hex must be 2 bytes long ('01' instead of '1')"}
iex> PgpWordlist.hex_to_word("XX", 1)
{:error, "Not valid hex"}
Link to this function

hex_to_words(hex)

View Source
hex_to_words(String.t()) :: {:ok, [String.t()]} | {:error, String.t()}

Converts an even length hex string to list of words

Any errors encountered during converting any item will be returned immediately without aggregation

Examples

iex> PgpWordlist.hex_to_words("00")
{:ok, ["aardvark"]}
iex> PgpWordlist.hex_to_words("E582")
{:ok, ["topmost", "Istanbul"]}
iex> PgpWordlist.hex_to_words("82E5")
{:ok, ["miser", "travesty"]}
iex> PgpWordlist.hex_to_words("82XXE5")
{:error, "Not valid hex"}
iex> PgpWordlist.hex_to_words("")
{:ok, []}
iex> PgpWordlist.hex_to_words("00F")
{:error, "Hex must be an even amount of bytes long"}
Link to this function

word_to_hex(word)

View Source
word_to_hex(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Converts a word to a hex based on the PGP word list.

Will handle different cases of words and return hex with uppercase letters.

Examples

iex> PgpWordlist.word_to_hex("AARDVARK")
{:ok, "00"}
iex> PgpWordlist.word_to_hex("aardvark")
{:ok, "00"}
iex> PgpWordlist.word_to_hex("AardVaRk")
{:ok, "00"}
iex> PgpWordlist.word_to_hex("woodlark")
{:ok, "FE"}
iex> PgpWordlist.word_to_hex("Windsor")
{:error, "Word does not exist in PGP specification"}
Link to this function

words_to_hex(words)

View Source
words_to_hex([String.t()]) :: String.t()

Converts a list of words to hex based on the PGP word list

Any errors encountered during converting any item will be returned immediately without aggregation

Examples

iex> PgpWordlist.words_to_hex(["topmost", "Istanbul", "Pluto", "vagabond"])
{:ok, "E58294F2"}
iex> PgpWordlist.words_to_hex(["miser", "travesty"])
{:ok, "82E5"}
iex> PgpWordlist.words_to_hex([])
{:ok, ""}
iex> PgpWordlist.words_to_hex(["Windsor"])
{:error, "Word does not exist in PGP specification"}
iex> PgpWordlist.words_to_hex(["miser", "Windsor"])
{:error, "Word does not exist in PGP specification"}