Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81152 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule adler32
10
*/
11
12
/* jslint bitwise:true */
13
14
"use strict";
15
16
var MOD = 65521;
17
18
// This is a clean-room implementation of adler32 designed for detecting
19
// if markup is not what we expect it to be. It does not need to be
20
// cryptographically strong, only reasonably good at detecting if markup
21
// generated on the server is different than that on the client.
22
function adler32(data) {
23
var a = 1;
24
var b = 0;
25
for (var i = 0; i < data.length; i++) {
26
a = (a + data.charCodeAt(i)) % MOD;
27
b = (b + a) % MOD;
28
}
29
return a | (b << 16);
30
}
31
32
module.exports = adler32;
33
34