seccon22-noiseccon

Seccon 2022 Qualifier Challenge 'Noiseccon'
git clone https://git.sinitax.com/sinitax/seccon22-noiseccon
Log | Files | Refs | sfeed.txt

findoff.js (1123B)


      1const { noise } = require("./perlin.js");
      2const { argv } = require("process");
      3const crypto = require("node:crypto");
      4const sharp = require("sharp");
      5const fs = require("fs");
      6
      7const WIDTH = 256;
      8const HEIGHT = 256;
      9
     10const main = async() => {
     11	var buffer = fs.readFileSync("tmp.webp")
     12	const image = await sharp(buffer, {
     13			webp: {
     14				width: WIDTH,
     15				height: HEIGHT,
     16				channels: 1
     17			}
     18		}).raw().toBuffer()
     19	var ivals = Uint8Array.from(image);
     20	console.log(ivals.length, 256 * 256 * 3)
     21
     22	for (let seed = 0; seed < 65536; seed++) {
     23		noise.seed(seed);
     24		//let ox = parseInt(argv[2]);
     25		for (let ox = 0; ox < 256; ox++) {
     26			//let p = parseInt(argv[3]);
     27			//console.log(p);
     28			for (let p = 0; p < 16; p++) {
     29				let match = true;
     30				for (let y = 0; y < 40; y++) {
     31					for (let x = 0; x < 40; x++) {
     32						let v = noise.perlin2(ox + p * 0.0625 + x * 0.05, y * 0.05);
     33						v = (v + 1.0) * 0.5;
     34						v = (v * 256) | 0;
     35						if (ivals[(y * 256 + x) * 3] != v) {
     36							match = false;
     37							break;
     38						}
     39					}
     40					if (!match)
     41						break;
     42				}
     43				if (match)
     44					console.log("IDX", ox);
     45			}
     46		}
     47	}
     48}
     49
     50main();