Skip to content

Commit 5e2be77

Browse files
committed
added unprotected flag checker
1 parent 3f51b52 commit 5e2be77

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
all:
22
clang++ -o check_flag check_flag.cpp CustomVM.cpp
33
strip check_flag
4-
release:
4+
release-protected:
55
clang++ -O3 -o check_flag check_flag.cpp CustomVM.cpp
6-
strip check_flag
6+
strip check_flag
7+
release-unprotected:
8+
clang++ -o unprotected_check_flag unprotected_check_flag.cpp

README.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +0,0 @@
1-
// Get substring from 'for(' to ';'
2-
// Trim to check if it is empty
3-
for(; ...)
4-
for( ; ...)
5-
6-
// find if first 4 characters are "int "
7-
1. From "int " to ";" take a substring
8-
2. Trim all whitespaces
9-
3. Variable: substring from 0 to =
10-
4. Initial value of that variable: substring from '=' + 1 till end
11-
12-
for(int i = 0; ...)
13-
for(int i=0; ...)
14-
15-
// First 4 characters are not 'int ' and first character is not a semicolon - variable was declared earlier
16-
for(i = 0; ...)
17-
for(i=0; ...)
18-
19-
for(int i = 0 ; ...)
20-
for(int i=0 ; ...)
21-
for(i = 0 ; ...)
22-
for(i=0 ; ...)

unprotected_check_flag.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main() {
6+
char* input = (char *)malloc(100);
7+
cout << endl << "************************************************** Welcome to my flag checker program! **************************************************" << endl;
8+
cout << endl;
9+
cout << "All you need to do is enter a flag. If it is a valid flag, I will be very happy!!! :)" << endl;
10+
cout << endl << "Please enter your flag now: ";
11+
cin >> input;
12+
13+
vector<int> flagValues({100, 50, 0, 190, 20, 210, 90, 60, 190, 0, 30, 60, 0, 210, 190, 20, 230, 60, 130, 100, 150, 80});
14+
int i;
15+
16+
for(i = 0; i < 22; i++) {
17+
int flagValue = (int)input[i];
18+
flagValue -= 95;
19+
flagValue *= 10;
20+
if(flagValue != flagValues[i]) {
21+
cout << endl << "Hmmm, sorry, that's an invalid flag. Please try again!";
22+
break;
23+
}
24+
}
25+
26+
if(i == 22) {
27+
cout << endl << "Congratulations, that's a valid flag!!!";
28+
}
29+
}

0 commit comments

Comments
 (0)