| | |
Encryptor
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2007
Posts: 3
Reputation:
Solved Threads: 0
Hello to all programmers:
I have been working on the following program but I am encountering some difficulties any help whatsoever would be greatly appreciated.
My instructions are:
Write a c++ program,
1. Prompts the user for a choice of encrypt or decrypt, prompts for the input and output filenames
2. has a function for encryption
a. generates a random key
b. stores the key in the encrypted file
c. encrypts the data from the input file by performing xor of the key with every byte from the input file
3. has a function for decryption
a. reads the key from the encrypted file
b. decrypts the data from the input file by performing xor of the key wit every byte from the file
4. performs the encryption or decryption based on the user's choice.
so far I have ( Not quite sure what to do next):
#include<iostream>
#include<string>
#include<ctime>
#include<cstdlib>
#include<fstream>
usingnamespace std;
void encrypt();
void decrypt();
char option;
// char inFile;
char outFile;
int decryptencrypt;
void main()
{
srand((unsigned)time(NULL));
encrypt();
decrypt();
cout << "Enter 1 to decrypt" << endl;
cout << "Enter 2 to encrypt" << endl;
cin >> decryptencrypt;
cout << "Enter the input filename" << endl;
cin >> option;
// cin.get(inFile);
string inFile;
getline(cin, inFile);
cout << "Enter the output filename" << endl;
cin >> outFile;
}
void encrypt(){
char t
}
void decrypt(){
}
I have been working on the following program but I am encountering some difficulties any help whatsoever would be greatly appreciated.
My instructions are:
Write a c++ program,
1. Prompts the user for a choice of encrypt or decrypt, prompts for the input and output filenames
2. has a function for encryption
a. generates a random key
b. stores the key in the encrypted file
c. encrypts the data from the input file by performing xor of the key with every byte from the input file
3. has a function for decryption
a. reads the key from the encrypted file
b. decrypts the data from the input file by performing xor of the key wit every byte from the file
4. performs the encryption or decryption based on the user's choice.
so far I have ( Not quite sure what to do next):
#include<iostream>
#include<string>
#include<ctime>
#include<cstdlib>
#include<fstream>
usingnamespace std;
void encrypt();
void decrypt();
char option;
// char inFile;
char outFile;
int decryptencrypt;
void main()
{
srand((unsigned)time(NULL));
encrypt();
decrypt();
cout << "Enter 1 to decrypt" << endl;
cout << "Enter 2 to encrypt" << endl;
cin >> decryptencrypt;
cout << "Enter the input filename" << endl;
cin >> option;
// cin.get(inFile);
string inFile;
getline(cin, inFile);
cout << "Enter the output filename" << endl;
cin >> outFile;
}
void encrypt(){
char t
}
void decrypt(){
}
Why do you ask for both the infile and the outfile? You should only ask the question appropriate to what the user has selected (and perhaps perform some error checking). A switch statement might suit you best:
And don't forget to allow a string parameter for encrypt()/decrypt(), or else it won't know what file to open!
But agreed with iamthwee, you haven't written much. What don't you know about writing an encrpytion program?
C++ Syntax (Toggle Plain Text)
switch (decryptencrypt) { case 1: // ask for infile, call decrypt(), blah blah break; case 2: // ask for outfile etc break; default: // invalid choice }
But agreed with iamthwee, you haven't written much. What don't you know about writing an encrpytion program?
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
What is this program supposed to output? you have not coded encrypt and decrypt yet
Simplest encrypt algorithm would be xor each of the byte of the input with a magic number, where exactly are you stuck ?
Simplest encrypt algorithm would be xor each of the byte of the input with a magic number, where exactly are you stuck ?
Last edited by ithelp; Feb 23rd, 2007 at 9:57 am.
Char arrays would be kind of silly when you could simply use a C++ string to hold the data. You then directly reference each character using the string's [] overloaded operators, and simply perform the XOR with the key. To decrypt it, simply use the XOR with the key again, and the character will be readable.
Not to say that it's a very secure method of encryption, but it will suffice for a homework assignment like this one...
Not to say that it's a very secure method of encryption, but it will suffice for a homework assignment like this one...
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Libraries
- Next Thread: Noobie help :P
Views: 1482 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






