public class Mnemonic
extends java.lang.Object
long
values like
-8798641734435409502 into String
s like nwihyayeetyoruehyazuetro. The advantage here is that
nwihyayeetyoruehyazuetro is very different from protoezlebauyauzlutoatra, even though the numbers they are made from
are harder to distinguish (-8798641734435409502 vs. -8032477240987739423, when using the default seed).
Modifier and Type | Field and Description |
---|---|
Arrangement<java.lang.String> |
allAdjectives |
Arrangement<java.lang.String> |
allNouns |
Arrangement<java.lang.String> |
items |
Constructor and Description |
---|
Mnemonic()
Default constructor for a Mnemonic generator; equivalent to
new Mnemonic(1L) , and probably a good choice
unless you know you need different seeds. |
Mnemonic(long seed)
Constructor for a Mnemonic generator that allows a different seed to be chosen, which will alter the syllables
produced by
toMnemonic(long) and the words produced by toWordMnemonic(int, boolean) if you give
the same numeric argument to differently-seeded Mnemonic generators. |
Mnemonic(long seed,
java.util.Collection<java.lang.String> adjectives,
java.util.Collection<java.lang.String> nouns)
Constructor that allows you to specify the adjective and noun collections used by
toWordMnemonic(int, boolean) as well as a seed. |
Mnemonic(long seed,
java.lang.String[] adjectives,
java.lang.String[] nouns)
Constructor that allows you to specify the adjective and noun collections (given as arrays) used by
toWordMnemonic(int, boolean) as well as a seed. |
Modifier and Type | Method and Description |
---|---|
long |
fromMnemonic(java.lang.String mnemonic)
Takes a String produced by
toMnemonic(long) or toMnemonic(long, boolean) and returns the long
used to encode that gibberish String. |
int |
fromWordMnemonic(java.lang.String mnemonic)
Takes a String phrase produced by
toWordMnemonic(int, boolean) and returns the int used to encode that
String. |
java.lang.String |
toMnemonic(long number)
Given any long, generates a slightly-more-memorable gibberish phrase that can be decoded back to the original
long with
fromMnemonic(String) . |
java.lang.String |
toMnemonic(long number,
boolean capitalize)
Given any long, generates a slightly-more-memorable gibberish phrase that can be decoded back to the original
long with
fromMnemonic(String) . |
java.lang.String |
toWordMnemonic(int number,
boolean capitalize)
Given any int, generates a short phrase that can be decoded back to the original int with
fromWordMnemonic(String) . |
public final Arrangement<java.lang.String> items
public final Arrangement<java.lang.String> allAdjectives
public final Arrangement<java.lang.String> allNouns
public Mnemonic()
new Mnemonic(1L)
, and probably a good choice
unless you know you need different seeds.
Thesaurus.adjective
and Thesaurus.noun
, which can be modified, and if these contents aren't identical for two different
Mnemonic objects (possibly constructed at different times, using different SquidLib versions), the Mnemonics will
have different encoded and decoded forms. You can either save the key set from allAdjectives
and
allNouns
and pass them to Mnemonic(long, Collection, Collection)
, or save the Thesaurus state
altogether using Thesaurus.archiveCategories()
, loading it before constructing any Mnemonics with
Thesaurus.addArchivedCategories(String)
.public Mnemonic(long seed)
toMnemonic(long)
and the words produced by toWordMnemonic(int, boolean)
if you give
the same numeric argument to differently-seeded Mnemonic generators. Unless you know you need this, you should
probably use Mnemonic()
to ensure that your text can be decoded.
Thesaurus.adjective
and Thesaurus.noun
, which can be modified, and if these contents aren't identical for two different
Mnemonic objects (possibly constructed at different times, using different SquidLib versions), the Mnemonics will
have different encoded and decoded forms. You can either save the key set from allAdjectives
and
allNouns
and pass them to Mnemonic(long, Collection, Collection)
, or save the Thesaurus state
altogether using Thesaurus.archiveCategories()
, loading it before constructing any Mnemonics with
Thesaurus.addArchivedCategories(String)
.seed
- a long seed that will be used to randomize the syllables and words used.public Mnemonic(long seed, java.util.Collection<java.lang.String> adjectives, java.util.Collection<java.lang.String> nouns)
toWordMnemonic(int, boolean)
as well as a seed. This should be useful when you want to enforce a stable
relationship between word mnemonics produced by toWordMnemonic(int, boolean)
and the int values they
decode to with fromWordMnemonic(String)
, because the default can change if the adjective and noun
collections in Thesaurus
change. There should be a fairly large amount of unique adjectives and nouns;
(long)adjectives.size() * nouns.size() * adjectives.size() * nouns.size()
should be at least 0x80000000L
(2147483648L), with case disregarded. If the total is less than that, not all possible ints can be encoded with
toWordMnemonic(int, boolean)
. Having 216 adjectives and 216 nouns is enough for a rough target. Each
word (adjectives and nouns alike) can have any characters in it except for space, since space is used during
decoding to separate words.seed
- a long seed that will be used to randomize the syllables and words used.adjectives
- a Collection of unique Strings (case-insensitive) that will be used as adjectivesnouns
- a Collection of unique Strings (case-insensitive) that will be used as nounspublic Mnemonic(long seed, java.lang.String[] adjectives, java.lang.String[] nouns)
toWordMnemonic(int, boolean)
as well as a seed. This should be useful when you want to enforce a stable
relationship between word mnemonics produced by toWordMnemonic(int, boolean)
and the int values they
decode to with fromWordMnemonic(String)
, because the default can change if the adjective and noun
collections in Thesaurus
change. There should be a fairly large amount of unique adjectives and nouns;
(long)adjectives.length * nouns.length * adjectives.length * nouns.length
should be at least 0x80000000L
(2147483648L), with case disregarded. If the total is less than that, not all possible ints can be encoded with
toWordMnemonic(int, boolean)
. Having 216 adjectives and 216 nouns is enough for a rough target. Each
word (adjectives and nouns alike) can have any characters in it except for space, since space is used during
decoding to separate words. You may want to use StringKit.split(String, String)
with space or newline as
the delimiter to get a String array from data containing space-separated words or data with one word per line.
It's also possible to use String.split(String)
, which can use "\\s"
to split on any whitespace.seed
- a long seed that will be used to randomize the syllables and words used.adjectives
- an array of unique Strings (case-insensitive) that will be used as adjectivesnouns
- an array of unique Strings (case-insensitive) that will be used as nounspublic java.lang.String toMnemonic(long number)
fromMnemonic(String)
. Examples of what this can produce are "noahritwimoesaidrubiotso" and
"loanuiskohaimrunoizlupwi", generated by a Mnemonic with a seed of 1 from -3743983437744699304L and
-8967299915041170097L, respectively. The Strings this returns are always 24 chars long, and contain only the
letters a-z.number
- any longpublic java.lang.String toMnemonic(long number, boolean capitalize)
fromMnemonic(String)
. Examples of what this can produce are "noahritwimoesaidrubiotso" and
"loanuiskohaimrunoizlupwi", generated by a Mnemonic with a seed of 1 from -3743983437744699304L and
-8967299915041170097L, respectively. The Strings this returns are always 24 chars long. If capitalize is true,
then the first letter will be a capital letter from A-Z, all other letters will be a-z (including the first if
capitalize is false).number
- any longcapitalize
- if true, the initial letter of the returned mnemonic String will be capitalizedpublic long fromMnemonic(java.lang.String mnemonic)
toMnemonic(long)
or toMnemonic(long, boolean)
and returns the long
used to encode that gibberish String. This can't take just any String; if the given parameter isn't at least 24
characters long, this can throw an IndexOutOfBoundsException
, and if it isn't made purely from the 3-char
syllables toMnemonic() produces, it won't produce a meaningful result.mnemonic
- a gibberish String produced by toMnemonic(long)
or toMnemonic(long, boolean)
mnemonic
originallypublic java.lang.String toWordMnemonic(int number, boolean capitalize)
fromWordMnemonic(String)
. Examples of what this can produce are "Mindful warriors and the pure torch"
and "Dynastic earldom and the thousandfold bandit", generated by a Mnemonic with a seed of 1 from -587415991 and
-1105099633, respectively. Those Strings were generated using the current state of Thesaurus
and the
adjectives and nouns it stores now, and if Thesaurus is added to over time, those Strings won't correspond to
those ints any more. The Strings this returns vary in length. The words this uses by default use only the letters
a-z and the single quote (with A-Z for the first character if capitalize is true), with space separating words.
If you constructed this Mnemonic with adjective and noun collections or arrays, then this will use only those
words and will still separate words with space (and it will capitalize the first char if capitalize is true).number
- any intcapitalize
- if true, the initial letter of the returned mnemonic String will be capitalizedpublic int fromWordMnemonic(java.lang.String mnemonic)
toWordMnemonic(int, boolean)
and returns the int used to encode that
String. This can't take just any String; it must be produced by toWordMnemonic(int, boolean)
to give a
meaningful result.mnemonic
- a String phrase produced by toWordMnemonic(int, boolean)
mnemonic
originallyCopyright © Eben Howard 2012–2022. All rights reserved.