-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
87 lines (56 loc) · 1.94 KB
/
script.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// # Hashing
// #1 - something to hash - arbitary data structure (signature, checking equality between objects, passwords, validation)
// #2 - do something to change it - deterministically process data (always get the same output given the same input)
// #3 - display/return the hash - get the same integer out, i.e. data in === data out
// require only needed for ourHashingFunctionUsingCryptoLibrary solution
// import library from node (implementation specific)
const {
createHash
} = require('node:crypto');
function ourHashingFunctionUsingCryptoLibrary () {
const hash = createHash('sha256'); // (implementation specific)
// #1 - something to hash
const startingVal = "abc";
// #2 - do something to change it
hash.update(startingVal);
const result = hash.digest('hex');
// #3 - display/return the hash
console.log(result);
return result;
}
function ourHashingFunctionUsingCaesarCypher () {
// our cypher (implementation specific)
const caesar = {
'a': 'b',
'b': 'c',
'c': 'd'
}
// #1 - something to hash
const startingVal = "abc";
// #2 - do something to change it
let hashValue = [];
for (let char of startingVal) {
hashValue.push(caesar[char]);
}
const result = hashValue.join('');
// #3 - display/return the hash
console.log(result);
return result;
};
function ourHashingFunctionUsingCharCodes (startingVal) {
// #1 - something to hash
// passed in as parameter
// #2 - do something to change it
let hashValue = [];
for (let i = 0; i < startingVal.length; i++) {
const codedChar = startingVal.charCodeAt(i);
hashValue.push(codedChar);
}
const result = hashValue.join('');
// #3 - display/return the hash
console.log(result);
return result;
};
ourHashingFunctionUsingCryptoLibrary();
ourHashingFunctionUsingCaesarCypher();
ourHashingFunctionUsingCharCodes('abc');