forked from PawanJaiswal08/leetcode-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhack.cpp
More file actions
39 lines (29 loc) · 740 Bytes
/
hack.cpp
File metadata and controls
39 lines (29 loc) · 740 Bytes
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
// Implementation of the code in C++
#include <bits/stdc++.h>
using namespace std;
int main()
{
// Hex String variable
string hex_s = "653cae8da8edb426052";
// Plain text variable
string plain = "";
// variable to store the XOR
// of previous digits
int x = 0;
int l = hex_s.length();
// Loop for loop from the end to
// the mid section of the string
for (int i = l - 1; i > (l / 2) - 1; i--) {
string digit = "";
digit += hex_s[i];
// calculation of the plaintext digit
unsigned int y = x ^ stoul(digit, nullptr, 16);
// calculation of XOR chain
x = x ^ y;
stringstream sstream;
sstream << hex << y;
string z = sstream.str();
plain = z[z.length() - 1] + plain;
}
cout << plain;
}