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 argc, string argv[])
- {
- string k = argv[1];
- if (argc == 2 && isalpha(k))
- {
- goto cypher;
- }
- else
- {
- printf("Wrong command-line argument! Try again!\n");
- return 1;
- }
- cypher: printf("Please enter massage you want to cypher!\n");
- string text = GetString();
- for (int i =0, n = strlen(text), m = strlen(k); i < n; i++)
- {
- if (isalpha(text[i]))
- {
- if (isupper(text[i]))
- {
- char letter = ((text[i] + k[i % m]) - 65) % 26;
- printf("%c", letter + 65);
- }
- else
- {
- char letterlow = ((text[i] + k[i % m]) - 97) % 26;
- printf("%c", letterlow + 97);
- }
- }
- else
- {
- printf("%c", text[i]);
- }
- }
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement