// Given a { length, fixed, count } triplet, calculate the internal state of // inc_key_loop() after the specified number of crypt operations. // // Note that the state produced may be a few crypts early due to the // number_cache behaviour. This is unavoidable, john does the same thing with // REC files internally. static bool calculate_number_state(uint8_t *numbers, uint32_t length, uint32_t fixed, uint32_t count, uint64_t crypts) { // Compensate for the number_cache in inc_key_loop() skipping certain // increments of numbers[]. if (fixed != length) crypts = crypts - (crypts % (count + 1)); // Convert number of crypts into a k-digit base-n representation // of crypts. This closely matches how John stores it's internal state, // with the exception of fixed digits. convert_to_base(numbers, kMaxLength, count + 1, crypts); // Move the digits above the fixed digit down one position, because the // fixed digit will displace them. This is the same as partial // multiplication of these digits by base, but moving them is more // efficient than having to convert them to integers. memmove(&numbers[0], &numbers[1], fixed); // Now we can force the fixed digit into the correct position. numbers[fixed] = count; // Finally, we need to adjust the digits above the fixed position // independently. This is because John will never set a digit in those // positions to count, however other arithmetic rules still apply. // // We can interpret this algorithm behaviour as setting these digits to one // base lower than the rest of the digits. Yes, this is confusing. convert_to_base(numbers, fixed, count, convert_from_base(numbers, fixed, count + 1)); // Complete. return true; }
void standard_use_type::post_use() { convert_from_base(); }
void standard_into_type::do_into() { int colType = sqlite3_column_type(m_st->m_stmt, m_iCol); if (colType == SQLITE_NULL) { // null encountered with no indicator check_precondition (m_ind != nullptr); *m_ind = i_null; } else { if (m_ind) *m_ind = i_ok; switch (colType) { case SQLITE_INTEGER: { sqlite3_int64 v = sqlite3_column_int64(m_st->m_stmt, m_iCol); switch (m_type) { case x_bool: as<bool>(m_data) = v != 0; break; case x_char: integer_into<char>(m_data, v); break; case x_short: integer_into<short>(m_data, v); break; case x_int: integer_into<int>(m_data, v); break; case x_long: integer_into<long>(m_data, v); break; case x_int64: integer_into<int64>(m_data, v); break; case x_uchar: integer_into<unsigned char>(m_data, v); break; case x_ushort: integer_into<unsigned short>(m_data, v); break; case x_uint: integer_into<unsigned int>(m_data, v); break; case x_ulong: integer_into<unsigned long>(m_data, v); break; case x_uint64: integer_into<uint64>(m_data, v); break; case x_beastString: as <String> (m_data) = String(v); break; default: fatal_error ("unknown case"); } } break; case SQLITE_FLOAT: { double v = sqlite3_column_double(m_st->m_stmt, m_iCol); switch (m_type) { case x_float: as<float>(m_data) = static_cast<float>(v); break; case x_double: as<double>(m_data) = v; break; case x_beastString: as <String> (m_data) = String(v); break; default: fatal_error ("unknown case"); }; } break; case SQLITE_TEXT: { switch (m_type) { case x_stdstring: { // excludes terminator int bytes = sqlite3_column_bytes(m_st->m_stmt, m_iCol); unsigned char const* v = sqlite3_column_text(m_st->m_stmt, m_iCol); std::string& result = as<std::string>(m_data); result.assign(reinterpret_cast<char const*>(v), bytes); } break; case x_stdwstring: fatal_error ("invalid case"); break; case x_beastString: { // excludes terminator int bytes = sqlite3_column_bytes(m_st->m_stmt, m_iCol); const CharPointer_UTF8::CharType* c = reinterpret_cast <const CharPointer_UTF8::CharType*> (sqlite3_column_text(m_st->m_stmt, m_iCol)); String& s = as <String> (m_data); s = String(CharPointer_UTF8(c), CharPointer_UTF8(c + bytes)); } break; default: { sqlite3_int64 v = sqlite3_column_int64(m_st->m_stmt, m_iCol); switch (m_type) { case x_bool: as<bool>(m_data) = v != 0; break; case x_char: integer_into<char>(m_data, v); break; case x_short: integer_into<short>(m_data, v); break; case x_int: integer_into<int>(m_data, v); break; case x_long: integer_into<long>(m_data, v); break; case x_int64: integer_into<int64>(m_data, v); break; case x_uchar: integer_into<unsigned char>(m_data, v); break; case x_ushort: integer_into<unsigned short>(m_data, v); break; case x_uint: integer_into<unsigned int>(m_data, v); break; case x_ulong: integer_into<unsigned long>(m_data, v); break; case x_uint64: integer_into<uint64>(m_data, v); break; default: fatal_error ("unknown case"); } } break; }; } break; case SQLITE_BLOB: fatal_error ("invalid case"); default: fatal_error ("unknown case"); }; } convert_from_base(); }