Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <chrono>
- #include "key.h"
- #include <map>
- #include <vector>
- #include <cmath>
- using namespace std;
- int main(int argc, char* argv[]) {
- if (argc != 2) {
- cout << "Usage:" << endl;
- cout << argv[0] << " <hashed password> < rand8.txt" << endl;
- return 1;
- }
- // Hashed password.
- Key hashed{argv[1]};
- Key zero{};
- // Table.
- Key table[N];
- // Unordered map containing combinations of floor of size of byte/2
- //map<size_t,Key> decrypt;
- map<Key, Key> decrypt;
- // Read table.
- for (int i{0}; i < N; i++) {
- char buffer[C + 1];
- if (scanf("%s", buffer) != 1) {
- cerr << "Too short table!" << endl;
- return 1;
- }
- table[i] = Key{buffer};
- }
- auto begin = chrono::high_resolution_clock::now();
- // Find all possible passwords that hash to 'hashed' and print them.
- // Put all combinations of encrypted lower half in map decrypt.
- Key candidate{};
- do {
- Key enc = subset_sum(candidate, table); //kryptera candidate
- decrypt[hashed-enc] = candidate;
- ++candidate;
- } while (!candidate.bit(N/2));
- Key higher_half{candidate};
- // higher_half= candidate;
- do{
- auto iterator = decrypt.find(subset_sum(higher_half, table));
- if (iterator != decrypt.end())
- cout << higher_half + iterator->second << endl;
- higher_half+= candidate;
- } while(higher_half != zero );
- auto end = chrono::high_resolution_clock::now();
- cout << "Decryption took "
- << std::chrono::duration_cast<chrono::seconds>(end - begin).count()
- << " seconds." << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement