/**
 * DevExtreme (esm/__internal/core/license/sha1.js)
 * Version: 23.2.6 (build 24140-0112)
 * Build date: Sun May 19 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import {
    bytesToWords,
    leftRotate,
    stringToBytes,
    wordsToBytes
} from "./byte_utils";
export function preprocess(text) {
    var bytes = new Uint8Array(text.length + 1);
    bytes.set(stringToBytes(text));
    bytes[bytes.length - 1] = 128;
    var words = bytesToWords(new Uint8Array(bytes));
    var result = new Uint32Array(16 * Math.ceil((words.length + 2) / 16));
    result.set(words, 0);
    result[result.length - 1] = 8 * (bytes.length - 1);
    return result
}
export function sha1(text) {
    var message = preprocess(text);
    var h = new Uint32Array([1732584193, 4023233417, 2562383102, 271733878, 3285377520]);
    for (var i = 0; i < message.length; i += 16) {
        var w = new Uint32Array(80);
        for (var j = 0; j < 16; j += 1) {
            w[j] = message[i + j]
        }
        for (var _j = 16; _j < 80; _j += 1) {
            var n = w[_j - 3] ^ w[_j - 8] ^ w[_j - 14] ^ w[_j - 16];
            w[_j] = n << 1 | n >>> 31
        }
        var a = h[0];
        var b = h[1];
        var c = h[2];
        var d = h[3];
        var e = h[4];
        for (var _j2 = 0; _j2 < 80; _j2 += 1) {
            var [f, k] = _j2 < 20 ? [b & c | ~b & d, 1518500249] : _j2 < 40 ? [b ^ c ^ d, 1859775393] : _j2 < 60 ? [b & c | b & d | c & d, 2400959708] : [b ^ c ^ d, 3395469782];
            var temp = leftRotate(a, 5) + f + e + k + w[_j2];
            e = d;
            d = c;
            c = leftRotate(b, 30);
            b = a;
            a = temp
        }
        h[0] += a;
        h[1] += b;
        h[2] += c;
        h[3] += d;
        h[4] += e
    }
    return wordsToBytes(h)
}
