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[1]);
- int j;
- {
- if (argc != 2) //if user doesn't run command-line argument of one or enter positive int
- {
- printf("Usage: ./vigenere key\n"); //prompt them to run it again
- return 1; //returning zero means everything went well
- }
- if (isalpha(argv[1])) //If user inputs an alpha key continue
- string p = get_string("plaintext: "); //prompt for plaintext and store
- {
- printf("ciphertext: "); //Print after collecting plaintext
- }
- for (int j = 0, n = strlen(argv[1]; j < n; j++) //length of the entire string. Save n as strlen for use in loop
- {
- char cipher; //char within the string
- int shift(char cipher);
- if (isupper(p[i]))
- {
- cipher = ((p[i] + key[j]) % 26); //add key and rotate
- printf("%c", cipher); //print ciphertext after rotating
- }
- else if (islower(p[i]))
- {
- cipher = ((p[i] + key[j]) % 26); //add key and rotate
- printf("%c", cipher); //print ciphertext after rotating
- }
- else
- {
- printf("%c", p[i]); //Else, print unchanged
- }
- }
- printf("\n");
- return 0;
- } //Closing brackets
- //function definition
- int shift(char c);
- int j;
- {
- for (j = 0; j < strlen(argv[1]); j++)
- int c = (argv[1]); //NEW SHIFT function; user input at start of program
- int key = (argv[1][j]);
- for (key[j] % strlen(argv[1]))
- if (islower(c))
- {
- key = ((key[j] - 97) % 26); //Shifting by alpha index
- }
- if (isupper(c))
- {
- key = ((key[j] - 65) % 26);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement