Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main()
- {
- char msg[100], ch;
- int i,key;
- char mode;
- printf("Wcisniej D dla dekodowania lub Z dla kodowania\na");
- mode = getch();
- printf("Enter a plaintext %c\n",mode);
- gets(msg);
- printf("Enter key");
- scanf("%d",&key);
- for(i=0;msg[i]!='\0';i++)
- {
- ch=msg[i];
- if(ch>='a'&&ch<='z')
- {
- if(mode == 'D' || mode == 'd')
- ch=ch-key;
- if(mode=='Z' || mode == 'z')
- ch=ch+key;
- if(ch>'z')
- {
- ch=ch-'z'+'a'-1;
- }
- msg[i]=ch;
- }
- else if(ch>='A'&&ch<'Z')
- {
- if(mode == 'D' || mode == 'd')
- ch=ch-key;
- if(mode=='Z' || mode == 'z')
- ch=ch+key;
- if(ch>'Z')
- {
- ch=ch='Z'+'A'-1;
- }
- msg[i]=ch;
- }
- }
- printf("Encrypted message: %s", msg);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement