-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (72 loc) · 3.65 KB
/
main.cpp
File metadata and controls
80 lines (72 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// Created by allietiv on 4/15/2025.
//
#include <iostream>
#include <vector>
#include "PasswordProcessor.h"
#include "HashMap_Analyzer.h"
#include "Heap_Analyzer.h"
#include <chrono>
using namespace std;
int main() {
//retrieving the file of passwords
//not absolute path-- may need to be altered depending on who is running it
string filename = "/Rocco-Stephanie-Allie-Project3/passwords.txt";
cout << "Reading passwords from file...\n" << endl;
//checking to ensure the file was accurately accessed and processed
vector<int> lengths = PasswordProcessor::getPasswordLengths(filename);
if (lengths.empty()) {
cerr << "Error: Password lengths vector is empty, make sure file is unzipped and loaded in properly" << endl;
return 1;
}
//analysis of the most common password lengths via hash mapping
//using time to compare hash mapping to heapifying the list to see what is more efficient
cout << "Analysis uses the Hash Map approach: " << endl;
auto start_hash = chrono::high_resolution_clock::now();
int most_common_hash = HashMapAnalyzer::getMostCommonLength(lengths);
auto end_hash = chrono::high_resolution_clock::now();
chrono::duration<double> duration_hash = end_hash - start_hash;
cout << "Most common password length: " << most_common_hash << endl;
cout << "Time taken to process: " << duration_hash.count() << " seconds\n\n";
//analysis of the most common password lengths via heapifying
//using time to compare heapifying to hash mapping the list to see what is more efficient
cout << "Analysis uses the Heap approach: " << endl;
auto start_heap = chrono::high_resolution_clock::now();
int most_common_heap = HeapAnalyzer::getMostCommonLength(lengths);
auto end_heap = chrono::high_resolution_clock::now();
chrono::duration<double> duration_heap = end_heap - start_heap;
cout << "Most common password length (Heap): " << most_common_heap << endl;
cout << "Time taken: " << duration_heap.count() << " seconds\n\n";
//checking to ensure that both methods give the same results
if (most_common_hash==most_common_heap) {
int most_common_length=most_common_hash;
cout << "The analysis of both data structures matches. This confirms " << most_common_length << "'s accuracy" << endl;
//compaing the time it took for both of them to execute to see which is better
//hash mapping should be more efficient, every so often heap will be quicker
if (duration_heap > duration_hash) {
cout << "Hashing has quicker time complexity with this problem.\n" << endl;
}
else if (duration_hash > duration_heap) {
cout << "Heaping has quicker time complexity with this problem.\n" << endl;
}
else {
cout << "Both hashing and heaping had the same time complexity with this problem.\n" << endl;
}
}
//comparing the user's password to the found results
string user_password;
cout << "Enter your password: ";
cin >> user_password;
//giving feedback to the user depending on the outcome of the comparison (either make longer or good)
if (user_password.length() == most_common_hash) {
cout << "That password length is the same as the most common one. Consider making it longer for security.\n";
}
else if (user_password.length() < most_common_hash) {
cout << "That password length is shorter than the most common one. Consider making it more than " << most_common_hash << " characters for security." << endl;
}
else {
cout << "Your password length is greater than the most common one. Good!\n";
}
//exit the program
return 0;
}