Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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

              
                <textarea id="jsonData"></textarea>
<button  >Check</button>

<p id="log">Enter you JSON data and click the check button</p>
              
            
!

CSS

              
                textarea {
  width: 500px;
}
              
            
!

JS

              
                import cryptoEs from "https://cdn.skypack.dev/crypto-es@1.2.7";

let MAX_ROLL = 100000;

$('button').click(function checkData() {
  let jsonArea = $("#jsonData");

  let log = $("#log");
  
  try {
    let jsonValue = JSON.parse(jsonArea.val());
    let privateKey = jsonValue.server_seed;
    let nonce = jsonValue.nonce;
    let clientSeed = jsonValue.client_seed;
    console.log(privateKey, clientSeed, nonce)
    let hmacValue = getRollHash(privateKey, clientSeed, nonce);
    let roll = getRoll(getHexaValue(hmacValue));
    
    log.html("Generated roll is " + roll + "<br> It should be " + jsonValue.roll);
  } catch (e) {
    log.text("Invalid JSON");
  }
});



function getRollHash(privateKey, publicKey, nonce) {
  let hmac = cryptoEs.HmacSHA256(publicKey + "-" + nonce, privateKey);

  return hmac.toString();
}

function getHexaValue(hash) {
  console.log(hash);
  return hash.substring(0, 10);
}

function getRoll(hexaNumber) {
  let decimalValue = parseInt(hexaNumber, 16);

  return (decimalValue % MAX_ROLL) + 1;
}

              
            
!
999px

Console