You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cfb8.js 518B

12345678910111213141516171819202122232425
  1. var Buffer = require('safe-buffer').Buffer
  2. function encryptByte (self, byteParam, decrypt) {
  3. var pad = self._cipher.encryptBlock(self._prev)
  4. var out = pad[0] ^ byteParam
  5. self._prev = Buffer.concat([
  6. self._prev.slice(1),
  7. Buffer.from([decrypt ? byteParam : out])
  8. ])
  9. return out
  10. }
  11. exports.encrypt = function (self, chunk, decrypt) {
  12. var len = chunk.length
  13. var out = Buffer.allocUnsafe(len)
  14. var i = -1
  15. while (++i < len) {
  16. out[i] = encryptByte(self, chunk[i], decrypt)
  17. }
  18. return out
  19. }