MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / sha1Bytes

Function sha1Bytes

graph-ui/src/core/hash.ts:64–107  ·  view source on GitHub ↗

sha1 einer Bytefolge, synchron.

(bytes: Uint8Array)

Source from the content-addressed store, hash-verified

62
63/** sha1 einer Bytefolge, synchron. */
64function sha1Bytes(bytes: Uint8Array): string {
65 const words = padded(bytes);
66 const h = new Uint32Array([0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]);
67 const w = new Uint32Array(80);
68
69 for (let block = 0; block < words.length; block += 16) {
70 for (let i = 0; i < 16; i += 1) {
71 w[i] = words[block + i];
72 }
73 for (let i = 16; i < 80; i += 1) {
74 w[i] = rotl(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
75 }
76 let [a, b, c, d, e] = [h[0], h[1], h[2], h[3], h[4]];
77 for (let i = 0; i < 80; i += 1) {
78 let f: number;
79 let k: number;
80 if (i < 20) {
81 f = (b & c) | (~b & d);
82 k = 0x5a827999;
83 } else if (i < 40) {
84 f = b ^ c ^ d;
85 k = 0x6ed9eba1;
86 } else if (i < 60) {
87 f = (b & c) | (b & d) | (c & d);
88 k = 0x8f1bbcdc;
89 } else {
90 f = b ^ c ^ d;
91 k = 0xca62c1d6;
92 }
93 const temp = (rotl(a, 5) + f + e + k + w[i]) >>> 0;
94 e = d;
95 d = c;
96 c = rotl(b, 30);
97 b = a;
98 a = temp;
99 }
100 h[0] = (h[0] + a) >>> 0;
101 h[1] = (h[1] + b) >>> 0;
102 h[2] = (h[2] + c) >>> 0;
103 h[3] = (h[3] + d) >>> 0;
104 h[4] = (h[4] + e) >>> 0;
105 }
106 return toHex(h);
107}
108
109const SHA256_K = new Uint32Array([
110 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,

Callers 1

sha1HexFunction · 0.85

Calls 3

paddedFunction · 0.85
rotlFunction · 0.85
toHexFunction · 0.85

Tested by

no test coverage detected