I'm trying to make a program get an input at one instance to encrypt for a user, at in another instance(whenever the user wants) derive from the same file created in the encryption run and reverses the encryption but instead, it's just giving me what looks like error codes. About 6 numbers/letters each time but that are not at all related to what it's supposed to do.
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <conio.h>
#include <cstdio>
#include <string>
using namespace std;
//ENCRYPTION AND DECRYPTION
string Decode(string text)
{
int a;
for(a=0; a<text.length(); a++){
text[a]--;
}
return text;
}
string Encode (string text)
{
int a;
for(a=0; a<text.length(); a++){
text[a]++;
}
return text;
}
//PROMPTS AND MAIN PROGRAM
int main(){
char input;
cout<<"+-+-+-+-+-+-+-+\n";
cout<<"|C|r|y|p|t|e|r|\n";
cout<<"+-+-+-+-+-+-+-+\n\n";
cout<<"Version 1.01 - Revision 2013\n";
cout<<"Created by Dylan Moore\n";
cout<<"____________________\n\n";
cout<<"Hello, would you like to decode or encode an encryption key?\nType 'd' for decode or 'e' for encode.\n\n";
cin>>input;
cin.get();
switch(input){
//DECODE
case 'd':
{
string Message;
ifstream myfile;
myfile.open ("Key.txt");
if (myfile.fail())
{
cout<<"Key.txt not found! Please make sure it is in the same directory as Crypter!\n\n";
cin.get();
return 0;
}
getline(myfile, Message);
myfile.close();
cout<<"Decoded Data:\n"<<Decode;(Message);
break;
}
//ENCODE
case 'e':
{
string Message;
ofstream myfile;
cout<<"Type the key you wish to be encrypted. When finished, press 'enter' 2 times to confirm.\n\n";
getline (cin, Message);
cin.get();
myfile.open ("Key.txt");
myfile<<Encode(Message);
myfile.close();
cout<<"Thank you, your message has been saved to 'Key.txt' in this directory.\n";
break;
}
}
return _getch();
}