Skip to content

Instantly share code, notes, and snippets.

@Sceptero
Created October 12, 2017 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sceptero/571d33a46bd48f69217feeef2de4e3ae to your computer and use it in GitHub Desktop.
Save Sceptero/571d33a46bd48f69217feeef2de4e3ae to your computer and use it in GitHub Desktop.
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