MCPcopy Create free account
hub / github.com/PaperDebugger/paperdebugger / generateSHA1Hash

Function generateSHA1Hash

webapp/_webapp/src/libs/helpers.ts:106–173  ·  view source on GitHub ↗
(inputString: string)

Source from the content-addressed store, hash-verified

104}
105
106export function generateSHA1Hash(inputString: string): string {
107 const encoder = new TextEncoder();
108 const uint8Array = encoder.encode(inputString);
109
110 const m = bytesToWords(uint8Array);
111 const l = uint8Array.length * 8;
112 const w = [];
113 let H0 = 1732584193;
114 let H1 = -271733879;
115 let H2 = -1732584194;
116 let H3 = 271733878;
117 let H4 = -1009589776;
118
119 // Padding
120 m[l >> 5] |= 0x80 << (24 - (l % 32));
121 m[(((l + 64) >>> 9) << 4) + 15] = l;
122
123 for (let i = 0; i < m.length; i += 16) {
124 const a = H0;
125 const b = H1;
126 const c = H2;
127 const d = H3;
128 const e = H4;
129
130 for (let j = 0; j < 80; j++) {
131 if (j < 16) w[j] = m[i + j];
132 else {
133 const n: number = w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16];
134 w[j] = (n << 1) | (n >>> 31);
135 }
136
137 const t =
138 ((H0 << 5) | (H0 >>> 27)) +
139 H4 +
140 (w[j] >>> 0) +
141 (j < 20
142 ? ((H1 & H2) | (~H1 & H3)) + 1518500249
143 : j < 40
144 ? (H1 ^ H2 ^ H3) + 1859775393
145 : j < 60
146 ? ((H1 & H2) | (H1 & H3) | (H2 & H3)) - 1894007588
147 : (H1 ^ H2 ^ H3) - 899497514);
148
149 H4 = H3;
150 H3 = H2;
151 H2 = (H1 << 30) | (H1 >>> 2);
152 H1 = H0;
153 H0 = t;
154 }
155
156 H0 += a;
157 H1 += b;
158 H2 += c;
159 H3 += d;
160 H4 += e;
161 }
162
163 const result = wordsToBytes([H0, H1, H2, H3, H4]);

Callers 1

main.tsxFile · 0.90

Calls 2

bytesToWordsFunction · 0.85
wordsToBytesFunction · 0.85

Tested by

no test coverage detected