Fungerande saker:
Det går att läsa från en .txt fil.
Det går att kryptera strängen.
Det går att dekryptera strängen.
Det går att spara krypterad sträng till fil.
Det går att läsa krypterad sträng från fil.
Icke fungerande saker:
Det går INTE att dekryptera krypterad sträng som är inläst från fil.
Jag förstår mig inte på detta då allt funkar utom kombinationen av läsa in från fil OCH dekryptera.
Ett stycke c#-kod:
#include <iostream>
#include <stdlib.h>
#include <string>
#include <fstream>
using namespace std;
void encrypt(string filename){
string line;
ifstream input(filename.c_str());
if (input.is_open())
{
while(!input.eof())
{
getline (input,line);
cout <<line<<endl;
}
for( int i=0 ; i<line.length() ; i++ )
line[i] = line[i]^129;
input.close();
}
else if(!input)
{
cerr<<"Could not open file";
exit(1);
}
ofstream output;
output.open("encryption.enc");
output << line << endl;
output << flush;
output.close();
for( int i=0 ; i<line.length() ; i++ )
line[i] = line[i]^129;
cout<<"Decrypted Crap Here:"<<line<<endl;
string line;
ifstream input("encryption.enc");
if (input.is_open())
{
while(!input.eof())
{
getline (input,line);
cout <<endl<<line<<endl;
}
for( int i=0 ; i<line.length() ; i++ )
line[i] = line[i]^129;
input.close();
}
else if(!input)
{
cerr<<"Could not open file";
exit(1);
}
cout << "Your decrypted text is :"<<line<<endl;
ifstream input("encryption.enc");
if (input.is_open())
{
while(!input.eof())
{
getline (input,line);
cout <<endl<<line<<endl;
}
for( int i=0 ; i<line.length() ; i++ )
line[i] = line[i]^129;
input.close();
}
else if(!input)
{
cerr<<"Could not open file";
exit(1);
}
cout << "Your decrypted text is :"<<line<<endl;
return;
}
int main(int argc, char *argv[])
{
string filename;
cout<<"Please enter the filename for encryption"<<endl;
getline(cin,filename);
if (!cin) return 0;
encrypt(filename);
system("PAUSE");
return (EXIT_SUCCESS);
}
Ingen status