Sha256: 93b44019393a5923f333967581cbfdc34f52010f50002f89ca71bae74a5fe1a6

Contents?: true

Size: 1.08 KB

Versions: 68

Compression:

Stored size: 1.08 KB

Contents

var RotationalCipher = function () {};

RotationalCipher.prototype.rotate = function (text, shiftKey) {
  if (text.length === 1) {
    if (text.charCodeAt(0) >= 97 && text.charCodeAt(0) <= 122) return this.rotateLowerCase(text, shiftKey);
    if (text.charCodeAt(0) >= 65 && text.charCodeAt(0) <= 90) return this.rotateUpperCase(text, shiftKey);
    return text;
  }
  return this.rotate(text.charAt(0), shiftKey) + this.rotate(text.slice(1), shiftKey);
};

RotationalCipher.prototype.rotateLowerCase = function (letter, shiftKey) {
  var rotatedLowerCase = String.fromCharCode(letter.charCodeAt(0) + shiftKey);
  if (rotatedLowerCase.charCodeAt(0) > 122) rotatedLowerCase = String.fromCharCode(rotatedLowerCase.charCodeAt(0) - 26);
  return rotatedLowerCase;
};

RotationalCipher.prototype.rotateUpperCase = function (letter, shiftKey) {
  var rotatedUpperCase = String.fromCharCode(letter.charCodeAt(0) + shiftKey);
  if (rotatedUpperCase.charCodeAt(0) > 90) rotatedUpperCase = String.fromCharCode(rotatedUpperCase.charCodeAt(0) - 26);
  return rotatedUpperCase;
};

module.exports = RotationalCipher;

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.138 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.137 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.136 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.135 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.134 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.133 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.132 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.131 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.130 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.129 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.128 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.127 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.126 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.125 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.124 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.123 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.122 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.121 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.120 tracks/javascript/exercises/rotational-cipher/example.js