Skip to content

Instantly share code, notes, and snippets.

@takano32
Forked from yuiseki/uuidxor.coffee
Created June 4, 2013 07:34
Show Gist options
  • Save takano32/5704235 to your computer and use it in GitHub Desktop.
Save takano32/5704235 to your computer and use it in GitHub Desktop.
uuid = require 'node-uuid'
uuid1 = uuid.v4()
uuid2 = uuid.v4()
uuid2bytes = (uuid) ->
bytes = []
sBytes = uuid.match(/([0-9a-zA-Z]{2})/g)
sBytes.forEach (inByte) ->
aByte = parseInt(inByte, 16)
bytes.push(aByte)
bytes
uuidxor = (uuid1, uuid2) ->
bytes = []
uuid1bytes = uuid2bytes(uuid1)
uuid2bytes = uuid2bytes(uuid2)
for i in [0..uuid1bytes.length]
byte1 = uuid1bytes[i]
byte2 = uuid2bytes[i]
bytes.push(byte1 ^ byte2)
new Buffer(bytes)
console.log uuidxor(uuid1, uuid2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment