Skip to content

Commit

Permalink
Optimize precomputations of possible Z{-1}[24,32) values
Browse files Browse the repository at this point in the history
Looping through charset4 was mostly useless.
msb(y[3]) was very often the same in each iteration.
  • Loading branch information
kimci86 committed Dec 25, 2024
1 parent dda11f2 commit 446f2c1
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/password.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ template <typename Derived /* must implement onSolutionFound() method */>
class SixCharactersRecovery
{
public:
SixCharactersRecovery(const Keys& target, const std::vector<std::uint8_t>& charset4,
const std::vector<std::uint8_t>& charset5)
SixCharactersRecovery(const Keys& target, const std::vector<std::uint8_t>& charset5)
{
// initialize target X, Y and Z values
x[6] = target.getX();
Expand All @@ -37,11 +36,20 @@ class SixCharactersRecovery
y[4] = (y[5] - 1) * MultTab::multInv - lsb(x[5]);
z[3] = Crc32Tab::crc32inv(z[4], msb(y[4]));

for (const auto p4 : charset4)
const auto y3_ignoring_lsb_x4 = (y[4] - 1) * MultTab::multInv;
const auto msb_y3_min = msb(y3_ignoring_lsb_x4 - 255);
const auto msb_y3_max = msb(y3_ignoring_lsb_x4 - 0);

z[2] = Crc32Tab::crc32inv(z[3], msb_y3_min);
z[1] = Crc32Tab::crc32inv(z[2], 0);
z[0] = Crc32Tab::crc32inv(z[1], 0);

z0_16_32.set(z[0] >> 16);
zm1_24_32.set(Crc32Tab::crc32inv(z[0], 0) >> 24);

if (msb_y3_max != msb_y3_min)
{
x[4] = Crc32Tab::crc32inv(x[5], p4);
y[3] = (y[4] - 1) * MultTab::multInv - lsb(x[4]);
z[2] = Crc32Tab::crc32inv(z[3], msb(y[3]));
z[2] = Crc32Tab::crc32inv(z[3], msb_y3_max);
z[1] = Crc32Tab::crc32inv(z[2], 0);
z[0] = Crc32Tab::crc32inv(z[1], 0);

Expand Down Expand Up @@ -140,7 +148,7 @@ class BruteforceRecovery : public SixCharactersRecovery<BruteforceRecovery>
public:
BruteforceRecovery(const Keys& keys, const std::vector<std::uint8_t>& charset, std::vector<std::string>& solutions,
std::mutex& solutionsMutex, bool exhaustive, Progress& progress)
: SixCharactersRecovery{keys, charset, charset}
: SixCharactersRecovery{keys, charset}
, charset{charset}
, solutions{solutions}
, solutionsMutex{solutionsMutex}
Expand Down

0 comments on commit 446f2c1

Please sign in to comment.