Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
goelp14
GitHub Repository: goelp14/easyctf-iv-problems
Path: blob/master/soupifier/source.cpp
671 views
1
#include "stdio.h"
2
#include "math.h"
3
#include <iostream>
4
#include <stdexcept>
5
using namespace std;
6
7
void print_error(){
8
//STUB
9
/*ifstream reader;
10
reader.open("flag.txt");
11
char output[100];
12
if (reader.is_open()) {
13
while (!reader.eof()) {
14
reader >> output;
15
cout<<output;
16
}
17
printf("\n");
18
}
19
reader.close();
20
*/
21
printf("hi\n");
22
}
23
bool soupify_string_successful(string input, short* ret, int counter)
24
{
25
counter++;
26
int upper = input.length();
27
if(upper > 500)
28
upper = 500;
29
for(int i = 0; i < upper; i++){
30
if(*ret < 0) return false;
31
*ret += (short)(input.at(i));
32
}
33
input = "";
34
cout<<"Input another string! ";
35
cin>>input;
36
if(counter == 3){
37
printf("Now soupifying! \n");
38
return true;
39
}
40
return soupify_string_successful(input, ret, counter);
41
}
42
int main()
43
{
44
string input = ""; //really bad mix of C and C++?
45
printf("Welcome to the Souper Magic Soup Number Generator! Input your string: ");
46
cin>>input;
47
short start = 4;
48
short* short_ptr = &start;
49
if(soupify_string_successful(input, short_ptr, 0)){
50
if(sqrt(*short_ptr) > 0){
51
cout<<"\nYour soup number is: "<<sqrt(*short_ptr)<<".\n";
52
return 0;
53
}
54
else{
55
print_error();
56
}
57
}
58
else{
59
printf("Soupify failed!\n");
60
}
61
return 0;
62
}
63
64