Advertisement
Guest User

Hide.jar

a guest
Feb 7th, 2016
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.26 KB | None | 0 0
  1.  /*
  2.  * Decompiled with CFR 0_110.
  3.  */
  4. import java.awt.Point;
  5. import java.awt.image.BufferedImage;
  6. import java.awt.image.RenderedImage;
  7. import java.io.File;
  8. import java.io.IOException;
  9. import java.io.PrintStream;
  10. import javax.imageio.ImageIO;
  11.  
  12. public class Hide {
  13.     protected void steg(String string, String string2) {
  14.         BufferedImage bufferedImage = this.loadImage(string2 + ".png");
  15.         BufferedImage bufferedImage2 = this.steg(string, bufferedImage);
  16.         try {
  17.             ImageIO.write((RenderedImage)bufferedImage2, "png", new File(string2 + "_out.png"));
  18.         }
  19.         catch (IOException var5_5) {
  20.             throw new RuntimeException("Unable to write image!");
  21.         }
  22.     }
  23.  
  24.     protected BufferedImage steg(String string, BufferedImage bufferedImage) {
  25.         if ((string = "" + string.length() + ":" + string).length() * 8 > bufferedImage.getWidth() * bufferedImage.getHeight()) {
  26.             System.out.println("There won't be enough space to store this message!");
  27.             System.out.println("Message length: " + string.length() + " bytes. " + "Image can hold a maximum of " + bufferedImage.getWidth() * bufferedImage.getHeight() / 8);
  28.             throw new RuntimeException("There won't be enough space to store this message!");
  29.         }
  30.         byte[] arrby = string.getBytes();
  31.         Point point = new Point(0, 0);
  32.         for (int n : arrby) {
  33.             for (int i = 0; i < 8; ++i) {
  34.                 if ((n & 128) == 128) {
  35.                     bufferedImage.setRGB(point.x, point.y, this.setLeastSignificantBit(bufferedImage.getRGB(point.x, point.y), true));
  36.                 } else {
  37.                     bufferedImage.setRGB(point.x, point.y, this.setLeastSignificantBit(bufferedImage.getRGB(point.x, point.y), false));
  38.                 }
  39.                 n <<= 1;
  40.                 this.movePointer(point, bufferedImage);
  41.             }
  42.         }
  43.         return bufferedImage;
  44.     }
  45.  
  46.     protected int setLeastSignificantBit(int n, boolean bl) {
  47.         n >>= 1;
  48.         n <<= 1;
  49.         if (bl) {
  50.             ++n;
  51.         }
  52.         return n;
  53.     }
  54.  
  55.     protected void movePointer(Point point, BufferedImage bufferedImage) {
  56.         if (point.x == bufferedImage.getWidth() - 1) {
  57.             point.x = -1;
  58.             ++point.y;
  59.         }
  60.         ++point.x;
  61.         if (point.y == bufferedImage.getHeight()) {
  62.             throw new RuntimeException("Pointer moved beyond the end of the image");
  63.         }
  64.     }
  65.  
  66.     private BufferedImage loadImage(String string) {
  67.         try {
  68.             BufferedImage bufferedImage = ImageIO.read(new File(string));
  69.             return bufferedImage;
  70.         }
  71.         catch (IOException var2_3) {
  72.             System.out.println("Unable to load \"" + string + "\"");
  73.             System.exit(0);
  74.             return null;
  75.         }
  76.     }
  77.  
  78.     public static void main(String[] arrstring) {
  79.         if (arrstring.length < 2) {
  80.             System.out.println("Input Arguments Is Not Valid.");
  81.             System.out.println("Run By 'java -jar Hide.jar `file-path` `message`'");
  82.             return;
  83.         }
  84.         System.out.println("Welcome!\nDecrypt The Image And Capture The Flag!");
  85.         Hide hide = new Hide();
  86.         hide.steg(arrstring[1], arrstring[0]);
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement