-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
71 lines (60 loc) · 2.12 KB
/
Main.cpp
File metadata and controls
71 lines (60 loc) · 2.12 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
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <sstream>
#include <tuple>
using namespace std;
int main()
{
vector<string> encryptedPasswords = { "fksjfld", "kdsjfl", "@ioihdsio8", "ua8fdhvi!" };
for (auto str : encryptedPasswords) {
//summing all the characters
int sum = 0;
for (int i = 0; i < str.length(); i++) {
char x = str.at(i);
sum += int(x);
}
cout << "Sum: " << sum << endl;
//doing the 3 multiples
string strSum = to_string(sum);
string threeSum = "";
for (int i = 0; i < 3; i++) {
for (int j = 0; j < strSum.length() - 1; j++) {
threeSum += strSum.substr(j, j + 1);
}
}
cout << "Three Sum: " << threeSum << endl;
//convert the three sum to hexstring
//first convert string back to an integer
int hexInt = stoi(threeSum);
cout << "Is this right: " << hexInt << endl;
//next convert integer to hexstring
stringstream stream;
stream << hex << hexInt;
string hexResult(stream.str());
cout << "Is this a string: " << hexResult << endl;
//take the fist 6 characters and break it up into the
tuple<unsigned int, unsigned int, unsigned int> rgb;
//red
unsigned int red = 0;
istringstream r(hexResult.substr(0, 2));
r >> hex >> red;
cout << "This is red hex couple: " << hexResult.substr(0, 2) << endl;
//green
unsigned int green = 0;
istringstream g(hexResult.substr(2, 2));
g >> hex >> green;
cout << "This is green hex couple: " << hexResult.substr(2, 2) << endl;
//blue
unsigned int blue = 0;
istringstream b(hexResult.substr(4, 4).substr(0, 2));
b >> hex >> blue;
cout << "This is blue hex couple: " << hexResult.substr(4, 4).substr(0, 2) << endl;
rgb = make_tuple(red, green, blue);
cout << std::get<0>(rgb)
<< " " << std::get<1>(rgb)
<< " " << std::get<2>(rgb)
<< std::endl;
}
}