I am wondering how to do some simple encrpytion for some files i have on my computer. My teacher put a file on our computers, and told us to make a program to encrpyt it so he couldn't read it when he tried to open it. I have NO expericence in C++ besides some 'Hello World' programs, but can do about everything in Python. Please help me learn how to do this. I have no code to give, and I use Microsoft Visual C++ Basic 2010.
Good encryption is very hard to do. Bad encryption is very easy.
Open the file, read in the first character, add 1 to that value, and then write it out to a new file. Keep going until all characters have been read. Bingo; data has been encrypted.
Decryption is the same, but subtract 1 from each value.
I don't get it, you said you can do this in Python, I know that Python is capable of doing this so why are you trying to do it in C++? I'm not trying to chase you away from the language but you don't seem to want to learn it to begin with.
I have a .txt file. He told us to make a program in C++ so when he opened it he hit the encryption. He also added it must be be over a 126 bit encryption.
I have a .txt file. He told us to make a program in C++ so when he opened it he hit the encryption.
Do you mean he gave you a text file, and you have to encrypt it and then give him back that encrypted file? Are we actually reading this right; that you have a file and you want to write a C++ program that will take that file and give you an encrypted version of that file?
@ OP: Can you write code that would read the entire file into memory? If so then please post it. I have a feeling that you're just discouraged at your ablility and you actually know more then you're letting on.
Open file to read from.
Open file to write to.
Read in first character.
Add one.
Write out new value to output file.
Repeat for all characters in the input file.
It's not very good encryption, but it is encryption. Once you get that working, if you want to improve the encryption, you can.
Which of these steps troubles you? We can point you towards the relevant tutorial pages.
@ OP: Moschops is right, you will get a weak form of encryption this way. It won't be 128-bit but I have a feeling that if you handed in a working program that one of us gave you you'd get called on plagerism. It's not worth it. Personally I would take the 'B-'\'C+' and move on.
#include <Python.h>
#include <string>
std::string pythonCode = """Type in here ""the python code ""to do the encryption";
int main() {
PyRun_SimpleString(pythonCode.c_str());
return 0;
}
Seriously though, you are not showing the slightest bit of effort. Why don't you write the python code for the algorithm suggested by Moschops, and we can point you to the relevant material to translate it into C++.
I have decided I will just write the encryption code in Python, and make a program to execute the module in C++. Thank you so much guys. Sorry I didn't put out enough effort. Thanks for the code kev82. I wnot using it thou that way I learn a little. Might find another way. If it can work that way. Plus, I dont know alot about encryption in Python, only like small bit. Thanks guys.
I find it more than a little odd that your teacher would ask you to implement 128bit encryption in C++ with little experience. Have you been sleeping in class?
Besides, your teacher can't tell whether the file was encrypted by a C++ program or a Python program.
It just doesn't matter, unless you have to actually send in the program as well.
@ Grey Wolf: I am the best in the class. This was a assignment that was optional, and just for the experience. He said he would give a random, crazy assignment, but also alot of time to do it in. So no, I don't sleep in class. Also, he said anything under 128bit was just as well unsecured. @Athar: I know he wouldn't, but then I wouldn't get the experience of doing it. Might as well take the expericence instead of cheating, right? Plus, I want to learn how to run a Python module from a C++ program. Thank you all for your help and advice.