card-sharing
Version:
card sharing config generator by parsing online sources
79 lines (66 loc) • 3.04 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var CryptographicBlock = function () {
function CryptographicBlock() {
_classCallCheck(this, CryptographicBlock);
}
_createClass(CryptographicBlock, [{
key: "init",
value: function init(key) {
var len = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : key.length;
this.keytable = [];
for (var i = 0; i < 256; i++) {
this.keytable.push(i);
}
var j = 0;
var aux = null;
for (var _i = 0; _i < 256; _i++) {
j = 0xff & j + key[_i % len] + this.keytable[_i];
aux = this.keytable[_i];
this.keytable[_i] = this.keytable[j];
this.keytable[j] = aux;
}
this.state = key[0];
this.counter = 0;
this.sum = 0;
}
}, {
key: "decrypt",
value: function decrypt(data) {
var len = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : data.length;
for (var i = 0; i < len; i++) {
this.counter = 0xff & this.counter + 1;
this.sum = this.sum + this.keytable[this.counter];
var aux = this.keytable[this.sum & 0xFF];
this.keytable[this.sum & 0xFF] = this.keytable[this.counter];
this.keytable[this.counter] = aux;
var z = data[i];
data[i] = z ^ this.keytable[this.keytable[this.counter] + this.keytable[this.sum & 0xFF] & 0xFF] ^ this.state;
z = data[i];
this.state = 0xff & (this.state ^ z);
}
}
}, {
key: "encrypt",
value: function encrypt(data) {
var len = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : data.length;
if (!len) len = data.length;
for (var i = 0; i < len; i++) {
this.counter = 0xff & this.counter + 1;
this.sum = this.sum + this.keytable[this.counter];
var aux = this.keytable[this.counter];
this.keytable[this.counter] = this.keytable[this.sum & 0xFF];
this.keytable[this.sum & 0xFF] = aux;
var z = data[i];
data[i] = z ^ this.keytable[this.keytable[this.counter & 0xFF] + this.keytable[this.sum & 0xFF] & 0xff] ^ this.state;
this.state = 0xff & (this.state ^ z);
}
}
}]);
return CryptographicBlock;
}();
exports.default = CryptographicBlock;