A- 1
Lampiran A-1 : Listing Program Main Form
Coding Main Form
using System; 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; using System.Threading.Tasks; using System.Windows.Forms; using Microsoft.Office.Interop.Word;
using App = Microsoft.Office.Interop.Word.Application;
using AForge.Video.FFMPEG;
using System.Diagnostics;
namespace Avi {
public partial class MainForm : Form
{
Stopwatch stopWatch = new Stopwatch();
public enum SEED_State
{ Accept, Reject }; public MainForm() { InitializeComponent(); bw1.WorkerSupportsCancellation = true; bw1.WorkerReportsProgress = true; splashPanel.Hide(); brwEmbedVideo.Filter = "*.avi|*.avi"; brwEmbedText.Filter = *.docx|*.docx|*.doc|*.doc|*.rtf|*.rtf|*.txt|*.txt"; saveEmbedVideo.DefaultExt = "*.avi|*.avi"; saveEmbedVideo.Filter = "*.avi|*.avi"; brwExtractVideo.Filter = "*.avi|*.avi"; } VideoFileReader reader; int frameCount = 0;
string embedText="", extractText=""; List<Bitmap> oriBitmap, embedBitmap; uint[] randomList;
uint SEED, newSEED;
private void btn_embvideo_Click(object sender, EventArgs e) {
string fileEmbedVideo;
btn_embvideo.Enabled = false; oriBitmap = new List<Bitmap>();
A-2
if (brwEmbedVideo.ShowDialog() == DialogResult.OK) {
frameCount = 0; bw1.RunWorkerAsync();
fileEmbedVideo = brwEmbedVideo.FileName; tb_embvideo.Text = fileEmbedVideo; reader = new VideoFileReader(); reader.Open(fileEmbedVideo); while (true)
{
using (var videoFrame = reader.ReadVideoFrame()) {
using (MemoryStream memory = new MemoryStream()) { if (videoFrame == null) break; else { frameCount++; videoFrame.Save(memory, ImageFormat.Bmp); oriBitmap.Add(new Bitmap(videoFrame)); } } } } Thread.Sleep(100);
pb_embvideo.Image = new Bitmap(oriBitmap[0]); } else { bw1.CancelAsync(); btn_embvideo.Enabled = true; }
Console.WriteLine("Framecount : "+frameCount); }
private void btn_embtext_Click(object sender, EventArgs e) {
embedText = ""; string fileEmbedText;
btn_embtext.Enabled = false;
if (brwEmbedText.ShowDialog() == DialogResult.OK) {
bw1.RunWorkerAsync();
fileEmbedText = brwEmbedText.FileName; App app = new App();
Document doc = app.Documents.Open(fileEmbedText); foreach (Paragraph p in doc.Paragraphs)
embedText += p.Range.Text.Trim(); ((_Document)doc).Close();
A-3
((_Application)app).Quit(); rtb_teks.Text = embedText; tb_embteks.Text = fileEmbedText;
randomList = new uint[embedText.Length];
tb_embperiode.Text = embedText.Length.ToString(); } else { bw1.CancelAsync(); btn_embtext.Enabled = true; } }
private void btn_embembed_Click(object sender, EventArgs e) {
List<uint> randomList = new List<uint>(); stopWatch.Reset(); btn_embembed.Enabled = false; stopWatch.Start(); if (!(tb_embvideo.Text == "" || tb_embteks.Text == "" || tb_embseed.Text == "")) { bw1.RunWorkerAsync();
SEED_State seed_state = SEED_State.Reject; embedBitmap = new List<Bitmap>(oriBitmap); SEED = uint.Parse(tb_embseed.Text);
newSEED = SEED; LFSR.setSEED(SEED); if (embedText.Length <= embedBitmap.Count) {
while (seed_state == SEED_State.Reject) {
for (int j = 0; j < embedText.Length; j++) {
uint random = (uint)(LFSR.getNextInt() % frameCount); if (randomList.Count == 0) { randomList.Add(random); continue; } if (randomList.Contains(random)) { randomList.Clear(); newSEED++; LFSR.setSEED(newSEED); break; } randomList.Add(random); if (j == embedText.Length - 1) seed_state = SEED_State.Accept; }
A-4
}
Console.WriteLine("New SEED : " + newSEED); Console.WriteLine("Embed SEED Result"); // in case overlapping
if (seed_state == SEED_State.Accept) {
for (int j = 0; j < embedText.Length; j++) {
embedBitmap[(int)randomList[j]] =
SteganographyHelper.embedText("" + embedText[j], embedBitmap[(int)randomList[j]]);
}
stopWatch.Stop(); }
if (saveEmbedVideo.ShowDialog() == DialogResult.OK) {
var writer = new VideoFileWriter();
TimeSpan ts = stopWatch.Elapsed; string elapsedTime =
String.Format("{0:00}:{1:00}:{2:000}.{3:000}",
ts.Hours, ts.Minutes, ts.Seconds,ts.Milliseconds );
writer.Open(saveEmbedVideo.FileName, embedBitmap[0].Width, embedBitmap[0].Height, 30, VideoCodec.Raw); for (int j = 0; j < embedBitmap.Count; j++) { writer.WriteVideoFrame(embedBitmap[j]); } writer.Close();
MessageBox.Show(this, "Penyisipan Berhasil " + elapsedTime, "Berhasil ", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { bw1.CancelAsync(); btn_embembed.Enabled = true; } } } else { bw1.CancelAsync(); string msgText=""; if (tb_embvideo.Text == "")
msgText += "Pilih file video terlebih dahulu"; else if (tb_embteks.Text == "")
msgText += "Pilih file teks terlebih dahulu"; else
msgText += "Pilih SEED terlebih dahulu";
MessageBox.Show(this, msgText, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
btn_embembed.Enabled = true; }
A-5
randomList.Clear(); }
private void btn_extvideo_Click(object sender, EventArgs e) {
string fileExtractVideo=""; embedBitmap = new List<Bitmap>(); frameCount = 0;
if (brwExtractVideo.ShowDialog() == DialogResult.OK) {
bw1.RunWorkerAsync();
fileExtractVideo = brwExtractVideo.FileName; tb_extvideo.Text = fileExtractVideo;
reader = new VideoFileReader(); reader.Open(fileExtractVideo); while (true)
{
using (var videoFrame = reader.ReadVideoFrame()) {
using (MemoryStream memory = new MemoryStream()) { if (videoFrame == null) break; else { frameCount++; videoFrame.Save(memory, ImageFormat.Bmp); embedBitmap.Add(new Bitmap(videoFrame)); }
} } }
pb_extvideo.Image = new Bitmap(embedBitmap[0]); } else { bw1.CancelAsync(); } } int periode;
private void btn_extextract_Click(object sender, EventArgs e) { btn_extextract.Enabled = false; stopWatch.Reset(); stopWatch.Start(); if (!(tb_extperiode.Text == "" || tb_extseed.Text == "" || tb_extvideo.Text == "")) { bw1.RunWorkerAsync();
periode = int.Parse(tb_extperiode.Text); SEED = uint.Parse(tb_extseed.Text); newSEED = SEED;
A-6
LFSR.setSEED(SEED);
SEED_State seed_state = SEED_State.Reject; randomList = new uint[periode];
while (seed_state == SEED_State.Reject) {
for (int j = 0; j < periode; j++) {
uint random = (uint)(LFSR.getNextInt() % frameCount); if (randomList.Length == 0) { randomList[j] = random; continue; } if (randomList.Contains(random)) {
Array.Clear(randomList, 0, randomList.Length); newSEED++; LFSR.setSEED(newSEED); break; } randomList[j] = random; if (j == periode - 1) {
seed_state = SEED_State.Accept; break;
} } }
for (int j = 0; j < periode; j++) {
extractText +=
SteganographyHelper.extractText(embedBitmap[(int)randomList[j]]); } rb_extteks.Text = extractText; stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:000}.{3:000}",
ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
MessageBox.Show(this, "Berhasil mengekstrak teks dari video" + elapsedTime, "Berhasil", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { bw1.CancelAsync(); btn_extextract.Enabled = true; string msgText = ""; if(tb_extvideo.Text=="")
msgText += "Pilih file video terlebih dahulu"; else if(tb_extseed.Text=="")
A-7
msgText += "Pilih SEED terlebih dahulu"; else
msgText += "Pilih periode terlebih dahulu";
MessageBox.Show(this, msgText, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation); }
}
private void aplikasiToolStripMenuItem_Click(object sender, EventArgs
e) { Panel.Show(); splashPanel.Hide(); proBar.Show(); }
private void aboutToolStripMenuItem_Click(object sender, EventArgs e) {
splashPanel.Show(); Panel.Hide(); proBar.Hide(); }
private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
Close(); }
private void bw1_DoWork(object sender, DoWorkEventArgs e) {
Thread.Sleep(1000);
for (int i = 0; i < 10000; i++) {
bw1.ReportProgress(i); }
}
private void MainForm_Load(object sender, EventArgs e) {
} } }
B-1
Lampiran B : Listing Program LFSR
LFSR using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Security.Cryptography; namespace Avi { class LFSR {
private static uint SEED; public static uint getNextInt() {
if (SEED != 0) {
uint start_state = SEED; uint lfsr = start_state; uint bit;
/* Must be 16bit to allow bit<<15 later in the code */
uint int_period = 0; do
{
// taps: 32 30 26 25; feedback polynomial: x^32 + x^30 + x^26 + x^25 + 1 */ bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 6) ^ (lfsr >> 7)) & 1; lfsr = (lfsr >> 1) | (bit << 31); ++int_period; } while (lfsr == start_state); SEED = lfsr; return lfsr; } return 0; }
public static void setSEED(uint seed) {
SEED = seed; }
} }
C-1
Lampiran C : Listing Program Stego-Helper
// code from sourceforge.comusing System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; using System.Threading.Tasks; namespace Avi { class SteganographyHelper {
public enum State
{
Hiding,
Filling_With_Zeros };
public static Bitmap embedText(string text, Bitmap bmp) {
// initially, we'll be hiding characters in the image
State state = State.Hiding;
// holds the index of the character that is being hidden
int charIndex = 0;
// holds the value of the character converted to integer
int charValue = 0;
// holds the index of the color element (R or G or B) that is currently being processed
long pixelElementIndex = 0;
// holds the number of trailing zeros that have been added when finishing the process
int zeros = 0;
// hold pixel elements
int R = 0, G = 0, B = 0; // pass through the rows
for (int i = 0; i < bmp.Height; i++) {
// pass through each row
for (int j = 0; j < bmp.Width; j++) {
// holds the pixel that is currently being processed
Color pixel = bmp.GetPixel(j, i);
// now, clear the least significant bit (LSB) from each pixel element
R = pixel.R - pixel.R % 2; G = pixel.G - pixel.G % 2; B = pixel.B - pixel.B % 2;
C-2
for (int n = 0; n < 3; n++) {
// check if new 8 bits has been processed
if (pixelElementIndex % 8 == 0) {
// check if the whole process has finished
// we can say that it's finished when 8 zeros are added
if (state == State.Filling_With_Zeros && zeros == 8)
{
// apply the last pixel on the image
// even if only a part of its elements have been affected
if ((pixelElementIndex - 1) % 3 < 2) {
bmp.SetPixel(j, i, Color.FromArgb(R, G, B));
}
// return the bitmap with the text hidden in
return bmp; }
// check if all characters has been hidden
if (charIndex >= text.Length) {
// start adding zeros to mark the end of the text
state = State.Filling_With_Zeros; }
else
{
// move to the next character and process again
charValue = text[charIndex++]; }
}
// check which pixel element has the turn to hide a bit in its LSB
switch (pixelElementIndex % 3) {
case 0: {
if (state == State.Hiding) {
// the rightmost bit in the character will be (charValue % 2) // to put this value instead of the LSB of the pixel element // just add it to it
// recall that the LSB of the pixel element had been cleared // before this operation
R += charValue % 2;
// removes the added rightmost bit of the character
// such that next time we can reach the next one
charValue /= 2; }
} break; case 1: {
C-3
{ G += charValue % 2; charValue /= 2; } } break; case 2: {if (state == State.Hiding) {
B += charValue % 2; charValue /= 2; }
bmp.SetPixel(j, i, Color.FromArgb(R, G, B));
} break; }
pixelElementIndex++;
if (state == State.Filling_With_Zeros) {
// increment the value of zeros until it is 8
zeros++; } } } } return bmp; }
public static string extractText(Bitmap bmp) {
int colorUnitIndex = 0; int charValue = 0;
// variable penyimpan hasil ekstraksi
string extractedText = String.Empty; // membaca setiap kolom
for (int i = 0; i < bmp.Height; i++) {
// membaca setiap kolom
for (int j = 0; j < bmp.Width; j++) {
Color pixel = bmp.GetPixel(j, i);
// for each pixel, pass through its elements (RGB)
for (int n = 0; n < 3; n++) { switch (colorUnitIndex % 3) { case 0: {
charValue = charValue * 2 + pixel.R % 2; } break;
C-4
{
charValue = charValue * 2 + pixel.G % 2; } break;
case 2: {
charValue = charValue * 2 + pixel.B % 2; } break;
}
colorUnitIndex++;
// if 8 bits has been added,
// then add the current character to the result text
if (colorUnitIndex % 8 == 0) {
// reverse? of course, since each time the process occurs
// on the right (for simplicity)
charValue = reverseBits(charValue);
// can only be 0 if it is the stop character (the 8 zeros)
if (charValue == 0) {
return extractedText; }
// convert the character value from int to char
char c = (char)charValue;
// add the current character to the result text
extractedText += c.ToString(); } } } } return extractedText; }
public static int reverseBits(int n) {
int result = 0;
for (int i = 0; i < 8; i++) { result = result * 2 + n % 2; n /= 2; } return result; } } }