Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. int main(void)
  6. {
  7. printf("\nPlease enter your messege: ");
  8. string name = GetString();
  9. int tester;
  10. char output[strlen(name)];
  11. printf("Please enter your EncryptionKey: ");
  12. int key = GetInt();
  13. for (int i = 0; i < strlen(name); ++i)
  14. {
  15.  
  16. tester = (int)name[i]; //Get Asci Code
  17. if (tester > 64 && tester < 91 )
  18. {
  19.  
  20. if (tester > 90-key)
  21. {
  22. //printf("%c is UPPERCASE and its ASCII code is %i \n",name[i],tester);
  23. tester = 65 + (key - (90 - tester) - 1);
  24. //printf ("The ASCII after Encryption(Overlap) is %i \n",tester);
  25. output[i] = (char)tester;
  26. }
  27. else
  28. {
  29. //printf("%c is UPPERCASE and its ASCII code is %i \n",name[i],tester);
  30. tester = tester+key;
  31. //printf ("The ASCII after Encryption is %i \n",tester);
  32. output[i] = (char)tester;
  33. }
  34. }
  35. else if ( tester > 96 && tester < 123)
  36. {
  37.  
  38.  
  39. if (tester > 122-key)
  40. {
  41. //printf("%c is LOWERCASE and its ASCII code is %i \n",name[i],tester);
  42. tester = 97 + (key - (122 - tester) - 1);
  43. //printf ("The ASCII after Encryption(Overlap) is %i \n",tester);
  44. output[i] = (char)tester;
  45. }
  46. else
  47. {
  48. //printf("%c is LOWERCASE and its ASCII code is %i \n",name[i],tester);
  49. tester = tester+key;
  50. //printf ("The ASCII after Encryption is %i \n",tester);
  51. output[i] = (char)tester;
  52. }
  53.  
  54. }
  55. else
  56. {
  57.  
  58. //printf("%c is Neither\n",name[i]);
  59. output[i] = (char)tester;
  60. }
  61.  
  62.  
  63.  
  64.  
  65. }
  66.  
  67. printf("Your Encrypted Messege is --> %s\n\n",output);
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement