Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Zaimplementuj proste szyfry harcerskie: GA-DE-RY-PO-LU-KI, PO-LITY-KA-RE-NU, KA-CE-MI-NU-TO-WY.
- Wyswietla sie menu, gdzie uzytkownik wybiera szyfr. Nastepnie komunikat „Podaj ciag wejsciowy”,
- który jest odczytywany przez program a nastepnie zmieniane litery zgodnie ze wzorcem szyfru.
- */
- #include<iostream>
- using namespace std;
- int wybor;
- int main(){
- cout << "Witaj w programie szyfrujacym." << endl;
- cout << "Wybierz szyfr, ktory Cie interesuje:" << endl << endl;
- cout << "1. GA-DE-RY-PO-LU-KI" << endl;
- cout << "2. PO-LI-TY-KA-RE-NU" << endl;
- cout << "3. KA-CE-MI-NU-TO-WY" << endl << endl;
- cin >> wybor;
- cout << endl;
- string slowo;
- string szyfr_1 = "GADERYPOLUKIgaderypoluki";
- string szyfr_2 = "POLITYKARENUpolitykarenu";
- string szyfr_3 = "KACEMINUTOWYkaceminutowy";
- switch(wybor){
- case 1:
- cout << "Szyfr GA-DE-RY-PO-LU-KI" << endl;
- cout << "Podaj swoje slowo: ";
- cin >> slowo;
- for(int i=0; i<slowo.length(); i++){
- for(int j=0; j<szyfr_1.length(); j++){
- if(slowo[i]==szyfr_1[j] && j%2==0){
- slowo[i]=szyfr_1[j+1];
- break;
- }
- if(slowo[i]==szyfr_1[j] && j%2!=0){
- slowo[i]=szyfr_1[j-1];
- }
- }
- }
- cout << endl;
- cout << "Slowo po zaszyfrowaniu:" << endl;
- cout << slowo << endl;
- break;
- case 2:
- cout << "Szyfr PO-LI-TY-KA-RE-NU" << endl;
- cout << "Podaj swoje slowo: ";
- cin >> slowo;
- for(int i=0; i<slowo.length(); i++){
- for(int j=0; j<szyfr_2.length(); j++){
- if(slowo[i]==szyfr_2[j] && j%2==0){
- slowo[i]=szyfr_2[j+1];
- break;
- }
- if(slowo[i]==szyfr_2[j] && j%2!=0){
- slowo[i]=szyfr_2[j-1];
- }
- }
- }
- cout << endl;
- cout << "Slowo po zaszyfrowaniu:" << endl;
- cout << slowo << endl;
- break;
- case 3:
- cout << "Szyfr KA-CE-MI-NU-TO-WY" << endl;
- cout << "Podaj swoje slowo: ";
- cin >> slowo;
- for(int i = 0; i<slowo.length(); i++){
- for(int j=0; j<szyfr_3.length(); j++){
- if(slowo[i]==szyfr_3[j] && j%2==0){
- slowo[i]=szyfr_3[j+1];
- break;
- }
- if(slowo[i]==szyfr_3[j] && j%2!=0){
- slowo[i]=szyfr_3[j-1];
- }
- }
- }
- cout << endl;
- cout << "Slowo po zaszyfrowaniu:" << endl;
- cout << slowo << endl;
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement