Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- #include <stdlib.h>
- int shift(char c);
- int main(int argc, string argv[])
- {
- string key = argv[1];
- if (argc== 2)
- {
- for(int i=0; i<strlen(key); i++)
- {
- if(isalpha(key[i]))
- {
- continue;
- }
- else
- {
- printf("Usage: ./vigenere keyboard\n");
- return 1;
- }
- }
- }
- else
- {
- printf("Usage: ./vigenere keyboard\n");
- return 1;
- }
- string text=get_string("plaintext: ");
- printf("ciphertext: ");
- int ktracker=strlen(key);
- int counter=0;
- for(int i=0;i<strlen(text);i++)
- {
- if(text[i]== '\40')
- {
- printf("%c",text[i]);
- }
- else
- {
- printf("%c",(text[i]+shift(key[counter%ktracker])));
- counter++;
- }
- }
- printf("\n");
- }
- int shift(char c)
- {
- int ans=0;
- if(isupper(c))
- {
- ans=((c-65) % 26);
- }
- else if(islower(c))
- {
- ans=((c-97) % 26);
- }
- return ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement