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

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.Splitnew char[] { }; get the parameter string q = r[0]; string[] words = q.Split.; chipdek.Text = words[0]; akhir = DateTime.Now; total = akhir - awal; waktupenyisipan = Convert.ToInt32total.TotalMilliseconds; MessageBox.ShowPesan berhasil diekstrak, Informasi, MessageBoxButtons.OK, MessageBoxIcon.Information; MessageBox.ShowWaktu ekstrsi adalah: + waktupenyisipan + ms.; p.Close; } private void button1_Click_1object sender, EventArgs e { ekskey.Text = ; plainText.Text = ; intkey.Text = ; cipherText.Text = ; pictureBox1.Image = null; pictureBox2.Image = null; } private void label7_Clickobject sender, EventArgs e { } private void button2_Click_1object sender, EventArgs e { eksdek.Text = ; chipdek.Text = ; plaindek.Text = ; intdek.Text = ; pictureBox4.Image = null; } } }

2. Function.py

import binascii import Image def ascii_to_bitmessage: return binintbinascii.hexlifymessage, 16.replaceb, .rjust8,0 def bit_to_asciibit: ascii = ; for i in range0, lenbit, 8: n = intbit[i:i+8], 2 ascii += binascii.unhexlifyx n return ascii Universitas Sumatera Utara def divide_sidemessage_bit: i = 0 left = right = half_size = lenmessage_bit2; 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_bitkey_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 range0, lenpc_1: key_plus_bit.appendkey_bit[pc_1[i]-1] return key_plus_bit def shift_bitpre_bit, num_of_shift: for i in rangenum_of_shift: temp_bit = pre_bit[0] pre_bit = pre_bit[1:] pre_bit += temp_bit return pre_bit def right_shift_bitpre_bit, num_of_shift: for i in rangenum_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_c16c, d: shift = [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1] for i in range16: c.appendshift_bitc[i], shift[i] d.appendshift_bitd[i], shift[i] return c, d def joinc, d: key_plus_block = [] for i in range17: key_plus_block.appendc[i]+d[i] return key_plus_block def get_key_plus_bit_2cd_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 range1, lencd_block: cd_temp = for j in range 0, lenpc_2: cd_temp += cd_block[i][pc_2[j]-1]; key_plus_bit_2.appendcd_temp return key_plus_bit_2 def message_permutation_1message: Universitas Sumatera Utara 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 range0, lenip: message_permutation_1 += message[ip[i]-1]; return message_permutation_1 def e_bitmessage: 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 range0,lene: e_bit += message[e[i]-1]; return e_bit def xor_bite_rn,kn, x: result_bit = for i in range 0,lene_rn: result_bit += xore_rn[i], kn[x][i] return result_bit def xorbit1, bit2: ifbit1 == 1: ifbit2==1: return0 else: return1 else: ifbit2==1: return 1 else: return0 def b_nk_xor: b_n = []; for i in range 0, lenk_xor, 6: temp = for j in rangei, i + 6: temp += k_xor[j] b_n.appendtemp return b_n def s_nb_n, i, s: row = intb_n[i][0]+b_n[i][5], 2 column = intb_n[i][1]+b_n[i][2]+b_n[i][3]+b_n[i][4], 2 return bins[row][column].replace0b, .zfill4; def fs_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 range0, lenp: temp+=s_box[p[i]-1] return temp def rnln_min1, f: temp = for i in range0, lenf: Universitas Sumatera Utara temp += xorln_min1[i], f[i] return temp def lnrnkn, x, l, r: e = e_bitr m = xor_bite, kn, x b = b_nm 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 = s_nb, 0, s1 s2b2 = s_nb, 1, s2 s3b3 = s_nb, 2, s3 s4b4 = s_nb, 3, s4 s5b5 = s_nb, 4, s5 s6b6 = s_nb, 5, s6 s7b7 = s_nb, 6, s7 s8b8 = s_nb, 7, s8 s_box = s1b1 + s2b2 + s3b3 + s4b4 + s5b5 + s6b6 + s7b7 + s8b8 f_var = fs_box result = rnl, f_var return result def ip_minrnln: Universitas Sumatera Utara 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 range0, lenip_inv: temp.appendrnln[ip_inv[i]-1]; encrypt_m_bit = .jointemp return encrypt_m_bit def get_img_resimgPath, param: ifparam == height: param = 0 else: param = 1 img = Image.openimgPath imgSize = img.size return imgSize[param] def get_img_pximgPath: img = Image.openimgPath imgPx = img.load x = get_img_resimgPath, height; x - height y = get_img_resimgPath, width; y - width plainPx = [] for i in range x: for j in range y: plainPx.appendimgPx[i, j] return plainPx Get blue pixels from image for padding process def get_bluePx0rgbaPx: bluePx = [] for i in range 0, lenrgbaPx: bluePx.appendrgbaPx[i][2] return bluePx Get blue pixels from image to get padded message def get_bluePx1rgbaPx: bluePx = [] for i in range 0, lenrgbaPx: ifrgbaPx[i][3] == 0: If alpha 0, thats the message limit break bluePx.appendrgbaPx[i][2] return bluePx def pad_bluePxbluePx, msgBit: blueBit = [] for i in range0, lenmsgBit: bluePxList = listbinbluePx[i].replace0b, bluePxList[lenbluePxList-1] = msgBit[i] joinedBluePx = .joinbluePxList newBluePx = intjoinedBluePx, 2 blueBit.appendnewBluePx return blueBit def set_bluePx_in_plainPxblue_pixel, plain_pixel: temp = [] for i in range0, lenblue_pixel: temp = listplain_pixel[i] temp[2] = blue_pixel[i] Universitas Sumatera Utara plain_pixel[i] = temp return plain_pixel def extract_bluePxbluePx: msgBit = for i in range0, lenbluePx: bluePxList = listbinbluePx[i].replace0b, msgBit += bluePxList[lenbluePxList-1] return msgBit def create_pngimgPath, rgbaPx, imgName, msgLength: x = get_img_resimgPath, height x - height y = get_img_resimgPath, width y - width img = Image.newRGBA, x, y, white k = 0 for i in rangex: for j in rangey: R = rgbaPx[k][0] G = rgbaPx[k][1] B = rgbaPx[k][2] if k == msgLength : A = 0 else: A = 255 img.putpixeli, j, R, G, B, A k += 1 return img.saveimgName, PNG def get_key_binkey: key_bin = ascii_to_bitkey key_bin_pc1 = get_key_plus_bitkey_bin key_bin_div = divide_sidekey_bin_pc1 c0 = key_bin_div[0] d0 = key_bin_div[1] c = [c0] d = [d0] key_bin_c1_c16 = get_c1_to_c16c, d c0 = key_bin_c1_c16[0] d0 = key_bin_c1_c16[1] key_bin_join = joinc0,d0 key_bin_pc2 = get_key_plus_bit_2key_bin_join return key_bin_pc2 def encrypt_mkey_bin_pc2, message: message_bin = for i in range0, 8: temp_bin = ascii_to_bitmessage[i] message_bin += temp_bin ip1 = message_permutation_1message_bin message_divide = divide_sideip1 l0 = message_divide[0] r0 = message_divide[1] ln = l0 rn = r0 x = 0 whilex 16: r_temp = rn Universitas Sumatera Utara rn = lnrnkey_bin_pc2, x, ln, rn ln = r_temp x += 1 rnln = strrn + strln joined_c = c = ip_minrnln joined_c += c return joined_c def get_cipher_messagekey_bin_pc2, message: padded_m = for i in range0, lenmessage, 8: char_length = lenmessage[i:i+8] if char_length 8 : padded_m += message[i:i+char_length].ljust8, else: padded_m += message[i:i+8].ljust8, message = padded_m join_e_m = for i in range0, lenmessage, 8: join_e_m += encrypt_mkey_bin_pc2,message[i:i+8] return join_e_m def decrypt_mkey_bin_pc2, message_bin: ip1 = message_permutation_1message_bin message_divide = divide_sideip1 l0 = message_divide[0] r0 = message_divide[1] ln = l0 rn = r0 x = 15 whilex - 1: r_temp = rn rn = lnrnkey_bin_pc2, x, ln, rn ln = r_temp x -= 1 rnln = strrn + strln joined_c = c = ip_minrnln joined_c += c return joined_c def get_plain_messagekey_bin_pc2, message: join_e_m = for i in range0, lenmessage, 64: join_e_m += decrypt_mkey_bin_pc2, message[i:i+64] return join_e_m Universitas Sumatera Utara

3. Internal_key.py