Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rozwiązanie misji 13 w Node (https://www.youtube.com/watch?v=RmiFyWmtAZk)
const extract = require('png-chunks-extract');
const fs = require('fs');
const zlib = require('zlib');
const chunks = extract(fs.readFileSync(process.argv[2]));
const ihdr = chunks[0].data;
const idat = chunks[1].data;
const width = (ihdr[0] << 24) + (ihdr[1] << 16) + (ihdr[2] << 8) + ihdr[3];
const blocksize = width * 3 + 1;
zlib.inflate(idat, (error, result) => {
let flag = "";
for (let i = 0; i < result.byteLength; i += blocksize)
flag += result[i];
flag = flag.match(/.{1,8}/g);
flag = flag.filter(x => x != "00000000").map(x => Number("0b" + x.split("").reverse().join("")));
flag = String.fromCharCode(...flag);
console.log("Flaga: " + flag);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment