Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdlib.h>
- int main (int agrc,string argv[])
- {
- if (agrc!=2)
- {
- printf("Please specify one command argument, being the cypher key");
- return 1;
- }
- string key = agrv[1];
- for (int i=0, j=strlen(key); i<j; i++)
- {
- key[i]=tolower(key[i]);
- }
- string plaintext=GetString();
- int letter;
- for (int i=0, j=strlen(key);i<j;i++)
- {
- if (isalpha(plaintext[i]))
- {
- if(isupper(plaintext[i]))
- {
- letter= (int)'A'+(((int)plaintext[i]-(int)'A'+((int)key[i%5]-(int)'a'))%26);
- }
- else
- {
- letter= (int)'a'+(((int)plaintext[i]-(int)'a'+((int)key[i%5]-(int)'a'))%26);
- }
- printf("%c",(char) letter);
- }
- else
- {
- printf("%c",plaintext[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement