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>
- #include <stdlib.h>
- //i is what number character of the string, s asks you for a string, n asks you what the key is, and b is what will be printed
- // lines 8 to 14 makes sure the user puts in 2 command line arguments
- // int a is what number character of the cipherc code
- int main(int argc, string argv[])
- {
- //making sure I have two command line arguments
- if (argc != 2)
- {
- printf("Usage:%s abc\n" , argv[0]);
- return 1;
- }
- //code only runs with two command line arguments
- if (argc == 2)
- {
- string s = get_string("plaintext: ");
- string b = (argv[1]);//argv1 is the string given at the command line argument
- int a = 0;
- // setting the cipher to the correct amount
- for (int i = 0; i < strlen(s); i++)
- {
- if (i < strlen(b))
- {
- a = i;
- b[a] = atoi(b[a]);
- }
- else
- {
- a = (i - strlen(b));
- }
- {
- if (islower(b[a]))
- {
- b[a] = toupper(b[a]);
- }
- if (isupper(b[a]))
- {
- b[a] = b[a] - 65;
- }
- // making sure the code wraps around capital z instead of going over it
- while (s[i] + b[a] > (int)'Z' && isupper(s[i]))
- {
- s[i] = s[i] - 26;
- }
- if isspace(s[i])
- {
- printf(" ");
- i = i + 1;
- }
- if ispunct(s[i])
- {
- s[i] = s[i] - b[a];
- }
- // making sure the code wraps around lowercase z instead of going over it
- while (s[i] + b[a] > (int)'z' && islower(s[i]))
- {
- s[i] = s[i] - 26;
- }
- printf("%c", s[i] + b[a]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement