Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// encrypt.js

/* global adventurejs A */

/**
 * Encrypt a string. Used to make point and hint data non human readable via encryption.
 * @method adventurejs#encrypt
 * @memberOf adventurejs
 * @param {String} text
 * @returns {String}
 */
adventurejs.encrypt = function Adventurejs_encrypt(text, key = "a") {
  let result = "";
  for (let i = 0; i < text.length; i++) {
    const charCode = text.charCodeAt(i) ^ key.charCodeAt(i % key.length);
    result += String.fromCharCode(charCode);
  }
  return result;
};