Advertisement
Antropex

Bartek

Sep 11th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4. char msg[100], ch;
  5. int i,key;
  6. char mode;
  7. printf("Wcisniej D dla dekodowania lub Z dla kodowania\na");
  8. mode = getch();
  9. printf("Enter a plaintext %c\n",mode);
  10. gets(msg);
  11. printf("Enter key");
  12. scanf("%d",&key);
  13. for(i=0;msg[i]!='\0';i++)
  14. {
  15. ch=msg[i];
  16. if(ch>='a'&&ch<='z')
  17. {
  18. if(mode == 'D' || mode == 'd')
  19. ch=ch-key;
  20. if(mode=='Z' || mode == 'z')
  21. ch=ch+key;
  22.  
  23. if(ch>'z')
  24. {
  25. ch=ch-'z'+'a'-1;
  26. }
  27. msg[i]=ch;
  28. }
  29. else if(ch>='A'&&ch<'Z')
  30. {
  31. if(mode == 'D' || mode == 'd')
  32. ch=ch-key;
  33. if(mode=='Z' || mode == 'z')
  34. ch=ch+key;
  35. if(ch>'Z')
  36. {
  37. ch=ch='Z'+'A'-1;
  38. }
  39. msg[i]=ch;
  40. }
  41. }
  42. printf("Encrypted message: %s", msg);
  43. return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement