Sovereignty is Mine
#include#include #include #include #include #include #include #include using namespace std; using u32 = uint32_t; using u16 = uint16_t; constexpr int BDAY_HASH_BITS = 20; constexpr int SAMPLE_LEN = 7; constexpr size_t BDAY_LIMIT = 1u << 14; constexpr int KEY_BITS = 16; constexpr size_t KEYSPACE = (1u << KEY_BITS); u32 double_encrypt(u16 key1, u16 key2, const string& sample); int main() { srand(static_cast (time(nullptr))); while (true) { u16 key1 = rand() & 0xFFFF; u16 key2 = rand() & 0xFFFF; unordered_map > hash_map; for (size_t i = 0; i < BDAY_LIMIT; ++i) { string sample; for (int j = 0; j < SAMPLE_LEN; ++j) sample += 'A' + (rand() % 26); u32 enc_hash = double_encrypt(key1, key2, sample); hash_map[enc_hash].push_back(sample); } for (const auto& [hash, samples] : hash_map) if (samples.size() > 1) { cout << "Eryday my Birthday paradox: " << hex << setw(4) << setfill('0') << key1 << " " << setw(4) << key2 << dec << endl; for (const string& s : samples) cout << " Sample: " << s << endl; return 0; } } } u32 double_encrypt(u16 key1, u16 key2, const string& sample) { u32 hash = 0; for (char c : sample) hash = (hash * 31 + c) ^ key1; hash ^= key2; return hash & ((1u << BDAY_HASH_BITS) - 1); }