JSFiddle - React, Tailwind, and code Playground

by qwweee7467

HTML

<input id="fileupload" type="file" name="fileupload">
<input onclick="javascript: GetSHA1ByBinaryString();" id="check" type="button" value="check SHA1"><div id="sha1"></div>

JavaScript

/* Get SHA1 by BinaryString */
function GetSHA1ByBinaryString() {
    try {
        //HTML5 support only
        var reader = new FileReader();
        var file = document.getElementById("fileupload").files[0];
        reader.readAsBinaryString(file);
        reader.onloadend = function (evt) {
            //Get SHA1
            var sha1 = sha_hexdigest(evt.target.result);
            document.getElementById("sha1").innerHTML = sha1;
        };
    } catch (err) {
        document.getElementById("sha1").innerHTML = err;
    }
}

function sha_hexdigest(bytes) {
    var digest = sha_bytes(sha_calculate(sha_ints(bytes), bytes.length * 8));
    var digits = '0123456789abcdef';
    var hex = '';
    for (var i = 0; i < digest.length; i++) {
        var c = digest.charCodeAt(i);
        hex += digits.charAt((c >> 4) & 0xF) + digits.charAt(c & 0xF);
    }
    return hex;
}

function sha_ints(bytes) {
    while (bytes.length % 4 != 0)
    bytes += '\x00';
    var ints = new Array();
    for (var i = 0; i < bytes.length; i += 4) {
        ints[ints.length] = (
        (bytes.charCodeAt(i) & 0xFF) << 24 | (bytes.charCodeAt(i + 1) & 0xFF) << 16 | (bytes.charCodeAt(i + 2) & 0xFF) << 8 | (bytes.charCodeAt(i + 3) & 0xFF));
    }
    return ints;
}

function sha_bytes(ints) {
    var bytes = '';
    for (var i = 0; i < ints.length; i++)
    bytes += String.fromCharCode((ints[i] >> 24) & 0xFF, (ints[i] >> 16) & 0xFF, (ints[i] >> 8) & 0xFF, ints[i] & 0xFF)
    return bytes;
}

function sha_calculate(ints, bitn) {
    while (ints.length * 32 <= bitn) ints[ints.length] = 0;
    ints[ints.length - 1] |= 1 << (31 - bitn % 32)
    while (ints.length % 16 != 14) ints[ints.length] = 0;
    ints[ints.length] = Math.floor(bitn / 0x100000000);
    ints[ints.length] = bitn & 0xFFFFFFFF;

    var h0 = 1732584193,
        h1 = -271733879,
        h2 = -1732584194,
        h3 = 271733878,
        h4 = -1009589776;
    var a, b, c, d, e, f, k, temp, w = new Array(80);
    for (var inti = 0;...