blob: 98ca38ecc02325e3fb121a3db351de3c20ac06c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
// Generated by CoffeeScript 1.9.2
var Buffer, create;
Buffer = require('buffer').Buffer;
create = require('./create');
module.exports = create('xmodem', function(buf, previous) {
var code, count, crc, i;
if (!Buffer.isBuffer(buf)) {
buf = Buffer(buf);
}
crc = previous != null ? ~~previous : 0x0;
count = buf.length;
i = 0;
while (count > 0) {
code = crc >>> 8 & 0xFF;
code ^= buf[i++] & 0xFF;
code ^= code >>> 4;
crc = crc << 8 & 0xFFFF;
crc ^= code;
code = code << 5 & 0xFFFF;
crc ^= code;
code = code << 7 & 0xFFFF;
crc ^= code;
count--;
}
return crc;
});
|