Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Zadanie 5. Napisac program wypelniajacy tablice dowolnym tekstem np. "Wyobraznia jest wazniejsza od wiedzy". A nastepnie dokonac jego szyfrowania wykorzystujac
- szyfr Cezara. Wyswietlic na ekranie monitora oba teksty.
- */
- #include <stdio.h>
- int main(int argc, char **argv) {
- 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'};
- 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'};
- char txt[] = "Wyobraznia jest wazniejsza od wiedzy";
- int move = 0;
- int size = sizeof(txt)-1;
- printf("%s\npodaj wspolczynnik przesuniecia ", txt);
- scanf("%d", &move);
- if(move<0) move -= 2*move;
- if(move>26) move -= (int)(move/26)*26;
- for(int x = 0; x<size;x++) {
- for(int y = 0; y<26;y++) {
- if(txt[x] == alphabetBig[y]) {
- if(y+move>=26) txt[x] = alphabetBig[(y+move)-26];
- else txt[x] = alphabetBig[y+move];
- y=26;
- }
- }
- for(int y = 0; y<26;y++) {
- if(txt[x] == alphabetSmall[y]) {
- if(y+move>=26) txt[x] = alphabetSmall[(y+move)-26];
- else txt[x] = alphabetSmall[y+move];
- y=26;
- }
- }
- }
- printf("\ntekst po szyfrowaniu: %s\n", txt);
- for(int x = 0; x<size;x++) {
- for(int y = 0; y<26;y++) {
- if(txt[x] == alphabetBig[y]) {
- if(y-move<0) txt[x] = alphabetBig[26+(y-move)];
- else txt[x] = alphabetBig[y-move];
- y=26;
- }
- }
- for(int y = 0; y<26;y++) {
- if(txt[x] == alphabetSmall[y]) {
- if(y-move<0) txt[x] = alphabetSmall[26+(y-move)];
- else txt[x] = alphabetSmall[y-move];
- y=26;
- }
- }
- }
- printf("\ntekst po odszyfrowaniu: %s\n", txt);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement