221 lines
7.3 KiB
C#
221 lines
7.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace KRY_0x02
|
|
{
|
|
public partial class main_form : Form
|
|
{
|
|
public main_form()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public int im_h = 0;
|
|
public int im_w = 0;
|
|
public static int cap = 0;
|
|
public string path = "";
|
|
|
|
public string getpath(TextBox t)
|
|
{
|
|
string path = t.Text;
|
|
return path;
|
|
}
|
|
|
|
public int get_capacity(int a, int b)
|
|
{
|
|
int c = 0;
|
|
a = im_h;
|
|
b = im_w;
|
|
c = ((a * b) / 8) - 8;
|
|
cap = c;
|
|
return c;
|
|
}
|
|
|
|
|
|
class do_a_stego
|
|
{
|
|
Bitmap my_bitmap;// = new Bitmap(getpath(textBox1));
|
|
Color pixel;
|
|
|
|
byte bit_array_to_byte(BitArray bit_array)
|
|
{
|
|
byte[] byte_array = new byte[1];
|
|
//if (bit_array.Count == cap)
|
|
if (bit_array.Count == 8)
|
|
{
|
|
bit_array.CopyTo(byte_array, 0);
|
|
}
|
|
else
|
|
{
|
|
byte_array[0] = 0;
|
|
MessageBox.Show($"you should have {bit_array.Count} bits for a byte bro", "error happened");
|
|
}
|
|
return byte_array[0];
|
|
}
|
|
|
|
public string encode(Bitmap b, string m)
|
|
{
|
|
/* WIP */
|
|
my_bitmap = b;
|
|
string message = m;
|
|
for (int i = 0; i < my_bitmap.Width - 1; i++)
|
|
{
|
|
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public string gimme(Bitmap b)
|
|
{
|
|
/* WIP */
|
|
my_bitmap = b;
|
|
bool[] my_bool_array = new bool[8];
|
|
int int_value;
|
|
|
|
int ii = my_bool_array.Length - 1;
|
|
|
|
for (int i = 0; i < my_bitmap.Width - 1; i++)
|
|
{
|
|
pixel = my_bitmap.GetPixel(i, 0);
|
|
int_value = pixel.B;
|
|
|
|
if ((int_value & 1) == 0)
|
|
{
|
|
my_bool_array[i] = false;
|
|
}
|
|
else if ((int_value & 1) == 1)
|
|
{
|
|
my_bool_array[i] = true;
|
|
}
|
|
}
|
|
|
|
BitArray my_bit_array = new BitArray(my_bool_array);
|
|
char my_char = Convert.ToChar(Convert.ToInt32(bit_array_to_byte(my_bit_array)));
|
|
return Convert.ToString(my_char);
|
|
}
|
|
}
|
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
// put
|
|
if (pictureBox1.Image == null)
|
|
{
|
|
MessageBox.Show("you've nowhere to write to, boi");
|
|
return;
|
|
}
|
|
do_a_stego do_A_Stego = new do_a_stego();
|
|
Bitmap b = new Bitmap(pictureBox1.Image);
|
|
string m = textBox1putm.Text;
|
|
do_A_Stego.encode(b, m);
|
|
}
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
// get
|
|
if (pictureBox1.Image == null)
|
|
{
|
|
MessageBox.Show("you've nowhere to read from, boi");
|
|
return;
|
|
}
|
|
do_a_stego do_A_Stego = new do_a_stego();
|
|
Bitmap b = new Bitmap(pictureBox1.Image);
|
|
textBox2getm.Text = do_A_Stego.gimme(b);
|
|
}
|
|
|
|
|
|
private void button4_Click(object sender, EventArgs e)
|
|
{
|
|
/*
|
|
* Wrap the creation of the OpenFileDialog instance in a using statement,
|
|
* rather than manually calling the Dispose method to ensure proper disposal
|
|
*/
|
|
|
|
using (OpenFileDialog dlg = new OpenFileDialog())
|
|
{
|
|
dlg.Title = "pick a pic";
|
|
dlg.Filter = "png (*.png)|*.png|bmp (*.bmp)|*.bmp|tiff (*.tiff)|*.tiff|custom (*.*)|*.*";
|
|
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
{
|
|
label5pathtopic.Text = @"path/to/pic";
|
|
pictureBox1.Image = new Bitmap(dlg.FileName);
|
|
pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
|
|
textBox3.Text = dlg.FileName;
|
|
path = textBox3.Text;
|
|
im_h = pictureBox1.Image.Height;
|
|
im_w = pictureBox1.Image.Width;
|
|
textBox4height.Text = im_h.ToString();
|
|
textBox5width.Text = im_w.ToString();
|
|
textBox6capacity.Text = get_capacity(im_h,im_w).ToString();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void button5_Click(object sender, EventArgs e)
|
|
{
|
|
/*/* use-default-pic button */
|
|
string filename = @"C:\Users\citizen\source\repos\KRY-0x02\security.png";
|
|
pictureBox1.Image = new Bitmap(filename);
|
|
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
|
|
label5pathtopic.Text = $"Security: Actual actual reality: nobody cares about his secrets."
|
|
+ " (Also, I would be hard-pressed to find that wrench for $5.)";
|
|
textBox3.Text = filename + "\t\t by randall ... https://xkcd.com/538";
|
|
path = filename;
|
|
im_h = pictureBox1.Image.Height;
|
|
im_w = pictureBox1.Image.Width;
|
|
textBox4height.Text = im_h.ToString();
|
|
textBox5width.Text = im_w.ToString();
|
|
textBox6capacity.Text = Convert.ToString(get_capacity(im_h, im_w));
|
|
}
|
|
|
|
private void button6_Click(object sender, EventArgs e)
|
|
{
|
|
/* clear pic selection */
|
|
label5pathtopic.Text = @"path/to/pic";
|
|
pictureBox1.Image = null;
|
|
textBox3.Text = "";
|
|
path = "";
|
|
textBox4height.Text = "";
|
|
textBox5width.Text = "";
|
|
textBox6capacity.Text = "";
|
|
im_h = 0;
|
|
im_w = 0;
|
|
}
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
{
|
|
if (pictureBox1.Image == null)
|
|
{
|
|
MessageBox.Show("you've nothing to export, boi");
|
|
return;
|
|
}
|
|
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
|
|
saveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
|
saveFileDialog1.Title = "export your neatly stego-ed pic";
|
|
saveFileDialog1.CheckFileExists = false;
|
|
saveFileDialog1.CheckPathExists = false;
|
|
saveFileDialog1.DefaultExt = "";
|
|
saveFileDialog1.Filter = "png (*.png)|*.png|any file you wish (*.*)|*.*";
|
|
saveFileDialog1.FilterIndex = 2;
|
|
saveFileDialog1.RestoreDirectory = true;
|
|
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
|
|
{
|
|
// Get file name.
|
|
string name = saveFileDialog1.FileName;
|
|
pictureBox1.Image.Save($"{name}",ImageFormat.MemoryBmp);
|
|
MessageBox.Show($"saved to {name}","gj, file saved!");
|
|
}
|
|
}
|
|
}
|
|
}
|