Skip to content

Instantly share code, notes, and snippets.

@gifguide2code
Created July 9, 2018 01:20
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 gifguide2code/382e99ee16e9defdaa9185979c3242ae to your computer and use it in GitHub Desktop.
Save gifguide2code/382e99ee16e9defdaa9185979c3242ae to your computer and use it in GitHub Desktop.
A Processing sketch to hide messages in images. It assigns letters to numbers which are then used to change the red values in a .png copy of the original.
IntList numbers;
void setup () {
numbers = new IntList();
String abc = ". abcdefghijklmnopqrstuvwxyz";
String message = "there is a place where the sidewalk ends and before the street begins and there the grass grows soft and white and there the sun burns crimson bright and there the moon bird rests from his flight to cool in the peppermint wind";
int n = 0;
for (int i=0; i<message.length();i++) {
String letter = str(message.charAt(i));
numbers.append(abc.indexOf(letter));
}
size(400, 317);
PImage Original = loadImage("Starry Night.jpg");
Original.loadPixels();
PImage Encoded = createImage(width,height,ARGB);
for (int x=0; x<width;x++) {
for (int y=0;y<height;y++) {
int loc = x + y * width;
float r = red(Original.pixels[loc]);
float g = green(Original.pixels[loc]);
float b = blue(Original.pixels[loc]);
if ( n<message.length()){
print(r + ": ");
r = r + numbers.get(n);
print(r + " ");
Encoded.pixels[loc] = color(r,g,b);
n++; } else {
Encoded.pixels[loc] = color(r,g,b);
}
}
}
Encoded.updatePixels();
image(Encoded,0,0);
save("Encoded.png");
}
void draw(){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment