Created
December 2, 2016 03:39
-
-
Save tylersloeper/6f7eba1e6ad252e4d5e4a46d6e730386 to your computer and use it in GitHub Desktop.
CS50 Pset02 (3 parts)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cs50.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <ctype.h> | |
int main(int argc, string argv[]) | |
{ | |
int i = 0; | |
int stringlength = 0; | |
if (argc > 2 || argc <2) | |
{ | |
printf("Please try again. Input the command and your cipher number.\n"); | |
return 1; | |
} | |
else | |
{ | |
//printf("Please provide me with a string (series of words) to encrypt. I will encrypt using the ceasar cypher and the number you have already provided:\n"); | |
string stringtoencrypt = GetString(); | |
int key = atoi(argv[1]); | |
for ( i = 0, stringlength = strlen(stringtoencrypt); i < stringlength; i++) | |
{ | |
if (isalpha(stringtoencrypt[i])) | |
{ | |
if (isupper(stringtoencrypt[i])) | |
{ | |
int letter = (((stringtoencrypt[i] + key - 65) % 26 ) + 65); | |
printf("%c", letter); | |
} | |
if (islower(stringtoencrypt[i])) | |
{ | |
int letter = (((stringtoencrypt[i] + key - 97) % 26 ) + 97); | |
printf("%c", letter); | |
} | |
} | |
else | |
{ | |
printf("%c", stringtoencrypt[i]); | |
} | |
} | |
printf("\n"); | |
} | |
} | |
//made by tyler loeper for CS50 2016 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <cs50.h> | |
#include <string.h> | |
#include <ctype.h> | |
int main(void) | |
{ | |
string fullname; | |
//printf("Please write your full name.\n"); | |
fullname = GetString(); | |
//strupr (fullname); | |
int stringlength = strlen(fullname); | |
//printf("Your name is %s\n", fullname); | |
for (int i = 0; i < stringlength; i++) | |
{ | |
if (i == 0) | |
{ | |
char lettertoprint = fullname[i]; | |
lettertoprint = toupper(lettertoprint); | |
printf("%c", lettertoprint); | |
} | |
else if (fullname[i] == ' ') | |
{ | |
//printf("%c", fullname[i+1]); | |
char lettertoprint = fullname[i+1]; | |
lettertoprint = toupper(lettertoprint); | |
printf("%c", lettertoprint); | |
} | |
} | |
printf("\n"); | |
//printf("\n Those are your initials are BLANK\n"); | |
} | |
//made by tyler loeper for CS50 2016 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cs50.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <ctype.h> | |
int main(int argc, string argv[]) | |
{ | |
//define all variables | |
int i = 0; | |
int j = 0; | |
int m = 0; | |
string key = argv[1]; | |
int keylength = strlen(key); | |
if (argc == 2) | |
{ | |
for (m= 0; m < keylength; m++) | |
{ | |
if isalpha(key[m]) | |
{ | |
} | |
else | |
{ | |
printf("Rejected\n"); | |
return 1; | |
} | |
} | |
//printf("Provide a word to vigenere encrypt with the codeword you provided\n"); | |
string message = GetString(); | |
int messagelength = strlen(message); | |
//get amount to change by | |
//if keyword is alpha needs to be checked too as well as reject more than one arg. so if arc is 2 proceed else exit. and for checking the key word i dont know. i could do a quick for loop that runs first then runs to the next, and if at anypoint it is not alpha then return 1. | |
for (i= 0, j= 0; i < messagelength; i++) | |
{ | |
if isalpha(message[i]) | |
{ | |
if isupper(message[i]) | |
{ | |
if isupper(key[j %keylength]) | |
{ | |
//char a = message | |
//char b = 0 | |
int encryptedchar = ((((message[i] + (key[j %keylength] - 65)) -65) % 26 ) +65); | |
j++; | |
printf("%c", encryptedchar); | |
} | |
if islower(key[j %keylength]) | |
{ | |
int encryptedchar = ((((message[i] + (key[j %keylength] - 97)) -65) % 26 ) +65); | |
j++; | |
printf("%c", encryptedchar); | |
} | |
} | |
if islower(message[i]) | |
{ | |
if isupper(key[j %keylength]) | |
{ | |
int encryptedchar = ((((message[i] + (key[j %keylength] - 65)) -97) % 26 ) +97); | |
j++; | |
printf("%c", encryptedchar); | |
} | |
if islower(key[j %keylength]) | |
{ | |
int encryptedchar = ((((message[i] + (key[j %keylength] - 97)) -97) % 26 ) +97); | |
j++; | |
printf("%c", encryptedchar); | |
} | |
} | |
} | |
else | |
{ | |
printf("%c", message[i]); | |
} | |
} | |
printf("\n"); | |
} | |
else | |
{ | |
printf("Rejected\n"); | |
return 1; | |
} | |
} | |
//made by tyler loeper for CS50 2016 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment