"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _lodash = _interopRequireDefault(require("lodash"));

var DKA = function DKA(config) {
  (0, _classCallCheck2["default"])(this, DKA);
  (0, _defineProperty2["default"])(this, "encode", function () {
    var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
    var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.config.key;
    var mReturnData = null;
    var arrayData = [];
    var mKeys = Buffer.alloc(200, key, "utf-8").readBigUInt64BE();
    var OriString = text.toString().split("");
    var OriKey = mKeys.toString().split(""); //######### STEP 2 #############################################

    var num = 0;
    OriString.forEach(function (step1item) {
      var convertAlphabetToInt = step1item.charCodeAt(0);
      arrayData.push(parseInt(convertAlphabetToInt) + parseInt(OriKey[num]));
      num === OriKey.length - 1 ? num = 0 : num++;
    });
    var hasil = '';
    arrayData.forEach(function (item) {
      hasil += String.fromCharCode(item);
    }); //######### END STEP 2 #############################################

    mReturnData = hasil;
    return mReturnData;
  });
  (0, _defineProperty2["default"])(this, "decode", function () {
    var StringEnc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
    var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.config.key;
    var mReturnData = null;
    var arrayData = [];
    var mKeys = Buffer.alloc(200, key, "utf-8").readBigUInt64BE();
    console.log(mKeys);
    var OriString = StringEnc.toString().split("");
    var OriKey = mKeys.toString().split("");
    var num = 0;
    OriString.forEach(function (step1item) {
      var convertAlphabetToInt = step1item.charCodeAt(0);
      arrayData.push(parseInt(convertAlphabetToInt) - parseInt(OriKey[num]));
      num === OriKey.length - 1 ? num = 0 : num++;
    });
    var hasil = '';
    arrayData.forEach(function (item) {
      hasil += String.fromCharCode(item);
    });
    mReturnData = hasil;
    /**
     mReturnData = decrypted.toString();*/
    //mReturnData = { iv : mSplitText[0], enc : mSplitText[1]}

    return mReturnData;
  });
  this.config = _lodash["default"].extend({
    alg: 'default',
    key: 10028
  }, config);
};

var _default = DKA;
exports["default"] = _default;
//# sourceMappingURL=index.js.map