Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. string key = argv[1];
  2.  
  3. for (int i = 0, k = strlen(key); i < k; i++)
  4. {
  5. if (isdigit(key[i]))
  6. {
  7. printf("Please give an alphabetical keyn");
  8. return 1;
  9. }
  10. }
  11.  
  12. string plain = GetString ();
  13. int j = 0;
  14. int plainn = strlen(plain);
  15.  
  16.  
  17. for (int i = 0; i < plainn; i++)
  18. {
  19. if (j>=(strlen(argv[1])))
  20. {
  21. j = 0;
  22. }
  23.  
  24. if (islower(key[j]))
  25. {
  26. key[j] = key[j] - 97;
  27. }
  28.  
  29. else if (isupper(key[j]))
  30. {
  31. key[j] = key[j] - 65;
  32. }
  33.  
  34. if (isalpha(plain[i]))
  35. {
  36. if (islower(plain[i]))
  37. {
  38. printf("%c", (((( plain[i]-'a')+(key[j++]))%26)+'a'));
  39.  
  40. }
  41.  
  42. else
  43. {
  44. printf("%c", (((( plain[i]-'A')+(key[j++]))%26)+'A'));
  45.  
  46. }
  47. }
  48.  
  49. else
  50. {
  51. printf("%c", plain[i]);
  52. }
  53. }
  54. printf("n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement