123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- "use strict";
- class StringXor {
- constructor() {
-
- this._value = undefined;
- }
-
- add(str) {
- const len = str.length;
- const value = this._value;
- if (value === undefined) {
-
- const newValue = (this._value = Buffer.allocUnsafe(len));
- for (let i = 0; i < len; i++) {
- newValue[i] = str.charCodeAt(i);
- }
- return;
- }
- const valueLen = value.length;
- if (valueLen < len) {
- const newValue = (this._value = Buffer.allocUnsafe(len));
- let i;
- for (i = 0; i < valueLen; i++) {
- newValue[i] = value[i] ^ str.charCodeAt(i);
- }
- for (; i < len; i++) {
- newValue[i] = str.charCodeAt(i);
- }
- } else {
- for (let i = 0; i < len; i++) {
- value[i] = value[i] ^ str.charCodeAt(i);
- }
- }
- }
-
- toString() {
- const value = this._value;
- return value === undefined ? "" : value.toString("latin1");
- }
-
- updateHash(hash) {
- const value = this._value;
- if (value !== undefined) hash.update(value);
- }
- }
- module.exports = StringXor;
|