fork download
  1. #include <stdio.h>
  2. int main()
  3. {
  4. char str[100];
  5. int key, i=0, left;
  6. printf("Enter your plain text : ");
  7. scanf("%[^\n]s",str);
  8. printf("Enter the key : ");
  9. scanf("%d",&key);
  10. if(key==0)
  11. {
  12. printf("INVALID INPUT");
  13. }
  14. else
  15. {
  16. while(str[i]!='\0')
  17. {
  18. //printf("%d\n", str[i]);
  19. if(str[i]>=48 && str[i]<=57)
  20. {
  21. if(str[i]+key<=57)
  22. {
  23. str[i] = str[i] + key;
  24. }
  25. else
  26. {
  27. left = (str[i] + key) - 57;
  28. str[i] = 47 + left;
  29. }
  30. }
  31. else if(str[i]>=65 && str[i]<=90)
  32. {
  33. if(str[i]+key<=90)
  34. {
  35. str[i] = str[i] + key;
  36. }
  37. else
  38. {
  39. left = (str[i] + key) - 90;
  40. str[i] = 64 + left;
  41. }
  42. }
  43. else if(str[i]>=97 && str[i]<=122)
  44. {
  45. if(str[i]+key<=122)
  46. {
  47. str[i] = str[i] + key;
  48. }
  49. else
  50. {
  51. left = (str[i] + key) - 122;
  52. str[i] = 96 + left;
  53. }
  54. }
  55. i++;
  56. }
  57. printf("The encrypted text is : %s",str);
  58. }
  59. return 0;
  60. }
Success #stdin #stdout 0s 4676KB
stdin
Standard input is empty
stdout
Enter your plain text : Enter the key : INVALID INPUT