Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define SZYFRANT "Projekt Szyfrant 1.0"
- #include <cstring>
- using namespace std;
- class KeyNumber {
- private:
- int liczba;
- public:
- void setKeyNumber(int n) {
- liczba = n;
- }
- int getKeyNumber() {
- return liczba;
- }
- };
- class Enigma {
- private:
- char * Alokacja(char bufor[], int buforSize) {
- char * alokowany = new char[buforSize];
- for (int i = 0; i <= buforSize; i++) {
- alokowany[i] = bufor[i];
- }
- return alokowany;
- }
- void Enigmuj(char text[], KeyNumber liczbaKlucz) {
- int i = 0;
- while (text[i] != NULL) {
- text[i] = text[i] + liczbaKlucz.getKeyNumber();
- i++;
- }
- i = 0;
- while (text[i] != NULL) {
- cout<<text[i];
- i++;
- }
- cout<<""<<endl;
- }
- void DeEnigmuj(char text[], KeyNumber liczbaKlucz){
- int i = 0;
- while (text[i] != NULL) {
- text[i] = text[i] - liczbaKlucz.getKeyNumber();
- i++;
- }
- i = 0;
- while (text[i] != NULL) {
- cout<<text[i];
- i++;
- }
- cout<<""<<endl;
- }
- public:
- void Szyfruj() {
- cout<<"Enter the text to encrypt:"<<endl;
- char cbufor[1000];
- cin.get(cbufor, 1000);
- cin.get();
- int buforSize = sizeof(cbufor) / sizeof(cbufor[0]);
- KeyNumber liczbaKlucz;
- Enigmuj(Enigma::Alokacja(cbufor, buforSize), liczbaKlucz);
- }
- void DeSzyfruj() {
- cout<<"Enter the text to decrypt:"<<endl;
- char cbufor[1000];
- cin.get(cbufor, 1000);
- cin.get();
- int buforSize = sizeof(cbufor) / sizeof(cbufor[0]);
- KeyNumber liczbaKlucz;
- DeEnigmuj(Enigma::Alokacja(cbufor, buforSize), liczbaKlucz);
- }
- };
- int main()
- {
- cout<<"Welcome to "<<SZYFRANT<<"!"<<endl;
- while(1) {
- cout<<"Please, choose one of the following options:"<<endl;
- cout<<"1. Set a key number;"<<endl;
- cout<<"2. Encrypt a message;"<<endl;
- cout<<"3. Decrypt a message;"<<endl;
- cout<<"Press q to exit "<<SZYFRANT<<"."<<endl;
- char main_menu;
- cin>>main_menu;
- switch(main_menu) {
- case '1':
- KeyNumber liczbaKlucz;
- cout<<"Please enter a key number:"<<endl;
- int buff_liczbaklucz;
- cin>>buff_liczbaklucz;
- liczbaKlucz.setKeyNumber(buff_liczbaklucz);
- cout<<"Key number has been set to "<<liczbaKlucz.getKeyNumber()<<"."<<endl;
- break;
- case '2':
- cin.get();
- Enigma enigma;
- enigma.Szyfruj();
- break;
- case '3':
- cin.get();
- Enigma deenigma;
- deenigma.DeSzyfruj();
- break;
- case 'q':
- cout<<"Thanks for using "<<SZYFRANT<<". Press any key."<<endl;
- cin.get();
- return 0;
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment