MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / preProcess

Function preProcess

Hashes/SHA1.js:67–90  ·  view source on GitHub ↗

* Pre-processes message to feed the algorithm loop * * @param {string} message - message to pre-process * @return {string} - processed message

(message)

Source from the content-addressed store, hash-verified

65 * @return {string} - processed message
66 */
67function preProcess(message) {
68 // convert message to binary representation padded to
69 // 8 bits, and add 1
70 let m =
71 message
72 .split('')
73 .map((e) => e.charCodeAt(0))
74 .map((e) => e.toString(2))
75 .map((e) => pad(e, 8))
76 .join('') + '1'
77
78 // extend message by adding empty bits (0)
79 while (m.length % 512 !== 448) {
80 m += '0'
81 }
82
83 // length of message in binary, padded, and extended
84 // to a 64 bit representation
85 let ml = (message.length * CHAR_SIZE).toString(2)
86 ml = pad(ml, 8)
87 ml = '0'.repeat(64 - ml.length) + ml
88
89 return m + ml
90}
91
92/**
93 * Hashes message using SHA-1 Cryptographic Hash Function

Callers 1

SHA1Function · 0.70

Calls 2

padFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected