<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<h1>speakCrypt</h1>
<input id="int" type="number" tabindex="0" placeholder="Integer to encrypt" />
<input id="salt" type="text" tabindex="0" placeholder="Salt" />
<input id="result" type="text" tabindex="0" disabled="disabled" />
</body>
</html>
$(function(){
$('#int, #salt').on('input', function () {
if ( $('#int').val() == '' ) return $('#result').val('');
var res = speakCrypt($('#int').val(), $('#salt').val());
$('#result').val(res);
});
$('#int').val(Math.ceil(Math.random() * 10000)).trigger('input');
});
function speakCrypt (int, salt, dict) {
dict = dict || [
'a,e,i,o,u,oi,ou,ai,au,on,in',
'b,c,d,f,g,j,k,l,m,n,p,r,s,t,v,w,x,y,z,bl,ch,cl,cr,dr,fl,tr,br'
];
if (!isFinite(int) || int < 0)
throw new TypeError('First argument must be a positive finite number.');
// Alternate vowel-first and consonant-first syllables
// depending on whether the int is pair or not
var mod = (int % 2 === 0) ? 0 : 1;
// Generate all syllables
var syllables = [];
dict[ mod ].split(',').forEach(function (first) {
dict[ (mod+1) % 2 ].split(',').forEach(function (second) {
syllables.push(first + second);
});
});
// If there's a salt, use it to consistently shuffle the syllables
if (salt) {
var charCode, j, i, v, p; salt += '';
for (i = syllables.length - 1, v = 0, p = 0; i > 0; i--, v++) {
v %= salt.length;
p += charCode = salt.charAt(v).charCodeAt(0);
j = (charCode + v + p) % i;
syllables.splice(j, 0, syllables.splice(i, 1)[0]);
}
}
// Find how many steps to look for
var steps = Math.ceil(Math.log(int) / Math.log(syllables.length));
if (steps < 2) steps = 1;
// Deduce syllables from steps
var result = '', steppedIndex;
for (var i = steps; i > 0; i--) {
steppedIndex = Math.floor(int / Math.pow(syllables.length, i - 1));
result += syllables[ Math.floor((steppedIndex % syllables.length) / 2) ];
}
return result;
}
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |