-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseFile.cpp
More file actions
111 lines (65 loc) · 3.11 KB
/
parseFile.cpp
File metadata and controls
111 lines (65 loc) · 3.11 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// parseFile.cpp - Parses file
#include "passwordNarrower.hpp"
#include "modifiers.hpp"
#include "stringops.hpp"
#include <fstream>
#include <string>
void PasswordNarrower::parseFile() {
std::ifstream i; // input file
std::ofstream o; // output file
// opens files
i.open(input.c_str());
o.open(output.c_str());
std::string temp; // variable where string is stored before adding to file
if (getArgVal(Modifiers::Password)) // initializes password-based narrowing
passwordInit();
int tempPwCount = 0; // If using password-based narrowing, this variable counts how many characters are
// similar.
while (i >> temp) { // Repeats until there is no more data in the input file
tempPwCount = 0;
if (temp.length() == length && getArgVal(Modifiers::Length)) { // If doing a precise length search
if (getArgVal(Modifiers::NumsOnly) && !hasChars(temp) && hasNums(temp)) // If searching for number passwords
o << temp << std::endl;
else if (getArgVal(Modifiers::CharsOnly) && !hasNums(temp)) // if searching for character passwords
o << temp << std::endl;
else if (getArgVal(Modifiers::UpperOnly) && !hasLower(temp) && !hasNums(temp)) // if searching for uppercase passwords
o << temp << std::endl;
else if (getArgVal(Modifiers::LowerOnly) && !hasUpper(temp) && !hasNums(temp)) // if searching for lowercase passwords
o << temp << std::endl;
else if (!getArgVal(Modifiers::CharsOnly) && !getArgVal(Modifiers::NumsOnly) && !getArgVal(Modifiers::UpperOnly) && !getArgVal(Modifiers::LowerOnly)) // if no cli options were given
o << temp << std::endl;
}
else if (temp.length() <= maxLength && temp.length() >= minLength && !getArgVal(Modifiers::Length)) {
if (!getArgVal(Modifiers::Password)) { // If not doing a password-based search
if (getArgVal(Modifiers::NumsOnly) && !hasChars(temp) && hasNums(temp))
o << temp << std::endl;
else if (getArgVal(Modifiers::CharsOnly) && !hasNums(temp))
o << temp << std::endl;
else if (getArgVal(Modifiers::UpperOnly) && !hasLower(temp) && !hasNums(temp))
o << temp << std::endl;
else if (getArgVal(Modifiers::LowerOnly) && !hasUpper(temp) && !hasNums(temp))
o << temp << std::endl;
else if (!getArgVal(Modifiers::CharsOnly) && !getArgVal(Modifiers::NumsOnly) && !getArgVal(Modifiers::UpperOnly) && !getArgVal(Modifiers::LowerOnly))
o << temp << std::endl;
}
else {
if (tempPass.length() == temp.length()) { // If specified password length and input length are the same
for (int x = 0; x < tempPass.length(); x++) { // Checks to see how many characters are similar
if (tempPass[x] != '*' && tempPass[x] == temp[x])
tempPwCount++;
}
if (tempPwCount == pwCount) { // If an equal number of known characters are similar
if (getArgVal(Modifiers::NumsOnly) && !hasChars(temp) && hasNums(temp))
o << temp << std::endl;
else if (getArgVal(Modifiers::CharsOnly) && !hasNums(temp))
o << temp << std::endl;
else if (!getArgVal(Modifiers::CharsOnly) && !getArgVal(Modifiers::NumsOnly))
o << temp << std::endl;
}
}
}
}
}
i.close();
o.close();
}