forked from p4-team/ctf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsharp_v4_f8d0_8096
100 lines (79 loc) · 1.84 KB
/
sharp_v4_f8d0_8096
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
#include <iostream>
#include <string>
#include <algorithm>
#include <stdint.h>
#include <stdio.h>
#include <openssl/sha.h>
using namespace std;
std::string calculate_flag(
std::string &part1,
int64_t part2,
std::string &part4,
uint64_t factor1,
uint64_t factor2)
{
std::transform(part1.begin(), part1.end(), part1.begin(), ::tolower);
std::transform(part4.begin(), part4.end(), part4.begin(), ::tolower);
SHA_CTX ctx;
SHA1_Init(&ctx);
unsigned int mod = factor1 % factor2;
for (unsigned int i = 0; i < mod; i+=2)
{
SHA1_Update(&ctx,
reinterpret_cast<const unsigned char *>(part1.c_str()),
part1.size());
}
while (part2-- > 0)
{
SHA1_Update(&ctx,
reinterpret_cast<const unsigned char *>(part4.c_str()),
part1.size());
}
unsigned char *hash = new unsigned char[SHA_DIGEST_LENGTH];
SHA1_Final(hash, &ctx);
std::string rv;
for (unsigned int i = 0; i < SHA_DIGEST_LENGTH; i++)
{
char *buf;
asprintf(&buf, "%02x", hash[i]);
rv += buf;
free(buf);
}
return rv;
}
int main(int argc, char **argv)
{
(void)argc; (void)argv; //unused
std::string part1;
cout << "Part1: Enter flag:" << endl;
cin >> part1;
int64_t part2;
cout << "Part2: Input 31337:" << endl;
cin >> part2;
std::string part3;
cout << "Part3: Watch this: https://www.youtube.com/watch?v=PBwAxmrE194" << endl;
cin >> part3;
std::string part4;
cout << "Part4: C.R.E.A.M. Get da _____: " << endl;
cin >> part4;
uint64_t first, second;
cout << "Part5: Input the two prime factors of the number 272031727027." << endl;
cin >> first;
cin >> second;
uint64_t factor1, factor2;
if (first < second)
{
factor1 = first;
factor2 = second;
}
else
{
factor1 = second;
factor2 = first;
}
std::string flag = calculate_flag(part1, part2, part4, factor1, factor2);
cout << "flag{";
cout << &lag;
cout << "}" << endl;
return 0;
}