Help with explaining how this work?
How to create the checksum index from a list of words; can explain it in non c++ terms?
/*!
* \brief Creates a checksum index in the word list array on the list of words.
* \param word_list Vector of words
* \param unique_prefix_length the prefix length of each word to use for checksum
* \return Checksum index
*/
uint32_t create_checksum_index(const std::vector &word_list,
uint32_t unique_prefix_length)
{
std::string trimmed_words = "";
for (std::vector::const_iterator it = word_list.begin(); it != word_list.end(); it++)
{
if (it->length() > unique_prefix_length)
{
trimmed_words += Language::utf8prefix(*it, unique_prefix_length);
}
else
{
trimmed_words += *it;
}
}
boost::crc_32_type result;
result.process_bytes(trimmed_words.data(), trimmed_words.length());
return result.checksum() % crypto::ElectrumWords::seed_length;
}
Also, is it implementable without use of pointers and c++ specific functions such as
inline std::string utf8prefix(const std::string &s, size_t count)
{
std::string prefix = "";
const char *ptr = s.c_str();
while (count-- && *ptr)
{
prefix += *ptr++;
while (((*ptr) & 0xc0) == 0x80)
prefix += *ptr++;
}
return prefix;
}
or
boost::crc_32_type result;
result.process_bytes(trimmed_words.data(), trimmed_words.length());