Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- #include <string.h>
- #include <stdlib.h>
- int main(int argc, string argv[]) {
- if (argc != 2) {
- printf("Invalid input\n");
- return 1;
- }
- int j = atoi(argv[1]);
- // j is the input to move the letters however many spaces
- //prevents the user from using negative integers
- while (j < 0) {
- printf("Invalid input %i, please supply a positive integer\n", j);
- j = get_int();
- }
- if (j > 26) {
- j %= 26;
- }
- printf("plaintext: ");
- string s = get_string();
- //input from user of string to encrypt
- for (int i = 0; i < strlen(s); i++) {
- //These if statements is for the uppercase case
- if (s[i] <= 'Z' && s[i] >= 'A') {
- s[i] += j;
- //wraps back around to uppercase letters
- if (s[i] > 'Z') {
- s[i] -= 26;
- }
- }
- //these if statements are for the lowercase case
- else if (s[i] <= 'z' && s[i] >= 'a') {
- s[i] += j;
- // wraps back around to lowercase letters
- if (s[i] > 'z') {
- s[i] -= 26;
- }
- }
- }
- printf ("ciphertext: %s\n", s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement