Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let u = "I should have known that you would have a perfect answer for me!!!";
- function movingShift(s, shift) {
- let arr = [];
- s.split("").forEach((x, idx) => {
- let source = x.toUpperCase().charCodeAt(0);
- if (source < 65 || source > 90) {
- arr.push(x);
- shift++;
- return;
- }
- let index = (source - 65 + (shift)) % 26 + 65;
- let letter = String.fromCharCode(index);
- x === x.toLowerCase() ? arr.push(letter.toLowerCase()) : arr.push(letter);
- shift++;
- })
- let cipher = arr.join("");
- return cipher;
- }
- let v = movingShift(u, 1);
- function demovingShift(v, shift) {
- shift = -1;
- let arr = [];
- v.split("").forEach((x, idx) => {
- let source = x.toUpperCase().charCodeAt(0);
- if (source < 65 || source > 90) {
- arr.push(x);
- shift--;
- return;
- }
- let index = (source - 65 + (shift)) % 26 + 65;
- let letter = String.fromCharCode(index);
- x === x.toLowerCase() ? arr.push(letter.toLowerCase()) : arr.push(letter);
- shift--;
- })
- return arr.join("");
- }
- console.log(movingShift(u, 1));
- console.log(demovingShift(v, 1));
- J vltasl rlhr zdfog odxr ypw atasl rlhr p gwkzzyq zntyhv lvz wp!!!
- 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