Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- #include <string.h>
- #include <ctype.h>
- int main(void)
- {
- printf("\nPlease enter your messege: ");
- string name = GetString();
- int tester;
- char output[strlen(name)];
- printf("Please enter your EncryptionKey: ");
- int key = GetInt();
- for (int i = 0; i < strlen(name); ++i)
- {
- tester = (int)name[i]; //Get Asci Code
- if (tester > 64 && tester < 91 )
- {
- if (tester > 90-key)
- {
- //printf("%c is UPPERCASE and its ASCII code is %i \n",name[i],tester);
- tester = 65 + (key - (90 - tester) - 1);
- //printf ("The ASCII after Encryption(Overlap) is %i \n",tester);
- output[i] = (char)tester;
- }
- else
- {
- //printf("%c is UPPERCASE and its ASCII code is %i \n",name[i],tester);
- tester = tester+key;
- //printf ("The ASCII after Encryption is %i \n",tester);
- output[i] = (char)tester;
- }
- }
- else if ( tester > 96 && tester < 123)
- {
- if (tester > 122-key)
- {
- //printf("%c is LOWERCASE and its ASCII code is %i \n",name[i],tester);
- tester = 97 + (key - (122 - tester) - 1);
- //printf ("The ASCII after Encryption(Overlap) is %i \n",tester);
- output[i] = (char)tester;
- }
- else
- {
- //printf("%c is LOWERCASE and its ASCII code is %i \n",name[i],tester);
- tester = tester+key;
- //printf ("The ASCII after Encryption is %i \n",tester);
- output[i] = (char)tester;
- }
- }
- else
- {
- //printf("%c is Neither\n",name[i]);
- output[i] = (char)tester;
- }
- }
- printf("Your Encrypted Messege is --> %s\n\n",output);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement