question on pointers & functions

Greetings.

I'm working on a program to Encrypt/Decrypt/Crack Vigenere Ciphers.
So far I am up to the determining the key length of a cipher in the Crack function.
I want to re-use parts of the code related to file/string handling for the Encrypt/Decrypt functions.

The flow is Menu calls cleanup, cleanup calls concatenate, concatenate calls get_input (string or filename), then depending which function you are in you encrypt and write to disk, decrypt and write to disk or crack and write to disk.

Can anyone point me at a tutorial on using pointers in this way?

The code I have is below, please pardon the mess, it's been a learning curve for me, I am still on Chapter 2 of Thinking in C++.

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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <iostream>
#include <string>
#include <fstream>
#include <vector>

using namespace std;

// Prototypes
void function_1();
void function_2();
void function_3();
char load_data();

int main (){
    bool quit = false;
    while(quit == false) {
        cout << "\n"
            "1) Function 1\n"
            "2) Function 2\n"
            "3) Function 3\n"
            "q) Quit\n"
            "Select a Menu Option :";
        char selection;
        cin >> selection;
        switch(selection){
            case '1': function_1(); break;
            case '2': function_2(); break;
            case '3': function_3(); break;
            case 'q': quit = true;  break;
            default : cout << "\n" << "try again" << "\n";
        }
     }
return 0;
}


void function_1(){
    cout << "This is Function 1, calling load_data()" << endl;
    load_data();
}

void function_2(){
    int number; 
    cout << "This is Function 2" << endl;
}

void function_3(){
    cout << "This is Function 3" << endl;
}

char load_data(){

    char filename[20];
    ifstream data_in;
    vector<string> words;
    string word;
    string data_conc;
    string data_alpha;

        cout << "Filename: " ;
        cin.ignore();
        cin.getline (filename,20); // get the filename from the user
        data_in.open (filename);  //open the file
        if(!data_in.is_open()){ // check to make sure it's open
           cout << "\n" << "Error opening file." << "\n" << endl;
           exit(0); // if not open, exit
        }
        else{
           cout << "\n" << "File read success." << "\n" << endl;
        }
        while(data_in >> word) // until we reach the end
           words.push_back(word); // push the file into memory word by word
        for(int i = 0; i < words.size(); i++){ // until we reach the end
           data_conc += words[i]; // clear out the whitespace
        }
        int i = 0;
        for (i = 0; data_conc[i]; i++){ // until we reach the end
           if(isalpha(data_conc[i])){ // check to see if char is alpha
              data_conc[i] = toupper(data_conc[i]); // if it is convert to upper
              data_alpha += data_conc[i]; // and put it in a new string
            }
        }
/*----------------------------------------------------------------------------*/
// Calculate Key Length


    int k=1;
    int num_shifts=26;
    float index=0;
    int key_len;
        for(k = 1; k < num_shifts; k++){
            int l = 0;
            int shift=k;
            float matches=0;
                for(l = 0; data_alpha[l + shift]; l++){
                    if(data_alpha[l] == data_alpha[l + shift]){
                        matches++;
                    }
                }
            index=(100 * matches / l);
               
            if (index >= 6) {break;}
    }
key_len=k;
cout << "Probable Key Length: " << key_len << endl;
/*----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------*/
// Calculate Key Characters
/*
float en_std_dist[] = {8.12, 1.49, 2.71, 4.32, 12.02, 2.30, 2.03, 5.92, 7.31,
0.10, 0.69, 3.98, 2.61, 6.95, 7.68, 1.82, 0.11, 6.02, 6.28, 9.10, 2.88, 1.11,
2.09, 0.17, 2.11, 0.07};

int key_pos;
float char_dev;
int z=0;


    for(z = 0; z < 26; z++) {
          
        
        
    }
*/
return 0;
}




/* The standard distribution of french letters. */
float fr_std_dist[] = {};

/* The standard distribution of german letters. */
float gr_std_dist[] = {};

/* The standard distribution of italian letters. */
float it_std_dist[] = {};
Topic archived. No new replies allowed.