Advertisement
Cinestra

Old Encrypt Solution

Dec 30th, 2022
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. string encrypt(const string& s, int n) {
  2.  
  3. int real_shift = n % 26;
  4. string new_string = "";
  5. for (int i = 0; i < s.length(); i++) {
  6. if (s[i] != ' ') {
  7. if (s[i] + real_shift > 'z') {
  8. new_string += s[i] + real_shift - 'z' + 96;
  9. }
  10. else {
  11. new_string += s[i] + real_shift;
  12. }
  13.  
  14. }
  15. else {
  16. new_string += ' ';
  17. }
  18. }
  19.  
  20. return new_string;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement