Created
May 25, 2019 22:27
-
-
Save YoussefLagtab/033ac5dae0e0d25ab95521aeebffafa6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 net = require('net') | |
const socket = net.Socket | |
const HOST = "vortex.labs.overthewire.org" | |
const PORT = 5842 | |
const options = { | |
readable: true, | |
writable: true | |
} | |
client = new socket(options) | |
client.connect(PORT, HOST, () => { | |
console.log('connected') | |
}) | |
client.on('data', (data) => { | |
console.log(data.toString(), '\n\n') | |
let d = data.toString('hex') | |
let integers = [...Array(4)].map((_, i) => { | |
let a = d.substr(i * 8, 8) | |
return [...Array(4)] | |
.map((_, i) => a.substr(i * 2, 2).split``.reverse().join``) | |
.join`` | |
.split`` | |
.reverse() | |
.join`` | |
}) | |
let sum = addHex(...integers) | |
console.log(d, d.length, integers) | |
client.write(sum) | |
}); | |
function addHex(...hex_nums) { | |
return hex_nums.reduce((a, c) => a + parseInt(c, 16), 0).toString(16) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment