Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            String id_user_masuk = dbHandler.ambilIdUser(textBox1.Text);

            if (id_user_masuk == "" || id_user_masuk == null)
            {
                MessageBox.Show("ID line tidak ditemukan. Bila belum ada, daftar ID anda di bot Stegomen Line");
            }
            else
            {
                login = new Form1(id_user_masuk);
                this.Hide();
                if (login.ShowDialog() == DialogResult.None)
                {
                    this.Show();
                }
            }
        }
Пример #2
0
        //////encrypt gambar
        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox4.Text == null || textBox4.Text == "")
            {
                MessageBox.Show("Kasih ID penerima dari Line tersebut");
            }
            else if (textBox3.Text == null || textBox3.Text == "")
            {
                MessageBox.Show("kasih dulu passwordnya untuk kemanan pesan!");
            }
            else if (textBox1.Text == "" || textBox1.Text == null)
            {
                MessageBox.Show("Tentukan Path gambar terlebih dahulu");
            }
            else
            {
                Bitmap img;
                string messagetext = kasihPassword(textBox2.Text, textBox3.Text);
                //double textlength = System.Text.ASCIIEncoding.ASCII.GetByteCount(messagetext);
                Console.WriteLine("Text length normal: " + messagetext.Length);
                //Console.WriteLine("Textlength:" + textlength);


                if (messagetext.Length - 2 > loadedImage.Width)
                {
                    MessageBox.Show("Ukuran gambar terlalu besar. Silahkan perpendek teksnya");
                }
                else
                {
                    String tampung_perbit_pixel = "";

                    if (AmbilExtensionPNG(textBox1.Text) == false)
                    {
                        String direktori = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                        KonvertPNG(textBox1.Text, direktori);
                        img = new Bitmap(direktori + "\\temp.png");
                        //Buat Debugging
                        Console.WriteLine("----------Berhasil Convert PNG---------");
                    }
                    else
                    {
                        img = new Bitmap(textBox1.Text);
                        Console.WriteLine("----------TIDAK CONVERT---------");
                    }

                    Console.WriteLine("Panjang textbox 2: " + textBox2.TextLength);
                    int tampung_panjang_karakter = textBox2.TextLength;

                    //Looping per karakter
                    for (int indeks_karakter = 0; indeks_karakter < messagetext.Length; indeks_karakter++)
                    {
                        char   karakter    = Convert.ToChar(messagetext.Substring(indeks_karakter, 1));
                        int    value       = Convert.ToInt32(karakter);
                        String char_binary = Convert.ToString(value, 2);
                        Console.WriteLine("VALUE CHAR = " + value + " BINER CHAR = " + char_binary);


                        //looping per 1 bit di LSB masukin pixelnya
                        for (int i = 0; i < char_binary.Length; i++)
                        {
                            Console.WriteLine("LOOP BIT ========" + i);
                            char  tampung       = Convert.ToChar(char_binary.Substring(i, 1));
                            Color pixel         = img.GetPixel(indeks_karakter, i);
                            int   pixel_B_value = pixel.B;

                            Console.WriteLine("PIXEL B = " + pixel_B_value);
                            String biner_pixel_B = Convert.ToString(pixel_B_value, 2);
                            Console.WriteLine("BINER_PIXEL = " + biner_pixel_B);
                            String ubahbit = library.ubah_bit(biner_pixel_B, tampung);

                            Console.WriteLine("UBAH BIT = " + ubahbit);
                            int newBinary_pixelB = Convert.ToInt32(ubahbit, 2);
                            Console.WriteLine(newBinary_pixelB);
                            img.SetPixel(indeks_karakter, i, Color.FromArgb(pixel.R, pixel.G, newBinary_pixelB));
                        }
                        //tampung indeks perbit di satu pixel agar nanti waktu decrypt bisa di fetch diambil length nya
                        tampung_perbit_pixel = tampung_perbit_pixel + char_binary.Length + "-";
                    }

                    //insert status dan indeks bit pixel ke database serta id penerimanya
                    dbHandler.insertDatabase(tampung_perbit_pixel, dbHandler.ambilIdUser(textBox4.Text));
                    Color pixelTerakhir = img.GetPixel(img.Width - 1, img.Height - 1);

                    //tampung messageID di pixel paling kanan bawah
                    int id_pesan = dbHandler.getLastMessageID();
                    Console.WriteLine("MESSAGE IDNYA DIMASUKIN = " + id_pesan);
                    img.SetPixel(img.Width - 1, img.Height - 1, Color.FromArgb(pixelTerakhir.R, pixelTerakhir.B, id_pesan));

                    Console.WriteLine("PANJANG PERINDEKS: " + tampung_perbit_pixel);
                    SaveFileDialog saveFile = new SaveFileDialog();
                    saveFile.Filter           = "Recommended!!!! (*.png) | *.png|Common Images(*.jpg)|*.jpg";
                    saveFile.InitialDirectory = @"C:\Users\";
                    if (saveFile.ShowDialog() == DialogResult.OK)
                    {
                        textBox1.Text             = saveFile.FileName.ToString();
                        pictureBox1.ImageLocation = textBox1.Text;
                        img.Save(textBox1.Text);
                    }
                    MessageBox.Show("Gambar berhasil Disimpan!");

                    //kirim notif ada yang buat pesan rahasia ke dia
                    if (library.sendToPenerima(dbHandler.ambilIdUser(textBox4.Text), dbHandler.ekstrakUserName(id_user_masuk), id_pesan) != "berhasil")
                    {
                        //MessageBox.Show("Gagal mengirim ke line penerima anda");
                    }
                    img.Dispose();
                    File.Delete(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\temp.png");
                    textBox2.Text = "";
                }
            }
        }