phraseToInt function
Implementation
BigInt phraseToInt(String phrase) {
BigInt result = BigInt.from(-1);
List<String> words = phrase.split(" ");
for (int i = 0; i < words.length; i++) {
String word = words[i];
int index = DICTIONARY.indexWhere(
(w) => w.startsWith(word.substring(0, ENGLISH_UNIQUE_PREFIX_LEN)));
if (index == -1) {
return BigInt.from(-1); // return -1 if word not found in dictionary
}
BigInt exp = BigInt.from(DICTIONARY_SIZE).pow(i);
BigInt increase = BigInt.from(index + 1) * exp;
result += increase;
}
return result;
}