Skip to content

Instantly share code, notes, and snippets.

@bojidar-bg
Created April 22, 2015 15:40
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 bojidar-bg/096c26c867b57edf2b78 to your computer and use it in GitHub Desktop.
Save bojidar-bg/096c26c867b57edf2b78 to your computer and use it in GitHub Desktop.
function encript(current, previous) {
previous = previous || 0;
return (current + previous)%27;
}
var Canvas = require("canvas");
var fs = require("fs");
var source = process.argv[2];
//---PREPARE---
source = source.toUpperCase();
source = source.split("");
var charA = "A".charCodeAt(0);
for(var i in source) {
if(source[i] >= "A" && source[i] <= "Z")
source[i] = source[i].charCodeAt(0) - charA + 1;
else
source[i] = 0;
}
//----CRYPT----
var encripted = [];
for(var i in source) {
encripted[i] = encript(source[i], source[i-1]);
}
//----IMAGE----
var CSIZE = 20;
var CMARGIN = 10;
var canvas = new Canvas(encripted.length*(CSIZE*2+CMARGIN) + 30,CSIZE*2+20);
var context = canvas.getContext("2d");
context.beginPath();
context.moveTo(0, canvas.height/2);
context.lineTo(canvas.width, canvas.height/2);
context.lineWidth = 2;
context.stroke();
context.closePath();
context.lineWidth = 1;
for(var i in encripted) {
var red_a = encripted[i] & 1;
var green_a = encripted[i] & 2;
var blue_a = encripted[i] & 4;
var color_a = "rgba(" + red_a*255 + ", " + green_a*255 + ", " + blue_a*255 + ", 1)";
context.beginPath();
context.fillStyle = color_a;
context.arc((1*i + 0.5)*(CSIZE*2+CMARGIN) + 30, 10 + CSIZE, CSIZE, Math.PI/2, Math.PI*3/2, false);
context.stroke();
context.fill();
context.closePath();
var red_b = encripted[i] & 8;
var green_b = encripted[i] & 16;
var blue_b = encripted[i] & 4;
var color_b = "rgba(" + red_b*255 + ", " + green_b*255 + ", " + blue_b*255 + ", 1)";
context.beginPath();
context.fillStyle = color_b;
context.arc((1*i + 0.5)*(CSIZE*2+CMARGIN) + 30, 10 + CSIZE, CSIZE, Math.PI/2, Math.PI*3/2, true);
context.stroke();
context.fill();
context.closePath();
}
var buffer = canvas.toBuffer();
fs.writeFile("./image_"+Math.round(Math.random()*36*36).toString(36)+".png", buffer);
//----PRINT----
for(var i in encripted) {
if(encripted[i] != 0)
encripted[i] = String.fromCharCode(encripted[i]%27 + charA - 1);
else
encripted[i] = " ";
}
console.log(encripted.join(""))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment