JSFiddle - React, Tailwind, and code Playground

by qwweee7467

HTML

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

JavaScript

/* Get SHA1 by ArrayBuffer */

function GetSHA1byArrayBuffer() {
    try {
        //HTML5 support only
        var reader = new FileReader();
        var file = document.getElementById("fileupload").files[0];
        reader.readAsArrayBuffer(file);
        reader.onloadend = function (evt) {
            //Get SHA1 , refer to ArrayBufferToSHA1.js
            var _sha1 = sha1.hash(evt.target.result);
            document.getElementById("sha1").innerHTML = _sha1;
        };
    } catch (err) {
        document.getElementById("sha1").innerHTML = err;
    }          
}


/**
 * Copyright (c) 2012 T. Michael Keesey
 * LICENSE: http://opensource.org/licenses/MIT
 */
var sha1;
(function (sha1) {
    var POW_2_24 = Math.pow(2, 24);
    var POW_2_32 = Math.pow(2, 32);

    function hex(n) {
        var s = "",
            v;
        for (var i = 7; i >= 0; --i) {
            v = (n >>> (i << 2)) & 15;
            s += v.toString(16);
        }
        return s;
    }

    function lrot(n, bits) {
        return ((n << bits) | (n >>> (32 - bits)));
    }
    var Uint32ArrayBigEndian = (function () {
        function Uint32ArrayBigEndian(length) {
            this.bytes = new Uint8Array(length << 2);
        }
        Uint32ArrayBigEndian.prototype.get = function (index) {
            index <<= 2;
            return (this.bytes[index] * POW_2_24) + ((this.bytes[index + 1] << 16) | (this.bytes[index + 2] << 8) | this.bytes[index + 3]);
        };
        Uint32ArrayBigEndian.prototype.set = function (index, value) {
            var high = Math.floor(value / POW_2_24),
                rest = value - (high * POW_2_24);
            index <<= 2;
            this.bytes[index] = high;
            this.bytes[index + 1] = rest >> 16;
            this.bytes[index + 2] = (rest >> 8) & 255;
            this.bytes[index + 3] = rest & 255;
        };
        return Uint32ArrayBigEndian;
    })();

    function string2ArrayBuffer(s) {
        s = s.replace(/[\u0080-\u07ff]/g, function (c)...