Created
March 14, 2019 19:33
-
-
Save ecomaikgolf/3486906406125da144396f04d0ec03e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <time.h> | |
#include <algorithm> | |
#include <random> | |
#include <string.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <thread> | |
#include <chrono> | |
#include <vector> | |
using namespace std; | |
const int MTEXT = 25; | |
const int MINCONT = 100; | |
const int SHIPCONT = 5; | |
const int SHIPWEIGHT = 500; | |
int main(){ | |
system("rm ./datos-entrada/fuzztest.txt"); | |
system("rm ./salida-correcta-esperada/fuzztest.salida-correcta-esperada"); | |
system("touch ./datos-entrada/fuzztest.txt"); | |
system("rm prac1"); | |
ifstream corrector("prac1"); | |
if(!corrector.good()){ | |
system("wget https://www.dlsi.ua.es//asignaturas/p2/downloads/1819/practicas/pr1/prac1 --quiet -O prac1 > /dev/null"); | |
cout << "[!] Introduce la contrasenya para hacer chmod" << endl; | |
system("sudo chmod +x prac1"); | |
} | |
corrector.close(); | |
//std::this_thread::sleep_for(std::chrono::seconds(3)); | |
ofstream of("./datos-entrada/fuzztest.txt"); | |
if(!of.is_open()) return -1; | |
srand(time(NULL)); | |
int iteraciones; | |
cout << "[-] Introduce el numero de iteraciones: "; | |
cin >> iteraciones; | |
vector<string> nombres; | |
for(int i = 0 ; i < iteraciones; i++){ | |
int randValue = rand()%10; | |
switch(randValue){ | |
case 1: | |
{ | |
of << 1 << '\n'; | |
break; | |
} | |
case 2: | |
{ | |
of << 2 << '\n'; | |
int weight = rand()%1000; | |
of << weight << '\n'; | |
if(weight >= MINCONT){ | |
of << rand()%10000 << '\n'; | |
} | |
break; | |
} | |
case 3: | |
{ | |
of << 3 << '\n'; | |
of << rand()%100 << '\n'; | |
break; | |
} | |
case 4: | |
{ | |
of << 4 << '\n'; | |
string name = ""; | |
for(int i = 0; i < MTEXT;i++){ | |
name += 'A' + rand()%26; | |
} | |
of << name << '\n'; | |
if(find(nombres.begin(),nombres.end(),name) == nombres.end()) break; | |
nombres.push_back(name); | |
int ncont = rand()%100; | |
if(ncont >= SHIPCONT){ | |
of << ncont << '\n'; | |
of << rand()%10000 << '\n'; | |
} | |
break; | |
} | |
case 5: | |
{ | |
if(nombres.size() != 0){ | |
of << 5 << '\n'; | |
int nrand = rand()%nombres.size(); | |
of << nombres[nrand] << '\n'; | |
nombres.erase(nombres.begin()+nrand); | |
}else{ | |
of << 5 << '\n'; | |
string name = ""; | |
for(int i = 0; i < MTEXT;i++){ | |
name += 'A' + rand()%26; | |
} | |
of << name << '\n'; | |
} | |
break; | |
} | |
case 6: | |
break; | |
case 7: | |
{ | |
of << 7 << '\n'; | |
break; | |
} | |
} | |
} | |
of << 1 << '\n'; | |
of << 'q' << '\n'; | |
of.close(); | |
cout << "[-] Ya se ha generado la prueba" << endl; | |
cout << "[-] Vamos a generar el archivo correcto de salida" << endl; | |
system("./prac1 < datos-entrada/fuzztest.txt > salida-correcta-esperada/fuzztest.salida-correcta-esperada"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment