Skip to content

Instantly share code, notes, and snippets.

@neonbyte1
Created May 13, 2025 12:32
Show Gist options
  • Select an option

  • Save neonbyte1/5aa93631330796f1f16280b595c01f55 to your computer and use it in GitHub Desktop.

Select an option

Save neonbyte1/5aa93631330796f1f16280b595c01f55 to your computer and use it in GitHub Desktop.
Decrypt Factorio "Blueprint String", modify the JSON and encrypt it to produce the modified "Blueprint String"

Factorio blueprint encryption/decryption

Small unix-like tool that requires Deno to decrypt or encrypt Factorio blueprints. Just pipe the encrypted or decrypted content to the factorio-blueprint script and adjust your parameters.

Options / parameters

  • --decrypt, -dec, -d: takes the "Blueprint String" and produces a minified JSON output
  • --encrypt, -enc, -e: takes the decrypted JSON output (minified or pretty, it doesn't matter) and produces the "Blueprint String"
  • --pretty, -p: produces a pretty JSON output instead of a minified one

Example

Note

Make sure the location of your factorio-blueprint script is inside your $PATH.

Decryption

echo "<BLUEPRINT_STRING>" | factorio-blueprint -d

Or if you've stored it in a file instead (e.g. awesome-blueprint.b64)

cat awesome-blueprint.b64 | factorio-blueprint -d

# you can redirect the output directly into a file

cat awesome-blueprint.b64 | factorio-blueprint -d > awesome-blueprint.json

Encryption

cat awesome-blueprint.json | factorio-blueprint -e
```
#!/usr/bin/env -S deno run --allow-read
import { Buffer } from "node:buffer";
import zlib from "node:zlib";
function hasOption(name: string, shortcut?: string | string[]): boolean {
const option = (input: string, count: number): string =>
`${"".padStart(count, "-")}${input}`;
shortcut ??= [];
return [
option(name, 2),
...(Array.isArray(shortcut) ? shortcut : [shortcut]).map((val) =>
option(val, 1)
),
].some((key) => Deno.args.includes(key));
}
const actionDecrypt = hasOption("decrypt", ["d", "dec"]);
const actionEncrypt = hasOption("encrypt", ["e", "enc"]);
let exitCode = 1;
if (actionDecrypt || actionEncrypt) {
const chunks: Uint8Array[] = [];
for await (const chunk of Deno.stdin.readable) {
chunks.push(chunk);
}
const inputFile = Buffer.concat(chunks).toString();
if (actionDecrypt) {
const encryptedBlueprint = Buffer.from(
inputFile.split("\n").map((val) => val.slice(1)).filter((line) =>
line.length > 0
).join(""),
"base64",
);
const decryptedBlueprint = zlib.inflateSync(encryptedBlueprint);
if (hasOption("pretty", "p")) {
console.log(
JSON.stringify(JSON.parse(decryptedBlueprint.toString()), undefined, 2),
);
} else {
console.log(decryptedBlueprint.toString());
}
} else {
const rawBlueprint = JSON.parse(JSON.stringify(inputFile));
const foo = zlib.deflateSync(rawBlueprint, { level: 9 });
console.log("0".concat(foo.toString("base64")));
}
exitCode = 0;
}
Deno.exit(exitCode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment