Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<cs50.h>
- #include<stdlib.h>
- #include<ctype.h>
- #include<string.h>
- int main(int argc, char* argv[])
- {
- int i=0,j=0,n=0,k=0;
- if(argc!=2)
- {
- printf("Bad I/p\n"); // checking for valid argv[1]
- return 1;
- exit(0);
- }
- char* key=argv[1];
- for(i=0,n=strlen(key);i<n;i++) // To check wether each character of key is alphabet
- {
- if (isalpha(key[i]))
- {
- printf("AFTER VALID\n");
- if (isupper(key[i]))
- {
- key[i]=key[i]-65;
- }
- if (islower(key[i]))
- {
- key[i]=key[i]-97;
- }
- }
- else
- printf("Enter valid key\n");
- exit(0);
- return 1;
- }
- printf("B4 input\n"); // why isn't this statement getting executed ?
- string msg=GetString(); // plaintext input from user
- if (isalpha(msg[j]))
- {
- for (int j=0,m=strlen(msg);j<m;j++)
- {
- if (isupper(msg[j]))
- {
- msg[j]=(((msg[j]-65)+key[k%n])%26)+65; // k%n = k% strlen(keyword) cipher formula for upper case
- }
- if (islower(msg[j]))
- {
- msg[j]=(((msg[j]-97)+key[k%n])%26)+97; // 97 and 65 are added to convert back to ascii form
- }
- else
- printf("%c",msg[j]);
- k++;
- printf("%c*",msg[j]);
- } // j-loop 2
- } //isalpha du
- else
- {
- printf("Enter valid key\n");
- exit(0);
- return 1;
- }
- } //main du bracket
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement