Thanks for the reply, and sure i'll make it more clear and post my code. My assignment is a weird version of a caesar encryption.
1) Read text file that contains 2 lines, each line into a different array.
- the first line is a 'key' which can be anywhere from 1-6 characters, the second line is the message to be encrypted, and the message can be anywhere from 1-60 characters.
2) create a "block" that's width is the size of the key.
3) arrange message into that block and based on each column header, encrypt the letter.
textfile contents:
CATS
I LOVE CATS & DOGS
array1 should output "CATS"
array2 should output "ILOVECATSDOGS" (as you can see, I'm supposed to read the file contents as separate characters and strip out any white spaces or anything that's not between capital A-Z)
message block should look like:
C A T S
----------
I L O V
E C A T
S D O G
S
- then somehow take each letter in each column and encrypt it. For example.
'I' becomes 'K'. This is because using an ASCII chart 'C' - 'A' = 2 so shift all the letters under C by 2.
-Anything in the second column won't shift 'A' - 'A' = 0. Third columns letters will shift by 19 letters 'T' - 'A' = 19, and 4th column will shift by 18 'S' - 'A' = 18.
-After encryption, print out the encrypted message to the screen.
I am struggling to even start. I have only been learning c++ for a week so pardon me for my idiocy, I don't know if this is too advanced of an assignment , and I'm a slow learner. I haven't learned about vectors, and was told not to use the string class but use cstring instead. So far I ask the user to input their filename (so anyone can test any file with the program). Now I'm trying to read in the contents of the textfile.
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
|
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
void openFile();
void readText();
ifstream encryptionFile;
int main() {
openFile();
readText();
encryptionFile.close();
return 0;
}
void openFile() {
char fileName[25];
cout << "Enter name of file you would like to encrypt " << endl;
cin >> fileName;
encryptionFile.open(fileName);
if (!encryptionFile.is_open()) {
cout << "File failed to open" << endl;
}
else{
cout << "File successfully opened!" << endl;
}
}
void readText(){ /*this function does not do what I want it to,
which is read char by char. It has
to be open ended because line one
can be 1-6 characters, and line 2 can
be 1-60 characters*/
int i;
char lineOne[i];
char lineTwo[i];
for (i = 0; i <= 5; i++){
encryptionFile >> lineOne[i];
cout << lineOne[i] << endl;
}
for (i = 0; i <= 59; i++){
encryptionFile >> lineTwo[i];
cout << lineTwo[i] << endl;
}
}
|
I appreciate any reply, hint/help.