{"size": 1547, "ext": "js", "max_stars_repo_path": "cipher.js", "max_stars_repo_name": "kazumaki/testing-practice", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cipher.js", "max_issues_repo_name": "kazumaki/testing-practice", "max_issues_repo_issues_event_min_datetime": "2021-05-11T10:01:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-11T10:01:32.000Z", "max_forks_repo_path": "cipher.js", "max_forks_repo_name": "kazumaki/testing-practice", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 34.3777777778, "max_line_length": 126, "alphanum_fraction": 0.5804783452}
const cipher = (() => {
  const offset = 2;

  const utilityFunction = (string, encrypt) => {
    const stringArray = string.split('');

    const encryptedArray = stringArray.map((char) => {
      if ((char.charCodeAt(0) < 'a'.charCodeAt(0) || char.charCodeAt(0) > 'z'.charCodeAt(0))
          && (char.charCodeAt(0) < 'A'.charCodeAt(0) || char.charCodeAt(0) > 'Z'.charCodeAt(0))) {
        return char;
      }

      let newKeyCode;

      if (encrypt) {
        newKeyCode = char.charCodeAt(0) + (offset % 26);

        if (char.toUpperCase() === char) {
          newKeyCode = newKeyCode > 'Z'.charCodeAt(0) ? 'A'.charCodeAt(0) + newKeyCode - 'Z'.charCodeAt(0) - 1 : newKeyCode;
        } else {
          newKeyCode = newKeyCode > 'z'.charCodeAt(0) ? 'a'.charCodeAt(0) + newKeyCode - 'z'.charCodeAt(0) - 1 : newKeyCode;
        }
      } else {
        newKeyCode = char.charCodeAt(0) - (offset % 26);

        if (char.toUpperCase() === char) {
          newKeyCode = newKeyCode < 'A'.charCodeAt(0) ? 'Z'.charCodeAt(0) - ('A'.charCodeAt(0) - newKeyCode) + 1 : newKeyCode;
        } else {
          newKeyCode = newKeyCode < 'a'.charCodeAt(0) ? 'z'.charCodeAt(0) - ('a'.charCodeAt(0) - newKeyCode) + 1 : newKeyCode;
        }
      }

      return String.fromCharCode(newKeyCode);
    });

    return encryptedArray.join('');
  };

  const encryptString = (string) => utilityFunction(string, true);
  const decryptString = (string) => utilityFunction(string, false);

  return { encryptString, decryptString };
})();

export default cipher;