Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- int check(int d, string f[]);
- char typeandcase(char pi, int size, char k[]);
- int main(int argc, string argv[])
- {
- if (check(argc, argv) == 3)
- {
- string P = get_string("paintext: ");
- int z = strlen(P);
- string NUM = argv[1]; char m[z + 1];
- m[z] = '\n';
- for (int j = 0; j < z; j ++)
- {
- typeandcase(P[j], z, NUM);
- m[j] = typeandcase(P[j], z, NUM);
- }
- printf("ciphertext: %s\n", m);
- return 0;
- }
- else
- {
- return 1;
- }
- }
- int check(int d, string f[])
- {
- if (d == 2)
- {
- for (int i = 0; i < strlen(f[1]); i ++)
- {
- if (isdigit(f[1][i]))
- {
- printf("Usage: ./vigenere keyword \n");
- return 1 ;
- }
- }
- return 3 ;
- }
- else
- {
- printf("Usage: ./vigenere keyword \n");
- return 1;
- }
- return 1;
- }
- char typeandcase(char pi, int size, char k[])
- {
- if (isalpha(pi))
- {
- for (int i = 0 ; i < size; i++)
- {
- if (islower(pi) && islower(k[i]))
- {
- pi -= 'a';
- k[i] -= 'a' ;
- pi = (pi + k[i]) % 26;
- pi += 'a';
- }
- else if (isupper(pi) && isupper(k[i]))
- {
- pi -= 'A';
- k[i] -= 'A' ;
- pi = (pi + k[i]) % 26;
- pi += 'A';
- }
- }
- printf("value: %c\n", pi);
- }
- return pi;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement