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

Function preProcess

Hashes/MD5.js:118–142  ·  view source on GitHub ↗

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

(message)

Source from the content-addressed store, hash-verified

116 * @return {Uint32Array} - processed message
117 */
118function preProcess(message) {
119 // Extend message by adding '0'
120 //
121 // message.length + 1 is for adding '1' bit
122 // 56 - (length % 64) is for padding with '0's
123 // 8 is for appending 64 bit message length
124 let m = padEnd(
125 message,
126 message.length + 1 + (56 - ((message.length + 1) % 64)) + 8
127 )
128
129 // Add '1' bit at the end of the message
130 m[message.length] = 1 << 7
131
132 // convert message to 32 bit uint array
133 m = u8ToU32(m)
134
135 // Append the length of the message to the end
136 // (ml / 0x100000000) | 0 is equivalent to (ml >> 32) & 0xffffffff) in other languages
137 let ml = message.length * 8
138 m[m.length - 2] = ml & 0xffffffff
139 m[m.length - 1] = (ml / 0x100000000) | 0
140
141 return m
142}
143
144/**
145 * Hashes message using MD5 Cryptographic Hash Function

Callers 1

MD5Function · 0.70

Calls 2

padEndFunction · 0.85
u8ToU32Function · 0.85

Tested by

no test coverage detected