Implementasi Modified LSB (Least Significant Bit) dan Algoritma DES (Data Encryption Standard) Pada Pengamanan Data Text

A-1

LISTING PROGRAM
1. Form1.cs
using
using
using
using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

System.Threading.Tasks;
IronPython.Hosting;
Microsoft.Scripting;
Microsoft.Scripting.Hosting;
System.IO;
System.Diagnostics;
System.Windows.Forms;
System.Drawing;

namespace program
{
public partial class Form1 : Form
{
public string imgPath;
public string paddedImgPath;
public string cipherteks;
DateTime awal;
DateTime akhir;
TimeSpan total;
public Form1()

{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DateTime awal;
DateTime akhir;
TimeSpan total;
int waktupenyisipan;
awal = DateTime.Now;
if (ekskey.Text == "" || ekskey.Text == "12345678" || ekskey.Text
== "enkripsi")
{
MessageBox.Show("kunci tidak boleh kosong!", "Peringatan!",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
Process p = new Process(); // create process (i.e., the python
program

p.StartInfo.FileName = "C:\\Python27\\python.exe";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false; // make sure we can read
the output from stdout
p.StartInfo.Arguments = "internal_key.py " + ekskey.Text; //
start the python program with two parameters
p.Start(); // start the process (the python program)
StreamReader s = p.StandardOutput;
String output = s.ReadToEnd();

Universitas Sumatera Utara

A-2

string[] r = output.Split(new char[] { ' ' }); // get the
parameter
string q = r[0];
//string[] words = q.Split('.');
intkey.Text = output;
p.WaitForExit();

akhir = DateTime.Now;
total = akhir - awal;
waktupenyisipan = Convert.ToInt32(total.TotalMilliseconds);
MessageBox.Show("Waktu pembangkitan kunci adalah: " +
waktupenyisipan + " ms.");
}
}
private void button3_Click(object sender, EventArgs e)
{
DateTime awal;
DateTime akhir;
TimeSpan total;
int waktupenyisipan;
awal = DateTime.Now;
Process p = new Process(); // create process (i.e., the python
program
p.StartInfo.FileName = "C:\\Python27\\python.exe";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false; // make sure we can read the
output from stdout

p.StartInfo.Arguments = "enkripsi_pesan.py " +
plainText.Text.Replace(' ', '_') + " " + ekskey.Text;// start the python
program with two parameters
p.Start(); // start the process (the python program)
StreamReader s = p.StandardOutput;
String output = s.ReadToEnd();
string[] r = output.Split(new char[] { ' ' }); // get the parameter
string q = r[0];
//string[] words = q.Split('.');
cipherText.Text = output;
cipherteks = output;
p.WaitForExit();
akhir = DateTime.Now;
total = akhir - awal;
waktupenyisipan = Convert.ToInt32(total.TotalMilliseconds);
MessageBox.Show("Waktu enkripsi adalah: " + waktupenyisipan + "
ms.");
}
private void button2_Click(object sender, EventArgs e)
{

try
{
plainText.Text="";
OpenFileDialog bukaPlainText = new OpenFileDialog();
bukaPlainText.InitialDirectory = "";
bukaPlainText.Filter = "File Text (*.txt)|*.txt";
bukaPlainText.FilterIndex = 1;
bukaPlainText.RestoreDirectory = true;
if (DialogResult.OK == bukaPlainText.ShowDialog())
{
string baca_teks = "";

Universitas Sumatera Utara

A-3

StreamReader objReader = new
StreamReader(bukaPlainText.FileName);
baca_teks = objReader.ReadLine();
while (baca_teks != null)

{
plainText.Text += baca_teks;
baca_teks = objReader.ReadLine();
}
objReader.Close();
}
}
catch (Exception ex)
{
MessageBox.Show("Terjadi Kesalah pada \n- " + ex.ToString());
}
}
private void button5_Click(object sender, EventArgs e)
{
OpenFileDialog theDialog = new OpenFileDialog();
theDialog.Title = "Open Image File";
theDialog.Filter = "PNG(*.png)|*.png";
theDialog.InitialDirectory = @"D:\";
theDialog.ShowDialog();
if (theDialog.FileName.ToString() != "")

{
Image image = Image.FromFile(theDialog.FileName.ToString());
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Image = image;
imgPath = theDialog.FileName.ToString();
MessageBox.Show("Citra berhasil diimport!", "Informasi!",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void button14_Click_1(object sender, EventArgs e)
{
DateTime awal;
DateTime akhir;
TimeSpan total;
int waktupenyisipan;
awal = DateTime.Now;
if (eksdek.Text == "" || eksdek.Text == "12345678" || eksdek.Text
== "enkripsi")
{
MessageBox.Show("kunci tidak boleh kosong!", "Peringatan!",

MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
Process p = new Process(); // create process (i.e., the python
program
p.StartInfo.FileName = "C:\\Python27\\python.exe";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false; // make sure we can read
the output from stdout
p.StartInfo.Arguments = "internal_key.py " + eksdek.Text; //
start the python program with two parameters
p.Start(); // start the process (the python program)

Universitas Sumatera Utara

A-4

StreamReader s = p.StandardOutput;
String output = s.ReadToEnd();

string[] r = output.Split(new char[] { ' ' }); // get the
parameter
string q = r[0];
//string[] words = q.Split('.');
intdek.Text= output;
p.WaitForExit();
p.WaitForExit();
akhir = DateTime.Now;
total = akhir - awal;
waktupenyisipan = Convert.ToInt32(total.TotalMilliseconds);
MessageBox.Show("Waktu pembangkitan kunci adalah: " +
waktupenyisipan + " ms.");
}
}
private void button12_Click_1(object sender, EventArgs e)
{
DateTime awal;
DateTime akhir;
TimeSpan total;
int waktupenyisipan;

awal = DateTime.Now;
Process p = new Process(); // create process (i.e., the python
program
p.StartInfo.FileName = "C:\\Python27\\python.exe";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false; // make sure we can read the
output from stdout
p.StartInfo.Arguments = "dekripsi_pesan.py " + imgPath + " " +
eksdek.Text;// start the python program with two parameters
p.Start(); // start the process (the python program)
StreamReader s = p.StandardOutput;
String output = s.ReadToEnd();
string[] r = output.Split(new char[] { ' ' }); // get the parameter
string q = r[0];
//string[] words = q.Split('.');
plaindek.Text = output;
p.Close();
akhir = DateTime.Now;
total = akhir - awal;
waktupenyisipan = Convert.ToInt32(total.TotalMilliseconds);
MessageBox.Show("Waktu dekripsi adalah: " + waktupenyisipan + "
ms.");
}
private void button6_Click(object sender, EventArgs e)
{
DateTime awal;
DateTime akhir;
TimeSpan total;
int waktupenyisipan;
awal = DateTime.Now;
Process p = new Process(); // create process (i.e., the python
program
p.StartInfo.FileName = "C:\\Python27\\python.exe";
p.StartInfo.RedirectStandardOutput = true;

Universitas Sumatera Utara

A-5

p.StartInfo.UseShellExecute = false; // make sure we can read the
output from stdout
p.StartInfo.Arguments = "imgPadding.py " + imgPath + " " +
ekskey.Text + " " + plainText.Text.Replace(' ', '_');// start the python
program with two parameters
p.Start(); // start the process (the python program)
StreamReader s = p.StandardOutput;
String output = s.ReadToEnd();
string[] r = output.Split(new char[] { ' ' }); // get the parameter
string q = r[0];
string[] words = q.Split('.');
paddedImgPath = words[0];
FileStream fs = new FileStream(words[0] + ".png", FileMode.Open);
Image image = Image.FromStream(fs);
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox2.Image = image;
fs.Close();
akhir = DateTime.Now;
total = akhir - awal;
waktupenyisipan = Convert.ToInt32(total.TotalMilliseconds);
MessageBox.Show("Pesan Berhasil disisipkan!", "Informasi!",
MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show("Waktu penyisipan adalah: " + waktupenyisipan + "
ms.");
p.Close();
}
private void button10_Click(object sender, EventArgs e)
{
OpenFileDialog theDialog = new OpenFileDialog();
theDialog.Title = "Open Image File";
theDialog.Filter = "PNG(*.png)|*.png";
theDialog.InitialDirectory = @"D:\";
theDialog.ShowDialog();
if (theDialog.FileName.ToString() != "")
{
Image image = Image.FromFile(theDialog.FileName.ToString());
pictureBox4.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox4.Image = image;
imgPath = theDialog.FileName.ToString();
MessageBox.Show("Citra berhasil diimport!", "Informasi!",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void button9_Click(object sender, EventArgs e)
{
DateTime awal;
DateTime akhir;
TimeSpan total;
int waktupenyisipan;
awal = DateTime.Now;
Process p = new Process(); // create process (i.e., the python
program
p.StartInfo.FileName = "C:\\Python27\\python.exe";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false; // make sure we can read the
output from stdout

Universitas Sumatera Utara

A-6

p.StartInfo.Arguments = "imgExtractMsg.py " + imgPath;// start the
python program with two parameters
p.Start(); // start the process (the python program)
StreamReader s = p.StandardOutput;
String output = s.ReadToEnd();
string[] r = output.Split(new char[] { ' ' }); // get the parameter
string q = r[0];
string[] words = q.Split('.');
chipdek.Text = words[0];
akhir = DateTime.Now;
total = akhir - awal;
waktupenyisipan = Convert.ToInt32(total.TotalMilliseconds);
MessageBox.Show("Pesan berhasil diekstrak!", "Informasi!",
MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show("Waktu ekstrsi adalah: " + waktupenyisipan + "
ms.");
p.Close();
}
private void button1_Click_1(object sender, EventArgs e)
{
ekskey.Text = "";
plainText.Text = "";
intkey.Text = "";
cipherText.Text = "";
pictureBox1.Image = null;
pictureBox2.Image = null;
}
private void label7_Click(object sender, EventArgs e)
{
}
private void button2_Click_1(object sender, EventArgs e)
{
eksdek.Text = "";
chipdek.Text = "";
plaindek.Text = "";
intdek.Text = "";
pictureBox4.Image = null;
}
}
}

2. Function.py
import binascii
import Image
def ascii_to_bit(message):
return bin(int(binascii.hexlify(message), 16)).replace("b",
"").rjust(8,'0')
def bit_to_ascii(bit):
ascii = '';
for i in range(0, len(bit), 8):
n = int(bit[i:i+8], 2)
ascii += binascii.unhexlify('%x' %n)
return ascii

Universitas Sumatera Utara

A-7

def divide_side(message_bit):
i = 0
left = ""
right = ""
half_size = len(message_bit)/2;
while (i < half_size):
left = left + message_bit[i];
right = right + message_bit[i+half_size];
i+=1
return left,right
def get_key_plus_bit(key_bit):
pc_1 = [57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59,
51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, 63, 55, 47, 39, 31, 23, 15, 7, 62,
54, 46, 38, 30, 22,14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4]
key_plus_bit = []
for i in range(0, len(pc_1)):
key_plus_bit.append(key_bit[pc_1[i]-1])
return key_plus_bit
def shift_bit(pre_bit, num_of_shift):
for i in range(num_of_shift):
temp_bit = pre_bit[0]
pre_bit = pre_bit[1:]
pre_bit += temp_bit
return pre_bit
def right_shift_bit(pre_bit, num_of_shift):
for i in range(num_of_shift):
temp_bit = pre_bit[27]
pre_bit = pre_bit[:27]
pre_bit = temp_bit + pre_bit
return pre_bit
def get_c1_to_c16(c, d):
shift = [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1]
for i in range(16):
c.append(shift_bit(c[i], shift[i]))
d.append(shift_bit(d[i], shift[i]))
return c, d
def join(c, d):
key_plus_block = []
for i in range(17):
key_plus_block.append(c[i]+d[i])
return key_plus_block
def get_key_plus_bit_2(cd_block):
pc_2 = [14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 23, 19, 12, 4, 26, 8,
16, 7, 27, 20, 13, 2, 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49,
39, 56, 34, 53, 46, 42, 50, 36, 29, 32]
key_plus_bit_2 = []
for i in range(1, len(cd_block)):
cd_temp = ""
for j in range (0, len(pc_2)):
cd_temp += cd_block[i][pc_2[j]-1];
key_plus_bit_2.append(cd_temp)
return key_plus_bit_2
def message_permutation_1(message):

Universitas Sumatera Utara

A-8

ip = [58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, 62, 54,
46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, 57, 49, 41, 33, 25, 17,
9, 1, 59, 51, 43, 35, 27, 19, 11, 3, 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47,
39, 31, 23, 15, 7];
message_permutation_1 = ""
for i in range(0, len(ip)):
message_permutation_1 += message[ip[i]-1];
return message_permutation_1
def e_bit(message):
e = [32, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11, 12, 13, 12, 13, 14,
15, 16, 17, 16, 17, 18, 19, 20, 21, 20, 21, 22, 23, 24, 25, 24, 25, 26, 27, 28,
29, 28, 29, 30, 31, 32, 1];
e_bit = ""
for i in range(0,len(e)):
e_bit += message[e[i]-1];
return e_bit
def xor_bit(e_rn,kn, x):
result_bit = ""
for i in range (0,len(e_rn)):
result_bit += xor(e_rn[i], kn[x][i])
return result_bit
def xor(bit1, bit2):
if(bit1 == '1'):
if(bit2=='1'):
return'0'
else:
return'1'
else:
if(bit2=='1'):
return '1'
else:
return'0'
def b_n(k_xor):
b_n = [];
for i in range (0, len(k_xor), 6):
temp = ""
for j in range(i, i + 6):
temp += k_xor[j]
b_n.append(temp)
return b_n
def s_n(b_n, i, s):
row = int(b_n[i][0]+b_n[i][5], 2)
column = int(b_n[i][1]+b_n[i][2]+b_n[i][3]+b_n[i][4], 2)
return bin(s[row][column]).replace("0b", "").zfill(4);
def f(s_box):
p = [16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, 2, 8, 24,
14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25];
temp = ""
for i in range(0, len(p)):
temp+=(s_box[p[i]-1])
return temp
def rn(ln_min1, f):
temp = ""
for i in range(0, len(f)):

Universitas Sumatera Utara

A-9

temp += xor(ln_min1[i], f[i])
return temp
def lnrn(kn, x, l, r):
e = e_bit(r)
m = xor_bit(e, kn, x)
b = b_n(m)
s1 = [[14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7],[0, 15, 7, 4,
14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8],[4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9,
7, 3, 10, 5, 0],[ 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13]];
s2 = [[15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10],[ 3, 13, 4, 7,
15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5],[0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12,
6, 9, 3, 2, 15],[13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9]];
s3 = [[10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8],[13, 7, 0, 9,
3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1],[13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2,
12, 5, 10, 14, 7], [1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12]];
s4 = [[7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15], [13, 8, 11,
5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9], [10, 6, 9, 0, 12, 11, 7, 13, 15, 1,
3, 14, 5, 2, 8, 4], [3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14]];
s5 = [[2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9], [14, 11, 2,
12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 16], [4, 2, 1, 11, 10, 13, 7, 8, 15, 9,
12, 5, 6, 3, 0, 14], [11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3]];
s6 = [[12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11], [10, 15, 4,
2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8], [9, 14, 15, 5, 2, 8, 12, 3, 7, 0,
4, 10, 1, 13, 11, 6], [4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13]];
s7 = [[4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1], [13, 0, 11,
7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6], [1, 4, 11, 13, 12, 3, 7, 14, 10,
15, 6, 8, 0, 5, 9, 2], [6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12]];
s8 =[[13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7], [1, 15, 13, 8,
10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2], [7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10,
13, 15, 3, 5, 8], [2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11]];
s1b1
s2b2
s3b3
s4b4
s5b5
s6b6
s7b7
s8b8

=
=
=
=
=
=
=
=

s_n(b,
s_n(b,
s_n(b,
s_n(b,
s_n(b,
s_n(b,
s_n(b,
s_n(b,

0,
1,
2,
3,
4,
5,
6,
7,

s1)
s2)
s3)
s4)
s5)
s6)
s7)
s8)

s_box = s1b1 + s2b2 + s3b3 + s4b4 + s5b5 + s6b6 + s7b7 + s8b8
f_var = f(s_box)
result = rn(l, f_var)
return result
def ip_min(rnln):

Universitas Sumatera Utara

A-10

ip_inv = [40, 8, 48, 16, 56, 24, 64, 32, 39, 7, 47, 15, 55, 23, 63, 31, 38,
6, 46, 14, 54, 22, 62, 30, 37, 5, 45, 13, 53, 21, 61, 29, 36, 4, 44, 12, 52,
20, 60, 28, 35, 3, 43, 11, 51, 19, 59, 27, 34, 2, 42, 10, 50, 18, 58, 26, 33,
1, 41, 9, 49, 17, 57, 25];
temp = [];
for i in range(0, len(ip_inv)):
temp.append(rnln[ip_inv[i]-1]);
encrypt_m_bit = ''.join(temp)
return encrypt_m_bit
def get_img_res(imgPath, param):
if(param == 'height'):
param = 0
else:
param = 1
img = Image.open(imgPath)
imgSize = img.size
return imgSize[param]
def get_img_px(imgPath):
img = Image.open(imgPath)
imgPx = img.load()
x = get_img_res(imgPath, 'height'); # x -> height
y = get_img_res(imgPath, 'width'); # y -> width
plainPx = []
for i in range (x):
for j in range (y): plainPx.append(imgPx[i, j])
return plainPx
# Get blue pixels from image for padding process
def get_bluePx0(rgbaPx):
bluePx = []
for i in range (0, len(rgbaPx)):
bluePx.append(rgbaPx[i][2])
return bluePx
# Get blue pixels from image to get padded message
def get_bluePx1(rgbaPx):
bluePx = []
for i in range (0, len(rgbaPx)):
if(rgbaPx[i][3] == 0): # If alpha 0, that's the message limit
break
bluePx.append(rgbaPx[i][2])
return bluePx
def pad_bluePx(bluePx, msgBit):
blueBit = []
for i in range(0, len(msgBit)):
bluePxList = list(bin(bluePx[i]).replace("0b", ""))
bluePxList[len(bluePxList)-1] = msgBit[i]
joinedBluePx = ''.join(bluePxList)
newBluePx = int(joinedBluePx, 2)
blueBit.append(newBluePx)
return blueBit
def set_bluePx_in_plainPx(blue_pixel, plain_pixel):
temp = []
for i in range(0, len(blue_pixel)):
temp = list(plain_pixel[i])
temp[2] = blue_pixel[i]

Universitas Sumatera Utara

A-11

plain_pixel[i] = temp
return plain_pixel
def extract_bluePx(bluePx):
msgBit = ''
for i in range(0, len(bluePx)):
bluePxList = list(bin(bluePx[i]).replace("0b", ""))
msgBit += bluePxList[len(bluePxList)-1]
return msgBit
def create_png(imgPath, rgbaPx, imgName, msgLength):
x = get_img_res(imgPath, 'height')# x -> height
y = get_img_res(imgPath, 'width')# y -> width
img = Image.new('RGBA', (x, y), 'white')
k = 0
for i in range(x):
for j in range(y):
R = rgbaPx[k][0]
G = rgbaPx[k][1]
B = rgbaPx[k][2]
if( k == msgLength ):
A = 0
else:
A = 255
img.putpixel((i, j), (R, G, B, A))
k += 1
return img.save(imgName, 'PNG')
def get_key_bin(key):
key_bin = ascii_to_bit(key)
key_bin_pc1 = get_key_plus_bit(key_bin)
key_bin_div = divide_side(key_bin_pc1)
c0 = key_bin_div[0]
d0 = key_bin_div[1]
c = [c0]
d = [d0]
key_bin_c1_c16 = get_c1_to_c16(c, d)
c0 = key_bin_c1_c16[0]
d0 = key_bin_c1_c16[1]
key_bin_join = join(c0,d0)
key_bin_pc2 = get_key_plus_bit_2(key_bin_join)
return key_bin_pc2
def encrypt_m(key_bin_pc2, message):
message_bin = ''
for i in range(0, 8):
temp_bin = ascii_to_bit(message[i])
message_bin += temp_bin
ip1 = message_permutation_1(message_bin)
message_divide = divide_side(ip1)
l0 = message_divide[0]
r0 = message_divide[1]
ln = l0
rn = r0
x = 0
while(x < 16):
r_temp = rn

Universitas Sumatera Utara

A-12

rn = lnrn(key_bin_pc2, x, ln, rn)
ln = r_temp
x += 1
rnln = str(rn) + str(ln)
joined_c = ""
c = ip_min(rnln)
joined_c += c
return joined_c
def get_cipher_message(key_bin_pc2, message):
padded_m = ''
for i in range(0, len(message), 8):
char_length = len(message[i:i+8])
if ( char_length < 8 ):
padded_m += message[i:i+char_length].ljust(8,' ')
else:
padded_m += message[i:i+8].ljust(8,' ')
message = padded_m
join_e_m = ''
for i in range(0, len(message), 8):
join_e_m += encrypt_m(key_bin_pc2,message[i:i+8])
return join_e_m
def decrypt_m(key_bin_pc2, message_bin):
ip1 = message_permutation_1(message_bin)
message_divide = divide_side(ip1)
l0 = message_divide[0]
r0 = message_divide[1]
ln = l0
rn = r0
x = 15
while(x >- 1):
r_temp = rn
rn = lnrn(key_bin_pc2, x, ln, rn)
ln = r_temp
x -= 1
rnln = str(rn) + str(ln)
joined_c = ""
c = ip_min(rnln)
joined_c += c
return joined_c
def get_plain_message(key_bin_pc2, message):
join_e_m = ''
for i in range(0, len(message), 64):
join_e_m += decrypt_m(key_bin_pc2, message[i:i+64])
return join_e_m

Universitas Sumatera Utara

A-13

3. Internal_key.py
from function import *
import sys
#mengambil nilai dari argument ekskey.text
key = sys.argv[1]
key_bin_pc2 = get_key_bin(key)
print str(key_bin_pc2)

4. Enkripsi_pesan.py
from function import *
import binascii
import sys
message = sys.argv[1].replace('_', ' ');
key = sys.argv[2]
key_bin_pc2 = get_key_bin(key)
print get_cipher_message(key_bin_pc2, message)

5. ImgPadding.py
from function import *
import sys
imgPath = sys.argv[1]
key = sys.argv[2]
message = sys.argv[3].replace('_', ' ');
key_bin_pc2 = get_key_bin(key)
joined_c = get_cipher_message(key_bin_pc2, message)
msgBit = joined_c
msgLength = len(msgBit)
plainPx = get_img_px(imgPath)
bluePx = get_bluePx0(plainPx)
paddedBluePx = pad_bluePx(bluePx, msgBit)
paddedPlainPx = set_bluePx_in_plainPx(paddedBluePx, plainPx)
imgName = "D:\\PaddedImage.png"
create_png(imgPath, paddedPlainPx, imgName, msgLength)
print imgName

Universitas Sumatera Utara

A-14

6. Dekripsi_pesan.py
from function import *
import binascii
import sys
key = sys.argv[2]
imgPath = sys.argv[1]
key_bin_pc2 = get_key_bin(key)
plainPx = get_img_px(imgPath)
bluePx = get_bluePx1(plainPx)
message = extract_bluePx(bluePx)
plain_bit = get_plain_message(key_bin_pc2, message)
print bit_to_ascii(plain_bit)

7. ImgExtractMsg.py
from function import *
import sys
imgPath = sys.argv[1]
plainPx = get_img_px(imgPath)
bluePx = get_bluePx1(plainPx)
msgBit = extract_bluePx(bluePx)
print str(msgBit)

Universitas Sumatera Utara

B-1

CURRICULUM VITAE
-------------------------------------------------------------------------------------------------------Data Pribadi

Nama

: Hengky Prayson Fangaro Gulo

Tempat/Tanggal Lahir : Gunung Sitoli / 28 Agustus 1992
Tinggi/Berat Badan

: 169 cm / 100 kg

Agama

: Kristen Protestan

Kewarganegaraan

: Indonesia

Alamat

: Jl. Jahe 6 no.2 Perumnas Simalingkar Medan

Alamat Orang Tua

: Jl. Jahe 6 no.2 Perumnas Simalingkar Medan

Telp/ Hp

: 085362402072

Email

: hengkygulo@gmail.com

-------------------------------------------------------------------------------------------------------Riwayat Pendidikan
[2010 – 2016]

: S1 Ilmu Komputer Universitas Sumatera Utara, Medan

[2007 – 2010]

: SMK Negeri 9 Medan

[2004 – 2007]

: SMP Negeri 10 Medan

[1999 – 2004]

: SD Negeri Tohia Gunung Sitoli

Universitas Sumatera Utara

B-2

-------------------------------------------------------------------------------------------------------Keahlian/Kursus
Keahlian Komputer

Bahasa :

Pemrograman

:Pyhton, C#, C++

English

Database

: MySQL

Indonesia

Perkantoran

: Microsoft Office

Universitas Sumatera Utara