Scusate ragazzi per l'UP ma ho appena sistemato il sorgente cosi che possa essere letto più facilmente:
codice:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fstream>
using namespace std;
char choose[2];
char path_file_to_encode[100];
char path_file_to_decode[100];
char path_file_key[100];
fstream file_to_encode; // Input in encode, Output in decode
fstream file_to_decode; // Output in encode, Input in decode
ifstream file_key; // Input in encode and decode
void encode();
void decode();
void info();
int main(int argc, char *argv[])
{
while(1)
{
system("CLS");
cout << "One Time Pad Encoder Decoder v 0.1\n";
cout << "1. Encode\n";
cout << "2. Decode\n";
cout << "3. Info\n";
cout << "Other. Exit\n";
cout << "Choose: ";
cin >> choose;
if(!strcmp(choose,"1"))
{
encode();
}
else if(!strcmp(choose,"2"))
{
decode();
}
else if(!strcmp(choose,"3"))
{
info();
}
else break;
}
return EXIT_SUCCESS;
}
void encode()
{
char byte0, byte1;
// Path del file da codificare
cout << "File to encode: ";
cin >> path_file_to_encode;
// Path del file chiave
cout << "File key: ";
cin >> path_file_key;
// Path del file codificato (fine procedura)
cout << "File encoded: ";
cin >> path_file_to_decode;
// Apro i file
file_to_encode.open(path_file_to_encode, ios::in | ios::binary);
file_key.open(path_file_key, ios::in | ios::binary);
file_to_decode.open(path_file_to_decode, ios::out | ios::binary);
// Processo di codifica
while (file_to_encode.get(byte0))
{
file_key.get(byte1);
byte0 += byte1;
file_to_decode.put(byte0);
}
// Chiudo i file
file_to_encode.close();
file_key.close();
file_to_decode.close();
cout << "File encoded correctly!\n";
system("PAUSE");
}
void decode()
{
char byte0, byte1;
// Path del file da decodificare
cout << "File to decode: ";
cin >> path_file_to_decode;
// Path del file chiave
cout << "File key: ";
cin >> path_file_key;
// Path del file decodificato (fine procedura)
cout << "File decoded: ";
cin >> path_file_to_encode;
// Apro i file
file_to_encode.open(path_file_to_encode, ios::out | ios::binary);
file_key.open(path_file_key, ios::in | ios::binary);
file_to_decode.open(path_file_to_decode, ios::in | ios::binary);
// Processo di decodifica
while (file_to_decode.get(byte0))
{
file_key.get(byte1);
byte0 -= byte1;
file_to_encode.put(byte0);
}
// Chiudo i file
file_to_encode.close();
file_key.close();
file_to_decode.close();
cout << "File decoded correctly!\n";
system("PAUSE");
}
void info()
{
// Output Informazioni
cout << "- Be sure that key file is longer or equal to decode/encode file\n";
cout << "- Created by DesertBoyOfSun http://ottastyle.com\n";
system("PAUSE");
}