Please help with my program

Im making a file destroyer and i need some help because im a little stumped. I want the program to find ever letter in the lowercase array and replace each letter with a random symbol. each time the program runs it should randomly choose a symbole for each letter. but i cant figure that part out.

code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <ctime>

using namespace std;

void destroy()
{
    string fileName;
    string hold_text;
    int position = string::npos;
    ifstream fileIn;
    ofstream fileOut;
    int random;

    time_t T;
    time(&T);
    srand(T);

    for(int i = 0; i < 26; i++)
    {
        random = rand() % 26;
    }

    char lowercase[27] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\0'};
    char symbol_set_one[27] = {'¡','¢','£','¤','¥','¦','§','¨','©','ª','«','¬','¯','°','±','²','³','´','µ','¶','·','¸','º','»','¼','½','\0'};

    cout << "What is the name of the file you want to destroy?" << endl;
    getline(cin, fileName);

    fileIn.open(fileName.c_str());

    stringstream ss(stringstream::in | stringstream::out | stringstream::app);

    while(getline(fileIn, hold_text))
    {
        ss << hold_text << endl;
    }

    hold_text = ss.str();

    for(int i = 0; i < 27; i++)
    {
        while((position = hold_text.find(lowercase[i])) != string::npos)
        {

        }
    }

}

int main()
{
    int choice;

    cout << "Welcome to File Destroyer\n" << endl;
    cout << "1) Destroy Files" << endl;
    cout << "2) Exit Program" << endl;

    if(choice == 1)
    {
        destroy();
    }
    if(choice == 2)
    {
        return 0;
    }
}

 
Last edited on
would you please tell me what's the purpose of
1
2
3
4
for(int i = 0; i < 26; i++)
{
        random = rand() % 26;
}


This should be like this
1
2
3
4
5
for(int i = 0; i < 26; i++)
{
        random = rand() % 26;
        lowercase[i] = symbol_set_one[random];
}
Last edited on
ok now do i need to put it in this for loop to replace stuff? or is it all already being replaced?

1
2
3
4
5
6
7
for(int i = 0; i < 27; i++)
    {
        while((position = hold_text.find(lowercase[i])) != string::npos)
        {

        }
    }
no you don't need this..it's already replaced...
Its not replacing anything.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <ctime>

using namespace std;

void destroy()
{
    string fileName;
    string hold_text;
    int position = string::npos;
    ifstream fileIn;
    ofstream fileOut;
    int random;

    time_t T;
    time(&T);
    srand(T);

    cin.ignore(500, '\n');

    char lowercase[27] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\0'};
    char symbol_set_one[27] = {'¡','¢','£','¤','¥','¦','§','¨','©','ª','«','¬','¯','°','±','²','³','´','µ','¶','·','¸','º','»','¼','½','\0'};

    cout << "What is the name of the file you want to destroy?" << endl;
    getline(cin, fileName);

    fileIn.open(fileName.c_str());

    stringstream ss(stringstream::in | stringstream::out | stringstream::app);

    while(getline(fileIn, hold_text))
    {
        ss << hold_text << endl;
    }

    hold_text = ss.str();

    for(int i = 0; i < 26; i++)
    {
        random = rand() % 26;
        lowercase[i] = symbol_set_one[random];
    }

    fileOut.open(fileName.c_str());

    fileOut << hold_text << endl;

    cout << "File Destroyed" << endl;

    cout << hold_text << endl;

    cin.get();

    fileOut.close();

}

int main()
{
    int choice;

    cout << "Welcome to File Destroyer\n" << endl;
    cout << "1) Destroy Files" << endl;
    cout << "2) Exit Program" << endl;
    cin >> choice;

    if(choice == 1)
    {
        destroy();
    }
    if(choice == 2)
    {
        return 0;
    }


}
I tried this and it replaces the text with symbols but not random ones, it just cycles through the symbol array and replaces all the letters in a row with the symbols, each letter needs to have a random symbol, so if i have

abcdefg

abcdefg

the symbols for every letter is different.

1
2
3
4
5
6
7
8
9
   for(int i = 0; i < 26; i++)
    {
        random = rand() % 26;

        while((position = hold_text.find(lowercase[i])) != string::npos)
        {
            hold_text[position] = symbol_set_one[random];
        }
    }
You've changed all your lowercase array's characters to symbols (line 45), so now the loop above is looking for symbols to change into a random symbol, rather than lowercase characters.

Jim
Well i want each individual letter to be replaced with a random symbol from the array and thats where im stuck :(
This code ...
1
2
3
4
5
for(int i = 0; i < 26; i++)
    {
        random = rand() % 26;
        lowercase[i] = symbol_set_one[random];
    }


changes the characters in lowercase[] from characters, to the symbols in symbol_set_one[].

This means that this code ...
1
2
3
4
5
6
7
8
9
for(int i = 0; i < 26; i++)
    {
        random = rand() % 26;

        while((position = hold_text.find(lowercase[i])) != string::npos)
        {
            hold_text[position] = symbol_set_one[random];
        }
    }


no longer searches for lowercase characters - it searches for symbols, which is what lowercase[] now contains.

Just don't perform the first loop and the second one will still be searching for characters - it'll all be good (probably)

Cheers,
Jim
Ok i got it i just did this

1
2
3
4
5
6
7
for(int i = 0; i < 27; i++)
    {
        while((position = hold_text.find(lowercase[i])) != string::npos)
        {
            hold_text[position] = symbol_set_one[rand() % 27];
        }
    }


Now i have a question, If i use this program on, say an exe, will it make the program unrecoverable? even if forensic recovery software was able to recover it, the program is totally useless right?
bump
You've moved from the realm of C++ into the realm of operating and file systems.

There's nothing the guarantee that when you re-write the content of a file to disk it'll go to the same location on the disk; the O/S is free to create the file wherever it wants, so you can't say for sure that the original will be destroyed just by re-writing it - you may end up with the original version lying around totally intact (just unreferenced) plus the new 'destroyed' version.

If you really want to make sure it's gone, you need to perform low-level disk writing over the top of the actual file on disk, to the physical disk sectors.

Jim
But yes, assuming 'whoever' recovers the 'destroyed' copy of an exe, with the random chars in it, it'll not run.
Your two last post are fighting each other.
I vote for the first one:
If you first read a file say beginning in sector 0 of your hard disk,
nothing limits your OS to send the new file in sector 4, making your job useless. You should look into OS-specific functions like for Windows: DeviceIoControl-> http://msdn.microsoft.com/en-us/library/windows/desktop/aa363216(v=vs.85).aspx .
Your two last post are fighting each other.


My last two? Just to avoid confusion - the second one wasn't meant as a complete answer, it was just stating that an exe that has had its bytes munged won't run.

Cheers,
Jim
Uhm I don't know what to say, because in the first one you said explicitly
There's nothing the guarantee that(...)

Then you said that an recovery of a file was going to happen.

But I just got in my mind (which is kinda slow) that you assumed they recovered the edited file.
Topic archived. No new replies allowed.