You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
398 B

  1. 'use strict';
  2. var randomByte = require('./random/random-byte');
  3. function encode(lookup, number) {
  4. var loopCounter = 0;
  5. var done;
  6. var str = '';
  7. while (!done) {
  8. str = str + lookup( ( (number >> (4 * loopCounter)) & 0x0f ) | randomByte() );
  9. done = number < (Math.pow(16, loopCounter + 1 ) );
  10. loopCounter++;
  11. }
  12. return str;
  13. }
  14. module.exports = encode;