fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void decode(char *msg, int shift) {
  5. char *c;
  6. // jedz po tablicy poki nie spotkasz nulla
  7. for (c = msg; *c != '\0'; c++) {
  8. int max, min;
  9. int ascii = (int)*c;
  10. // sprawdz czy maly czy duzy znak
  11. if (ascii >= 97 && ascii <= 122) {
  12. // male znaki
  13. max = 123;
  14. min = 97;
  15. } else if (ascii >= 65 && ascii <= 90) {
  16. // duze znaki
  17. max = 91;
  18. min = 65;
  19. } else {
  20. continue;
  21. }
  22. // zrob cezara
  23. ascii += shift;
  24. // jesli wypadamy poza range - modulo + min
  25. if (ascii >= max) {
  26. ascii = (ascii + min) % max;
  27. }
  28. // podmien
  29. *c = ascii;
  30. }
  31. }
  32.  
  33. int main(void) {
  34. char msg[20] = "Adam Jest ze";
  35. int shift = 1;
  36. printf("orig : %s \n", msg);
  37. decode(msg, shift);
  38. printf("caesar by %d: %s",shift, msg);
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0s 4528KB
stdin
Standard input is empty
stdout
orig :       Adam Jest ze 
caesar by 1: Bebn Kftu af