Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <head>
  <meta charset="UTF-8">
  <title>
    256-bit Hash Generator using Browser's Own SHA-256 Algorithm
  </title>
</head>
<body>
  <div id="inputForm">
    <textarea rows="20" cols="100" id="textImages" tabindex=0></textarea>
    <div id="nonce">
      <span style="font-size: 2em">
        <textarea rows="1" cols="20" id="textNonce"
                          style="font-size:1.5em; color:red" tabindex=0>
                </textarea></span>
      <input type="button" id="btnCompleteHash" value="⇥" style="font-size: 2em"/>
 	  </div>
  </div>
  <p></p>
  <div class="flex-container">
    <div id="hash"></div>
    <div id="lsn"></div>
  </div>
</body>
              
            
!

CSS

              
                    body {
      font-family: sans-serif
    }
    #nonce {
      display: grid;
      height: 100px;
      align-items: center;
      grid-template-columns: repeat(6, 1fr);
      grid-template-rows: 100px;
    }
    #nonce span {
      grid-column: 1 / 5;
    }
    #nonce #btnIncrement {
      grid-column-start: 5;
    }
    #nonce #cmp {
      grid-column-start: 6;
    }
    #hash {
      color: darkblue;
      font-size: 1.425em;
      font-weight: 600;
      font-family: monospace;
    }
              
            
!

JS

              
                var el = document.getElementById("hash");
var hashHexValue = "";
var crypto = window.crypto || window.msCrypto;
var fieldNonce = document.getElementById("textNonce");
const difficulty = 3;

if (!crypto.subtle) { alert("Cryptography API not Supported") };

async function rollHash() {
  var promise = await crypto.subtle.digest({name: "SHA-256"}, str2ab(document.getElementById("textImages").value + fieldNonce.value));
  hashHexValue = ab2hex(promise);
  if (hashHexValue.substring(0, difficulty) == Array(difficulty + 1).join("0")) {
    lastSuccessfulNonce = "LSN: " + hashHexValue + ", " + fieldNonce.value;
    document.getElementById("lsn").textContent = lastSuccessfulNonce;
    var el = document.getElementById("textImages");
    el.value += "\r\n" + lastSuccessfulNonce;
    el.scrollTop = el.scrollHeight;
  }
}

function ab2hex(buffer) { // buffer is an ArrayBuffer
  return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
}

function ab2binary(buffer) { // buffer is an ArrayBuffer
  return Array.prototype.map.call(new Uint8Array(buffer), x => ('00000000' + x.toString(2)).slice(-8)).join('');
}

function ab2str(buf) {
  return String.fromCharCode.apply(null, new Uint16Array(buf));
}

function str2ab(str) {
  var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
  var bufView = new Uint16Array(buf);
  for (var i=0, strLen=str.length; i < strLen; i++) {
    bufView[i] = str.charCodeAt(i);
  }
  return buf;
}

var buttonCompleteHash = document.getElementById("btnCompleteHash");

textImages.onpaste = function (event) {
  rollHash();
  fieldNonce.value = -1;
  document.getElementById("hash").textContent = hashHexValue;
}

buttonCompleteHash.onclick = function () {
  if (document.getElementById("btnCompleteHash").value === "⇥") {
    document.getElementById("btnCompleteHash").value = "◼";
    intervalHundredths = window.setInterval (function () {
      fieldNonce.value = parseInt(fieldNonce.value) + 1;
      rollHash();
    }, 0.01);
    intervalTenths = window.setInterval (function () {
      document.getElementById("hash").textContent = hashHexValue;
    }, 10);      
  } else {
    document.getElementById("btnCompleteHash").value = "⇥";
    clearInterval(intervalHundredths);
    clearInterval(intervalTenths);
  }
};

function myCheck() {
  // Get the checkbox
  var checkBox = document.getElementById("myCheck1");
  // Get the output text
  var text = document.getElementById("text");

  // If the checkbox is checked, display the output text
  if (checkBox.checked == true){
    text.style.display = "inline-block";
  } else {
    text.style.display = "none";
  }
}
              
            
!
999px

Console