Thread: SecureOverwrite
View Single Post
Old May 17th, 2006, 6:39 PM   #1
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 4 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
SecureOverwrite

Hi all. I wrote this program to see if it would really work, and to see how useful it might be. It's a SecureOverwrite program, that takes a file path and overwrites it with random numbers, and then deletes the file. Comments and suggestions on how I might improve the program are welcome. The algorithm for the overwrite method is very simple right now, so any ideas on how I might make it better are welcome. This was compiled without error or warning in Dev-C++.
#include <iostream>
#include <fstream>
#include "KillProcess.cpp"
using namespace std;

int OhNo(string Horrors)
{
    cerr << Horrors << endl;
    return 1;
}

int main()
{
    char fileName[255];
    cout << "Enter file to be securely removed: ";
    cin.getline(fileName,255);
    
    int number = 0; int number2 = 0; int number3 = 0; int number4 = 0; int number5 = 0;
    int number6 = 0; int number7 = 0; int number8 = 0; int number9 = 0; int number10 = 0;
    
    ifstream fin(fileName);
    if (fin)
    {
       cout << "File found." << endl;
       cout << "Now ending process if running..." << endl;
       KillProcess(fileName);
       
       int times, theLimit;
       cout << "Enter times to securely overwrite: ";
       cin >> times;
       if ( !cin.good() ) return OhNo("Error: bad input");
       
       // Overwrite method: Erases all data in file, writes random number. Does this as much as specified.
       for (theLimit = 1; theLimit <= times; theLimit++)
       {
           ofstream fout(fileName);
           number = rand(); number2 = rand(); number3 = rand(); number4 = rand(); number5 = rand();
           number6 = rand(); number7 = rand(); number8 = rand(); number9 = rand(); number10 = rand();
           
           fout << number << number2 << number3 << number4 << number5
           << number7 << number8 << number9 << number10;
           
           fout.close();
           cout << "*";
       }
       
       cout << "\nFile was overwritten " << theLimit << " times." << endl;
       cout << "Now removing file..." << endl;
       fin.close();
       int check = remove(fileName);
       
       if ( check == 0 ) { cout << "Success." << endl; }
       if ( check != 0 ) { cout << "Failure to remove file." << endl; }
    }
    else
    {
        cout << "File not found" << endl;
    }
    cin.sync();
    cin.get();
    return 0;
}

You can find the KillProcess() code here. Thanks to the dude that wrote this.

I didn't comment much, because the code is fairly easy to read (IMO, I might change it anyways). Thanks for your comments and suggestions.
__________________
The world's first athletic computer geek!
The home of PrProgramsStudios
How not to post a question: <-- Please don't reply
Prm753 is offline   Reply With Quote