Projekt

Obecné

Profil

Stáhnout (518 Bajtů) Statistiky
| Větev: | Revize:
1
var Buffer = require('safe-buffer').Buffer
2

    
3
function encryptByte (self, byteParam, decrypt) {
4
  var pad = self._cipher.encryptBlock(self._prev)
5
  var out = pad[0] ^ byteParam
6

    
7
  self._prev = Buffer.concat([
8
    self._prev.slice(1),
9
    Buffer.from([decrypt ? byteParam : out])
10
  ])
11

    
12
  return out
13
}
14

    
15
exports.encrypt = function (self, chunk, decrypt) {
16
  var len = chunk.length
17
  var out = Buffer.allocUnsafe(len)
18
  var i = -1
19

    
20
  while (++i < len) {
21
    out[i] = encryptByte(self, chunk[i], decrypt)
22
  }
23

    
24
  return out
25
}
(4-4/9)