Guest User

Untitled

a guest
Nov 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void Cipher(char *_Origin, int _Key);
  5.  
  6. void main()
  7. {
  8. Cipher("CAT", 3);
  9. Cipher("CABBAGE", 3);
  10. Cipher("TEST", 8);
  11. Cipher("HELLO, WORLD!", 5);
  12. }
  13.  
  14. void Cipher(char * _Origin, int _Key)
  15. {
  16. int Size = 0;
  17. do Size++;
  18. while (*(_Origin + Size) != '\0');
  19. char *Ciphered = new char[Size+1];
  20.  
  21. for (int i = 0;i < Size;i++)
  22. {
  23. if (((int)*(_Origin + i)) < 65 || ((int)*(_Origin + i)) > 90)
  24. {
  25. Ciphered[i] = (int)*(_Origin + i);
  26. }
  27. else if (((int)*(_Origin + i)) + _Key > 90)
  28. {
  29. Ciphered[i] = ((int)*(_Origin + i)) + _Key - 26;
  30. }
  31. else
  32. {
  33. Ciphered[i] = ((int)*(_Origin + i)) + _Key;
  34. }
  35. }
  36. Ciphered[Size] = '\0';
  37.  
  38. cout << Ciphered << endl;
  39.  
  40. delete[] Ciphered;
  41. }
Add Comment
Please, Sign In to add comment