mirror of
https://github.com/kwsch/pkNX.git
synced 2026-10-02 14:16:55 -05:00
Fix bugs + make it working
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "HashDecoder.h"
|
||||
#include "Timer.h"
|
||||
#include <unordered_set>
|
||||
|
||||
using namespace pkNXHashDecoder;
|
||||
|
||||
@@ -19,6 +20,10 @@ std::unordered_map<uint64_t, std::string> FnvHashDecoder::StartDecoding(const in
|
||||
{
|
||||
std::unordered_map<uint64_t, std::string> foundKeys;
|
||||
|
||||
std::unordered_set<uint64_t> HashesToLookFor{
|
||||
0xC75DDBE25402B11C,
|
||||
};
|
||||
|
||||
// Reset all chars to starting point
|
||||
charIndex[0] = (uint32_t)startChar;
|
||||
|
||||
@@ -26,7 +31,7 @@ std::unordered_map<uint64_t, std::string> FnvHashDecoder::StartDecoding(const in
|
||||
hashBases[0] = kOffsetBasis_64;
|
||||
for (int i = 0; i < length - 1; ++i)
|
||||
{
|
||||
hashBases[i] ^= AllowedChars[0];
|
||||
hashBases[i] ^= AllowedChars[charIndex[i]];
|
||||
hashBases[i] *= kFnvPrime_64;
|
||||
|
||||
// Move the hash to the next index as basis
|
||||
@@ -44,7 +49,7 @@ std::unordered_map<uint64_t, std::string> FnvHashDecoder::StartDecoding(const in
|
||||
hash ^= AllowedChars[i];
|
||||
hash *= kFnvPrime_64;
|
||||
|
||||
if (hash == 9252365659083253459ul)
|
||||
if (HashesToLookFor.find(hash) != HashesToLookFor.end())
|
||||
{
|
||||
charIndex[length - 1] = i;
|
||||
foundKeys.emplace(hash, BuildString(length));
|
||||
@@ -83,9 +88,9 @@ std::unordered_map<uint64_t, std::string> FnvHashDecoder::StartDecoding(const in
|
||||
hashBases[i + 1] = hashBases[i];
|
||||
|
||||
// Automatically test for shorter length strings
|
||||
if (hashBases[i] == 9252365659083253459ul)
|
||||
if (HashesToLookFor.find(hashBases[i]) != HashesToLookFor.end())
|
||||
{
|
||||
foundKeys.emplace(hashBases[i], BuildString(i));
|
||||
foundKeys.emplace(hashBases[i], BuildString(i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,17 +7,17 @@ namespace pkNXHashDecoder {
|
||||
public:
|
||||
std::unordered_map<uint64_t, std::string> StartDecoding(int length, int startChar);
|
||||
|
||||
private:
|
||||
constexpr static int MAX_LENGTH = 128;
|
||||
constexpr static std::string_view AllowedChars = "etaoinshrdlcumw_0123456789fgypbvkjxqz/."; // Sorted by most common first
|
||||
constexpr static size_t AllowedCharsCount = AllowedChars.size();
|
||||
|
||||
private:
|
||||
std::string BuildString(size_t length) const;
|
||||
|
||||
constexpr static uint64_t kFnvPrime_64 = 0x00000100000001b3;
|
||||
constexpr static uint64_t kOffsetBasis_64 = 0xCBF29CE484222645;
|
||||
|
||||
std::array<uint32_t, MAX_LENGTH> charIndex{}; // Current AllowedChar index
|
||||
std::array<uint64_t, MAX_LENGTH> hashBases{}; // Current AllowedChar index
|
||||
|
||||
std::string BuildString(size_t length) const;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user