Created
June 7, 2024 00:29
-
-
Save SmugZombie/3572f10325b2ea821cc4343186d5790e to your computer and use it in GitHub Desktop.
String to MAC address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require('crypto'); | |
function stringToMacAddress(input) { | |
// Create an MD5 hash of the input string | |
const hash = crypto.createHash('md5').update(input).digest('hex'); | |
// Convert the hash to MAC address format | |
const macAddress = hash.match(/.{1,2}/g).slice(0, 6).join(':'); | |
return macAddress; | |
} | |
// Test the function | |
console.log(stringToMacAddress('hello world')); // Example output: '5e:b6:3b:76:24:f4' | |
console.log(stringToMacAddress('hello worLd')); // Example output: '4f:a5:6c:87:35:e5' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment