Digested-Tile 2024-09-13
Authors:: Unknown License:: Unspecified Digest Root:: 07a1008bdcaa
MarkdownTile
computeSHA256.js
// Import the crypto module for cryptographic operations
const crypto = require('crypto');
// Function to generate a truncated SHA-256 hash of the input content
function computeSHA256(content, length = 12) {
// Record the start time for performance measurement
const startTime = Date.now();
// Generate SHA-256 hash, convert to hex, and truncate to specified length
const shash = crypto.createHash('sha256').update(content).digest('hex').substring(0, length);
// Log the number of characters hashed and the time taken
const endTime = Date.now();
const hashtime = ((endTime - startTime) / 1000).toFixed(2);
console.log(`Hashed ${content.length} characters in ${hashtime}s into #${shash}`)
// Return the truncated hash
return shash;
}
// Export the generateHash function for use in other modules
module.exports = computeSHA256;DeformattedTile
computeSHA256.js
// Import the crypto module for cryptographic operations
const crypto = require('crypto');
// Function to generate a truncated SHA-256 hash of the input content
function computeSHA256(content, length = 12) {
// Record the start time for performance measurement
const startTime = Date.now();
// Generate SHA-256 hash, convert to hex, and truncate to specified length
const shash = crypto.createHash('sha256').update(content).digest('hex').substring(0, length);
// Log the number of characters hashed and the time taken
const endTime = Date.now();
const hashtime = ((endTime - startTime) / 1000).toFixed(2);
console.log(`Hashed ${content.length} characters in ${hashtime}s into #${shash}`)
// Return the truncated hash
return shash;
}
// Export the generateHash function for use in other modules
module.exports = computeSHA256;