Advertisement
youuw

5.c

Nov 29th, 2021
876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.68 KB | None | 0 0
  1. /*
  2. Zadanie 5. Napisac program wypelniajacy tablice dowolnym tekstem np. "Wyobraznia jest wazniejsza od wiedzy". A nastepnie dokonac jego szyfrowania wykorzystujac
  3. szyfr Cezara. Wyswietlic na ekranie monitora oba teksty.
  4. */
  5.  
  6. #include <stdio.h>
  7.  
  8. int main(int argc, char **argv) {
  9.  
  10.     char alphabetBig[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
  11.     char alphabetSmall[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  12.     char txt[] = "Wyobraznia jest wazniejsza od wiedzy";
  13.  
  14.     int move = 0;
  15.     int size = sizeof(txt)-1;
  16.     printf("%s\npodaj wspolczynnik przesuniecia ", txt);
  17.     scanf("%d", &move);
  18.     if(move<0) return 1;
  19.     if(move>26) move -= (int)(move/26)*26;
  20.     for(int x = 0; x<size;x++) {
  21.         for(int y = 0; y<26;y++) {
  22.             if(txt[x] == alphabetBig[y]) {
  23.                 if(y+move>=26) txt[x] = alphabetBig[(y+move)-26];
  24.                 else txt[x] = alphabetBig[y+move];
  25.                 y=26;
  26.             }
  27.         }
  28.         for(int y = 0; y<26;y++) {
  29.             if(txt[x] == alphabetSmall[y]) {
  30.                 if(y+move>=26) txt[x] = alphabetSmall[(y+move)-26];
  31.                 else txt[x] = alphabetSmall[y+move];
  32.                 y=26;
  33.             }
  34.         }
  35.     }
  36.  
  37.     printf("\ntekst po szyfrowaniu: %s\n", txt);
  38.  
  39.     for(int x = 0; x<size;x++) {
  40.         for(int y = 0; y<26;y++) {
  41.             if(txt[x] == alphabetBig[y]) {
  42.                 if(y-move<0) txt[x] = alphabetBig[26+(y-move)];
  43.                 else txt[x] = alphabetBig[y-move];
  44.                 y=26;
  45.             }
  46.         }
  47.         for(int y = 0; y<26;y++) {
  48.             if(txt[x] == alphabetSmall[y]) {
  49.                 if(y-move<0) txt[x] = alphabetSmall[26+(y-move)];
  50.                 else txt[x] = alphabetSmall[y-move];
  51.                 y=26;
  52.             }
  53.         }
  54.     }
  55.  
  56.     printf("\ntekst po odszyfrowaniu: %s\n", txt);
  57.     return 0;
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement