-
Notifications
You must be signed in to change notification settings - Fork 1
/
createHash.js
52 lines (44 loc) · 1.22 KB
/
createHash.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
function randomChar() {
var n = Math.floor(Math.random() * 62);
if (n < 10) {
return n; //0-9
}
if (n < 36) {
return String.fromCharCode(n + 55); //A-Z
}
return String.fromCharCode(n + 61); //a-z
}
function createHash(len) {
var str = '';
while(str.length < len) {
str += randomChar();
return str;
}
}
module.exports = createHash;
// var alphabet = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
// var base = alphabet.length; // base is the length of the alphabet (58 in this case)
// // utility function to convert base 10 integer to base 58 string
// function encode(num){
// var encoded = '';
// while (num){
// var remainder = num % base;
// num = Math.floor(num / base);
// encoded = alphabet[remainder].toString() + encoded;
// }
// return encoded;
// }
// // utility function to convert a base 58 string to base 10 integer
// function decode(str){
// var decoded = 0;
// while (str){
// var index = alphabet.indexOf(str[0]);
// var power = str.length - 1;
// decoded += index * (Math.pow(base, power));
// str = str.substring(1);
// }
// return decoded;
// }
// module.exports.encode = encode;
// module.exports.decode = decode;