UNPKG

niceware

Version:

Utility for generating memorable passwords and converting random bytes into human-readable phrases

118 lines (115 loc) 5.85 kB
<html> <head> <meta charset="utf8"/> <meta name="viewport" content="width=device-width"/> <title>Niceware</title> </head> <body> <a href="https://github.com/diracdeltas/niceware"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a> <div style='width: 75%; margin: auto; margin-top: 100px; font-size: 20px;'> <h2>Niceware</h2> <p> <a href="https://www.npmjs.com/package/niceware" target="_blank">Niceware</a> words are chosen at random from a list of 65,536 English language words. Each word has 16 bits of entropy. An 8-word random passphrase has 128 bits of entropy which is strong enough to use for cryptographic keys. </p> <p> In comparison, words chosen from a standard Diceware list with 7,776 words have ~12.92 bits of entropy per word and therefore require more words to achieve the same security level. </p> <p> Niceware can also be used to convert existing cryptographic keys and other random bytes into human-readable phrases. </p> <p> Niceware is also available as a <a href='https://pypi.python.org/pypi/niceware'>pip module</a>, <a href='https://www.npmjs.com/package/nicepass'>CLI</a>, and <a href='https://chrome.google.com/webstore/detail/niceware-password/dhnichgmciickpnnnhfcljljnfomadag'>Chrome extension</a>, thanks to people who are not me. </p> <div> <h3>Demo #1: Generate a Passphrase</h3> <p style='font-size: 18px'> <b>**For demonstration purposes only! You should not trust a third-party online tool to generate your passwords.**</b> </p> Passphrase strength: <select name='size'> <option value='2'>16 bits</option> <option value='4'>32 bits</option> <option value='6'>48 bits</option> <option value='8'>64 bits</option> <option value='10' selected>80 bits</option> <option value='12'>96 bits</option> <option value='14'>112 bits</option> <option value='16'>128 bits</option> </select> <button onclick="generatePassphrase()">Generate passphrase</button> <pre id="output" style="color:green;"></pre> </div><div style='margin-top: 40px;'> <h3>Demo #2: Convert hex to a fun phrase</h3> <textarea placeholder='Enter some hex in here:' style='margin-bottom: 10px; width:400px; height:100px;'></textarea> <div> <button onclick="hexToWords()">Convert to words</button> <span style='color: red; font-size: 16px;' id='error'></span> </div> <pre id="output2" style='margin-top: 10px; color: green'></pre> </div><div> <h3>Demo #3: Convert a Niceware phrase to hex</h3> <input placeholder='Enter phrase here:' style='margin-bottom: 10px; width:400px;' /> <div> <button onclick="wordsToHex()">Convert to hex</button> <span style='color: red; font-size: 16px;' id='error2'></span> </div> <pre id="output3" style='margin-top: 10px; color: green'></pre> </div> </div> <script src='browser/niceware.js' integrity="sha256-RGerdpbBHOeZyAKRRekyPf6DadvMV3c+clPCExwL2Bs=" crossorigin="anonymous"></script> <script> function generatePassphrase () { var e = document.querySelector('select') var size = e.options[e.selectedIndex].value var passphrase = window.niceware.generatePassphrase(Number(size)) document.getElementById("output").innerText = passphrase.join(' ') } function hexToWords () { document.querySelector('#error').innerText = '' var text = document.querySelector('textarea').value try { text = text.toLowerCase().replace(/[,\s]/g, '') if (text.length % 2 === 1) { text = '0' + text } const arr = new Uint8Array(text.length / 2) for (var i = 0; i < text.length / 2; i++) { let val = Number('0x' + text[2 * i] + text[2 * i + 1]) if (val >= 0 && val < 256) { arr[i] = val } else { throw new Error('Text must be hex-encoded.') } } document.getElementById("output2").innerText = window.niceware.bytesToPassphrase(arr).join(' ') } catch (e) { document.querySelector('#error').innerText = 'Error: ' + e.message } } function wordsToHex () { document.querySelector('#error2').innerText = '' var text = document.querySelector('input').value try { text = text.toLowerCase().replace(/,/g, ' ').replace(/\s+/g, ' ') const byteArray = window.niceware.passphraseToBytes(text.split(' ')) var str = '' for (var i = 0; i < byteArray.length; i++) { let char = byteArray[i].toString(16) if (char.length === 1) { char = '0' + char } str = str + char } document.getElementById("output3").innerText = str } catch (e) { document.querySelector('#error2').innerText = 'Error: ' + e.message } } </script> </body> </html>