Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> // <- standardowe wejscie wyjscie
- #include <fstream>
- #include <string.h>
- using namespace std;
- int main(int argc, char ** argv)//argc to liczba calkowita informujaca o tym ile argumentow zostalo przekazanych. PYTANIE!
- {
- cout<<"**************************************************************"<< endl;
- cout << "*\t\t ******************* \t\t *"<< endl;
- cout << "*\t\t * CRYPTO WKR 2017 * \t\t *"<< endl;
- cout << "*\t\t ******************* \t\t *"<< endl;
- cout<<"**************************************************************"<< endl;
- if (argc == 2) // pierwszym parametrem jest nazwa programu
- {
- if( argv[1][0]=='-' && argv[1][1]=='h' && strlen(argv[1]) == 2 || std::string(argv[1])=="--help")
- {
- cout<<"* Prosze uzupelnic pole pomocy w miare rozwoju aplikacji. *"<< endl;
- cout<<"* W chwili obecnej program zbudowany jest jako szablon, *"<< endl;
- cout<<"* ktory powinien byc uzupelniany o kolejne algorytmy *"<< endl;
- cout<<"* kryptograficzne. Powodzenia. *"<< endl;
- cout<<"**************************************************************"<< endl;
- cout<<"* Dolecowy program powinien dzialac w nastepujacy sposob: *"<< endl;
- cout<<"* W wierszu polecen wywolujemy nazwe programu i parametry *"<< endl;
- cout<<"* programu, gdzie: *"<< endl;
- cout<<"* -bc szyfr blokowy w trybie c/d (szyfrowanie/deszyfrowanie);*"<< endl;
- cout<<"* -sc szyfr strumieniowy w trybie c/d *"<< endl;
- cout<<"* (szyfrowanie/deszyfrowanie); *"<< endl;
- cout<<"* -hf funkcja skrotu bez trybow; *"<< endl;
- cout<<"* -ac szyfr asymetryczny w trybie c/d *"<< endl;
- cout<<"* (szyfrowanie/deszyfrowanie); *"<< endl;
- cout<<"* -i sciezka pliku wejsciowego (tekstu jawnego, *"<< endl;
- cout<<"* wiadomosci); *"<< endl;
- cout<<"* -o sciezka pliku wyjsciowego (tekstu zaszyfrowanego, *"<< endl;
- cout<<"* skrotu); *"<< endl;
- cout<<"* -k sciezka klucza; *"<< endl;
- cout<<"* -h, --help to pomoc (wystepuje bez innych parametrow); *"<< endl;
- cout<<"**************************************************************"<< endl;
- cout<<"*Przyklad: *"<< endl;
- cout<<"*crypto.exe -bc d -i C:\\in.txt -o D:\\out.txt -k C:\\key.txt *"<< endl;
- cout<<"**************************************************************"<< endl;
- cout<<"* Porgram operuje na plikach tekstowych. *"<< endl;
- cout<<"**************************************************************"<< endl;
- }
- else
- {
- cout<< argc<<endl;
- cout<<"blednie wprowadzone parametr/parametry. (Blad: E001)" <<endl;
- }
- }
- else
- { fstream input;
- fstream output;
- fstream key;
- bool flaga_algorytmu=false;
- int flaga_poprawnosci_parametrow=0;
- int wybor_algorytmu=0;
- for (int i = 0; i < argc; i++)
- {
- if (argv[i][0] == '-')
- {
- if(argc==i+1 || argv[i+1][0] == '-')
- {
- if(std::string(argv[i])=="-hf")
- {
- cout << argv[i] << ":";
- cout << "Ok, wyznaczenie skrotu do dzialania nie potrzebuje parametru ani pliku klucza;" << endl;
- }
- else if(std::string(argv[i])=="-bc")
- {
- flaga_algorytmu=true;
- cout << argv[i] << ": ";
- cout << "Nie podano parametru pracy szyfru blokowego;" <<endl;
- }
- else if(std::string(argv[i])=="-sc")
- {
- flaga_algorytmu=true;
- cout << argv[i] << ": ";
- cout << "Nie podano parametru pracy szyfru strumieniowego;" <<endl;
- }
- else if(std::string(argv[i])=="-ac")
- {
- flaga_algorytmu=true;
- cout << argv[i] << ": ";
- cout << "Nie podano parametru pracy szyfru asymetrycznego;" <<endl;
- }
- else if(std::string(argv[i])=="-i")
- {
- cout << argv[i] << ": ";
- cout << "Nie podano sciezki pliku wejsciowego;" <<endl;
- }
- else if(std::string(argv[i])=="-o")
- {
- cout << argv[i] << ": ";
- cout << "Nie podano sciezki pliku wyjsciowego;" <<endl;
- }
- else if(std::string(argv[i])=="-k")
- {
- cout << argv[i] << ": ";
- cout << "Nie podano pliku klucza;" <<endl;
- }
- else
- {
- cout << argv[i] << ": ";
- cout << "Niepoprawny parametr pracy programu;"<<endl;
- }
- }
- else
- {
- if(std::string(argv[i])=="-i")
- {
- input.open(argv[i+1], ios::in);
- if(input.good()==true)
- {
- cout << "Dane wejsciowe zostana pobrany z pliku: " << argv[++i] << endl;
- }
- else
- {
- cout << argv[i] << ": ";
- cout << "Niepoprawna sciezka pliku wejsciowego!"<<endl;
- }
- }
- else if(std::string(argv[i])=="-o")
- {
- output.open(argv[i+1], ios::out);
- if(output.good()==true)
- {
- cout << "Dane wyjsciowe zostana zapisane do pliku: " << argv[++i] << endl;
- }
- else
- {
- cout << argv[i] << ": ";
- cout << "Niepoprawna sciezka pliku wejsciowego!"<<endl;
- }
- }
- else if(std::string(argv[i])=="-k")
- {
- key.open(argv[i+1], ios::in);
- if(key.good()==true)
- {
- cout << "Klucz zostanie pobrany z pliku: " << argv[++i] << endl;
- }
- else
- {
- cout << argv[i] << ": ";
- cout << "Niepoprawna sciezka klucza!"<<endl;
- }
- }
- else if(std::string(argv[i])=="-bc")
- {
- if(std::string(argv[i+1])=="c" || std::string(argv[i+1])=="d")
- {
- cout << "Szyfr blokowy bedzie pracowal w trybie (szyfrowania -> c , deszyfrowania -> d): " << argv[++i] << endl;
- }
- else
- {
- cout << argv[i] << ": ";
- cout << "Niepoprawny tryb pracy szyfru;"<<endl;
- }
- }
- else if(std::string(argv[i])=="-sc")
- {
- if(std::string(argv[i+1])=="c" || std::string(argv[i+1])=="d")
- {
- cout << "Szyfr strumieniowy bedzie pracowal w trybie (szyfrowania -c , deszyfrowania -d): " << argv[++i] << endl;
- }
- else
- {
- cout << argv[i] << ": ";
- cout << "Niepoprawny tryb pracy szyfru;"<<endl;
- }
- }
- else if(std::string(argv[i])=="-as")
- {
- if(std::string(argv[i+1])=="c" || std::string(argv[i+1])=="d")
- {
- cout << "Szyfr asymetryczny bedzie pracowal w trybie (szyfrowania -c , deszyfrowania -d): " << argv[++i] << endl;
- }
- else
- {
- cout << argv[i] << ": ";
- cout << "Niepoprawny tryb pracy szyfru;"<<endl;
- }
- }
- else
- {
- cout << argv[i] << ": ";
- cout << "Niepoprawny parametr pracy programu;"<<endl;
- }
- }
- }
- }
- }
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment