0

I'm trying to recreate a text converter ultimately simular to rot13.com. However I don't know how to make it convert specific characters to another character. If I wanted to input;

example

Then I would want the output to be

rcszqar

Some more;

abc > snv

foo > gpp

bar > nst

I'm using return String.fromCharCode((c <= 'Z' ? 90 : 122) >= (c = c.charCodeAt(0) + i) ? c : c - 26);

But no matter what numbers I change in that line, none of them are replaced correctly.

Community
  • 1
  • 1
ZW443
  • 1
  • 2

1 Answers1

0

The function is documented here: http://stackoverflow.com/a/617685/987044

        function rot(s, i) {            return s.replace(/[a-zA-Z]/g, function (c) {
                return String.fromCharCode((c <= 'Z' ? 90 : 122) >= (c = c.charCodeAt(0) + i) ? c : c - 26);            });         }       function update() {             document.getElementById('output').value = rot(document.getElementById('input').value,
+document.getElementById('rot').value);         }

The only number you need to change is the variable i when calling the function. For example

rot ("example", 13);//->"rcszqar"
grateful
  • 1,128
  • 13
  • 25