Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. let u = "I should have known that you would have a perfect answer for me!!!";
  2.  
  3. function movingShift(s, shift) {
  4. let arr = [];
  5.  
  6. s.split("").forEach((x, idx) => {
  7. let source = x.toUpperCase().charCodeAt(0);
  8. if (source < 65 || source > 90) {
  9. arr.push(x);
  10. shift++;
  11. return;
  12. }
  13. let index = (source - 65 + (shift)) % 26 + 65;
  14. let letter = String.fromCharCode(index);
  15. x === x.toLowerCase() ? arr.push(letter.toLowerCase()) : arr.push(letter);
  16. shift++;
  17. })
  18.  
  19. let cipher = arr.join("");
  20. return cipher;
  21. }
  22.  
  23. let v = movingShift(u, 1);
  24.  
  25. function demovingShift(v, shift) {
  26. shift = -1;
  27. let arr = [];
  28. v.split("").forEach((x, idx) => {
  29. let source = x.toUpperCase().charCodeAt(0);
  30. if (source < 65 || source > 90) {
  31. arr.push(x);
  32. shift--;
  33. return;
  34. }
  35. let index = (source - 65 + (shift)) % 26 + 65;
  36. let letter = String.fromCharCode(index);
  37. x === x.toLowerCase() ? arr.push(letter.toLowerCase()) : arr.push(letter);
  38. shift--;
  39. })
  40. return arr.join("");
  41. }
  42.  
  43. console.log(movingShift(u, 1));
  44. console.log(demovingShift(v, 1));
  45.  
  46. J vltasl rlhr zdfog odxr ypw atasl rlhr p gwkzzyq zntyhv lvz wp!!!
  47.  
  48. I sho;ld ha<e k45=4 :.a: ?5; =5;2* .a<+ a 6+8,+): a49=+8 ,58 3+!!!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement