Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Drawing;
- using System.IO;
- using System.Threading.Tasks;
- namespace Stenography
- {
- class Program
- {
- static void Main(string[] args)
- {
- if (args.Length <= 0 || !File.Exists(args[args.Length - 1])) {
- Console.WriteLine("stenography [options] <image>");
- return;
- }
- string targetFile = args[args.Length - 1];
- bool saveToFile = args.Contains<string>("-dump");
- TextWriter consoleWindowOut = Console.Out;
- int bits = 2;
- StreamWriter outFile = new StreamWriter("out.txt");
- if (saveToFile) {
- Console.SetOut(outFile);
- }
- Bitmap bmp = new Bitmap(args[args.Length - 1]);
- byte[] data = new byte[bmp.Height * bmp.Width * 3];
- // Build array of bytes, each one is <bits> bits long
- int c = 0;
- for (int i = 0; i < bmp.Height; i++) {
- for (int j = 0; j < bmp.Width; j++) {
- data[c] = (byte)(bmp.GetPixel(j, i).R & ((1 << bits) - 1));
- data[c + 1] = (byte)(bmp.GetPixel(j, i).G & ((1 << bits) - 1));
- data[c + 2] = (byte)(bmp.GetPixel(j, i).B & ((1 << bits) - 1));
- c += 3;
- }
- }
- // Print each byte in data, with a space every 4 bytes
- for (int i = 0; i < data.Length; i++) {
- if (i % 4 == 0 && i != 0) {
- Console.Write(" ");
- }
- Console.Write(Convert.ToString(data[i], 2).PadLeft(2, '0'));
- //Console.Write(Convert.ToString(data[i], 16).PadLeft(2, '0') + " ");
- }
- Console.SetOut(consoleWindowOut);
- outFile.Close();
- Console.Write(File.ReadAllText("out.txt"));
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment