DankParrot

REALLY LAZY RUSHED CODE

Jun 8th, 2016
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Threading.Tasks;
  8.  
  9. namespace Stenography
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             if (args.Length <= 0 || !File.Exists(args[args.Length - 1])) {
  16.                 Console.WriteLine("stenography [options] <image>");
  17.                 return;
  18.             }
  19.  
  20.             string targetFile = args[args.Length - 1];
  21.             bool saveToFile = args.Contains<string>("-dump");
  22.  
  23.  
  24.             TextWriter consoleWindowOut = Console.Out;
  25.             int bits = 2;
  26.  
  27.             StreamWriter outFile = new StreamWriter("out.txt");
  28.             if (saveToFile) {
  29.                 Console.SetOut(outFile);
  30.             }
  31.  
  32.             Bitmap bmp = new Bitmap(args[args.Length - 1]);
  33.             byte[] data = new byte[bmp.Height * bmp.Width * 3];
  34.  
  35.             // Build array of bytes, each one is <bits> bits long
  36.             int c = 0;
  37.             for (int i = 0; i < bmp.Height; i++) {
  38.                 for (int j = 0; j < bmp.Width; j++) {
  39.                     data[c] = (byte)(bmp.GetPixel(j, i).R & ((1 << bits) - 1));
  40.                     data[c + 1] = (byte)(bmp.GetPixel(j, i).G & ((1 << bits) - 1));
  41.                     data[c + 2] = (byte)(bmp.GetPixel(j, i).B & ((1 << bits) - 1));
  42.                     c += 3;
  43.                 }
  44.             }
  45.  
  46.             // Print each byte in data, with a space every 4 bytes
  47.             for (int i = 0; i < data.Length; i++) {
  48.                 if (i % 4 == 0 && i != 0) {
  49.                     Console.Write(" ");
  50.                 }
  51.  
  52.                 Console.Write(Convert.ToString(data[i], 2).PadLeft(2, '0'));
  53.                 //Console.Write(Convert.ToString(data[i], 16).PadLeft(2, '0') + " ");
  54.             }
  55.  
  56.             Console.SetOut(consoleWindowOut);
  57.             outFile.Close();
  58.             Console.Write(File.ReadAllText("out.txt"));
  59.  
  60.             Console.ReadKey();
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment