#include <iostream>
#include <fstream>
using namespace std;
int clean(int i, int j, int max) {
int z = 0;
ifstream in("corrupted.png.bz2", ios::in | ios::binary);
ofstream out("foo.png.bz2", ios::out | ios::binary);
char p, n;
in.read(&p,1);
while (in.read(&n,1)) {
if (n != '\n' || p != '\r') {
out.write(&p,1);
}
else {
if (z == i || z == j) out.write(&p,1);
z++;
}
p = n;
}
out.write(&p,1);
out.close();
system("bunzip2 foo.png.bz2");
system("rm foo.png.bz2");
in.close();
}
int count() {
int l = 0;
ifstream in("corrupted.png.bz2", ios::in | ios::binary);
char p, n;
in.read(&p,1);
while (in.read(&n,1)) {
if (n == '\n' && p == '\r') {
l++;
}
p = n;
}
in.close();
return l;
}
int main() {
int max = count();
cout << "Change zip to work with: " << max << endl;
for (int i = 0; i < max; i++) {
for (int j = 0; j <= i; j++) {
clean(i,j,max);
}
}
}