Implementasi Kombinasi Algoritma Vigenere dan Algoritma Data Encryption Standard (DES) pada Aplikasi Short Message Service (SMS) Berbasis Windows Phone
59
LISTING PROGRAM
Form Utama :
using
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Net;
System.Windows;
System.Windows.Controls;
System.Windows.Navigation;
Microsoft.Phone.Controls;
Microsoft.Phone.Shell;
vigenere_des.Resources;
namespace vigenere_des
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Application.Current.Terminate();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new
Uri("/Page1.xaml",
UriKind.RelativeOrAbsolute));
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new
Uri("/Page2.xaml",
UriKind.RelativeOrAbsolute));
}
private void Button_Click_3(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new
Uri("/Page3.xaml",
UriKind.RelativeOrAbsolute));
}
private void Button_Click_4(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new
Uri("/Page4.xaml",
UriKind.RelativeOrAbsolute));
}
}
}
Universitas Sumatera Utara
60
Form Buat Pesan :
using
using
using
using
using
using
using
using
using
using
using
using
using
using
System;
System.IO;
System.Collections.Generic;
System.Linq;
System.Net;
System.Windows;
System.Windows.Controls;
System.Windows.Navigation;
Microsoft.Phone.Controls;
Microsoft.Phone.Shell;
Microsoft.Phone.UserData;
System.Security.Cryptography;
System.Text;
Microsoft.Phone.Tasks;
namespace vigenere_des
{
public partial class Page3 : PhoneApplicationPage
{
public Page3()
{
InitializeComponent();
}
string enkripsiv(string pesan, string kunci)
{
int pjgkunci = kunci.Length;
int pjgpesan = pesan.Length;
string hasil = "";
for (int i = 0; i < pjgpesan; i++)
{
hasil = hasil + Convert.ToChar((((int)pesan[i]
(int)kunci[i % (pjgkunci)]) % 95) + 32);
}
+
return hasil;
}
private void Button2_Click(object sender, RoutedEventArgs e)
{
string message = plaint.Text;
string key = plaink.Text;
ciphert.Text = enkripsiv(message, key);
}
private void Button3_Click(object sender, RoutedEventArgs e)
{
Cryptographer
cryptographer
=
new
Cryptographer(Algorithms.DES);
cipherk.Text = cryptographer.EncryptionStart(plaink.Text,
desk.Text.ToUpper(), false);
}
Universitas Sumatera Utara
61
private void Button4_Click(object sender, RoutedEventArgs e)
{
SmsComposeTask smsComposeTask = new SmsComposeTask();
smsComposeTask.To = buku_telepon.Text;
smsComposeTask.Body = ciphert.Text;
smsComposeTask.Show();
}
string data;
private void txtName_GotFocus(object sender, RoutedEventArgs
e)
{
TextBox t = sender as TextBox;
data = t.Text;
t.Text = string.Empty;
}
private void txtName_LostFocus(object sender, RoutedEventArgs
e)
{
TextBox t = sender as TextBox;
if (t.Text.Equals(string.Empty))
{
t.Text = data;
}
}
private void Button1_Click(object sender, RoutedEventArgs e)
{
Contacts cons = new Contacts();
cons.SearchCompleted
+=
new
EventHandler(Contacts_SearchCompleted);
cons.SearchAsync(String.Empty, FilterKind.None, "Contacts
Test #1");
}
void
Contacts_SearchCompleted(object
ContactsSearchEventArgs e)
{
System.Text.StringBuilder
sb
System.Text.StringBuilder();
sender,
=
new
foreach (Contact con in e.Results)
{
sb.AppendLine(con.DisplayName);
}
MessageBox.Show(sb.ToString());
}
}
}
Universitas Sumatera Utara
62
Form Dekrip Pesan :
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Net;
System.Windows;
System.Windows.Controls;
System.Windows.Navigation;
Microsoft.Phone.Controls;
Microsoft.Phone.Shell;
namespace vigenere_des
{
public partial class Page4 : PhoneApplicationPage
{
public Page4()
{
InitializeComponent();
}
string dekripsiv(string pesan, string kunci)
{
int pjgkunci = kunci.Length;
int pjgpesan = pesan.Length;
string hasil = "";
for (int i = 0; i < pjgpesan; i++)
{
if ((((int)pesan[i] - 32) - (int)kunci[i % (pjgkunci
- 1)]) < -63)
{
hasil = hasil + Convert.ToChar((((int)pesan[i] 32) - (int)kunci[i % (pjgkunci)]) + 190);
}
else if ((((int)pesan[i] - 32) - (int)kunci[i %
(pjgkunci - 1)]) < 32)
{
hasil = hasil + Convert.ToChar((((int)pesan[i] 32) - (int)kunci[i % (pjgkunci)]) + 95);
}
else
{
hasil = hasil + Convert.ToChar((((int)pesan[i] 32) - (int)kunci[i % (pjgkunci)]) % 95);
}
}
return hasil;
}
private void Button3_Click(object sender, RoutedEventArgs e)
{
string message = ciphert1.Text;
string key = plaink1.Text;
plaint1.Text = dekripsiv(message, key);
}
private void Button2_Click(object sender, RoutedEventArgs e)
Universitas Sumatera Utara
63
{
Cryptographer
cryptographer
Cryptographer(Algorithms.DES);
plaink1.Text
cryptographer.DecryptionStart(cipherk1.Text,
false);
}
private
void
TextChangedEventArgs e)
{
=
new
=
desk.Text.ToUpper(),
plaint_TextChanged(object
sender,
}
string data;
private void txtName_GotFocus(object sender, RoutedEventArgs
e)
{
TextBox t = sender as TextBox;
data = t.Text;
t.Text = string.Empty;
}
private void txtName_LostFocus(object sender, RoutedEventArgs
e)
{
TextBox t = sender as TextBox;
if (t.Text.Equals(string.Empty))
{
t.Text = data;
}
}
}
}
Class Algorithms.cs :
using System;
using System.Collections.Generic;
using System.Text;
namespace vigenere_des
{
class Algorithms
{
public static readonly int DES = 0;
}
}
Universitas Sumatera Utara
64
Class Cryptographer.cs :
using
using
using
using
System;
System.Collections.Generic;
System.Text;
System.Threading;
namespace vigenere_des
{
class Cryptographer
{
CommonProcess cProcess = null;
public Cryptographer(int algorithm_number)
{
if (Algorithms.DES == algorithm_number)
{
cProcess = new DES.ProcessDES();
}
}
public string EncryptionStart(string text, string key, bool
IsBinary)
{
return cProcess.EncryptionStart(text, key, IsBinary);
}
public string DecryptionStart(string text, string key, bool
IsBinary)
{
return cProcess.DecryptionStart(text, key, IsBinary);
}
}
}
Class Commonprocess.cs :
using System;
using System.Collections.Generic;
using System.Text;
namespace vigenere_des
{
abstract class CommonProcess
{
public abstract string EncryptionStart(string
key, bool IsTextBinary);
public abstract string
key, bool IsTextBinary);
}
}
DecryptionStart(string
text,
string
text,
string
Universitas Sumatera Utara
65
Class DESData.cs :
using System;
using System.Collections.Generic;
using System.Text;
namespace vigenere_des.DES
{
#region tabel permutasi
class DESData
{
public static readonly int[] pc_1 ={
9, 1, 58, 50,
42,
51, 43, 35,
27,
36, 63, 55,
47,
54, 46, 38,
30,
37, 29, 21,
13,
57, 49, 41, 33, 25, 17,
34, 26, 18, 10, 2, 59,
19, 11, 3, 60, 52, 44,
39, 31, 23, 15, 7, 62,
22, 14, 6, 61, 53, 45,
5, 28, 20, 12, 4 };
public static readonly int[] 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
};
public static readonly int[] 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 };
public static readonly int[] ip_1 ={ 40, 8, 48, 16,
64, 32, 39, 7,
47, 15, 55, 23,
38, 6, 46, 14,
54, 22, 62, 30,
45, 13, 53, 21,
61, 29, 36, 4,
52, 20, 60, 28,
35, 3, 43, 11,
59, 27, 34, 2,
56, 24,
63, 31,
37,
5,
44,
12,
51,
19,
Universitas Sumatera Utara
66
42, 10, 50, 18, 58, 26,
33, 1, 41, 9,
49, 17, 57, 25 };
public static readonly int[] pc_e ={ 32, 1, 2, 3,
6, 7, 8, 9, 8,
9, 10, 11, 12,
14, 15, 16,
17, 16, 17, 18,
20, 21, 22,
23, 24, 25, 24,
28, 29, 28,
29, 30, 31, 32,
4, 5, 4, 5,
13, 12, 13,
19, 20, 21,
25, 26, 27,
1 };
public static readonly int[] pc_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 };
public static readonly int[] nrOfShifts ={ 0, 1, 1, 2, 2, 2,
2, 2, 2, 1,
2, 2, 2, 2, 2, 2, 1
};
public static List sBoxes = new List();
static DESData()
{
sBoxes.Add(s1);
sBoxes.Add(s2);
sBoxes.Add(s3);
sBoxes.Add(s4);
sBoxes.Add(s5);
sBoxes.Add(s6);
sBoxes.Add(s7);
sBoxes.Add(s8);
}
public static readonly int[,] 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 } };
public static readonly int[,] s2 ={ { 15,
4, 9, 7, 2, 13, 12, 0, 5, 10 },
{ 3, 13,
12, 0, 1, 10, 6, 9, 11, 5 },
{ 0, 14,
1, 5, 8, 12, 6, 9, 3, 2, 15 },
{ 13, 8,
11, 6, 7, 12, 0, 5, 14, 9 } };
1, 8, 14, 6, 11, 3,
4, 7, 15, 2, 8, 14,
7, 11, 10, 4, 13,
10, 1, 3, 15, 4, 2,
Universitas Sumatera Utara
67
public static readonly int[,] s3 ={ { 10,
5, 1, 13, 12, 7, 11, 4, 2, 8 },
{ 13, 7,
2, 8, 5, 14, 12, 11, 15, 1 },
{ 13, 6,
11, 1, 2, 12, 5, 10, 14, 7 },
{ 1, 10,
4, 15, 14, 3, 11, 5, 2, 12 } };
0, 9, 14, 6, 3, 15,
0, 9, 3, 4, 6, 10,
4, 9, 8, 15, 3, 0,
13, 0, 6, 9, 8, 7,
public static readonly int[,] s4 ={ { 7, 13, 14, 3, 0, 6,
10, 1, 2, 8, 5, 11, 12, 4, 15 },
{ 13, 8, 11, 5, 6, 15, 0,
4, 7, 2, 12, 1, 10, 14, 9 },
{ 10, 6, 9, 0, 12, 11,
13, 15, 1, 3, 14, 5, 2, 8, 4 },
{ 3, 15, 0, 6, 10, 1, 13,
9, 4, 5, 11, 12, 7, 2, 14 } };
9,
3,
7,
8,
public static readonly int[,] 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, 6 },
{ 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 } };
public static readonly int[,] 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 } };
public static readonly int[,] 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 } };
public static readonly int[,] s8 ={ {
1, 10, 9, 3, 14, 5, 0, 12, 7 },
{ 1,
12, 5, 6, 11, 0, 14, 9, 2 },
{ 7,
0, 6, 10, 13, 15, 3, 5, 8 },
{ 2,
15, 12, 9, 0, 3, 5, 6, 11 } };
}
#endregion
13, 2, 8, 4, 6, 15, 11,
15, 13, 8, 10, 3, 7, 4,
11, 4, 1, 9, 12, 14, 2,
1, 14, 7, 4, 10, 8, 13,
Universitas Sumatera Utara
68
#region pembuatan kelas kunci
class Keys
{
public string[] Cn = new string[17];
public string[] Dn = new string[17];
public string[] Kn = new string[16];
}
#endregion
}
Class ProcessDES.cs :
using System;
using System.Collections.Generic;
using System.Text;
namespace vigenere_des.DES
{
class ProcessDES : CommonProcess
{
public ProcessDES()
{
}
#region proses enkripsi
public override string EncryptionStart(string
key, bool IsTextBinary)
{
#region pengambilan 16 kunci
text,
string
string binary_key = this.FromTextToBinary(key);
string
key_plus
=
this.DoPermutation(binary_key,
DESData.pc_1);
string C0 = "", D0 = "";
C0 = this.SetLeftHalvesKey(key_plus);
D0 = this.SetRightHalvesKey(key_plus);
Keys keys = this.SetAllKeys(C0, D0);
#endregion
#region proses enkripsi
string binaryText = "";
if (IsTextBinary == false)
{
binaryText = this.FromTextToBinary(text);
}
else
{
binaryText = text;
}
Universitas Sumatera Utara
69
binaryText = this.setTextMutipleOf64Bits(binaryText);
StringBuilder
EncryptedTextBuilder
StringBuilder(binaryText.Length);
=
new
for (int i = 0; i < (binaryText.Length / 64); i++)
{
string
PermutatedText
this.DoPermutation(binaryText.Substring(i * 64, 64), DESData.ip);
=
string L0 = "", R0 = "";
L0 = this.SetLeftHalvesKey(PermutatedText);
R0 = this.SetRightHalvesKey(PermutatedText);
string FinalText = this.FinalEncription(L0, R0, keys,
false);
string selesai = BinaryStringToHexString(FinalText);
EncryptedTextBuilder.Append(selesai);
}
return EncryptedTextBuilder.ToString();
#endregion
}
#endregion
#region proses dekripsi
public override string DecryptionStart(string
key, bool IsTextBinary)
{
#region pengambilan 16 kunci
text,
string
string binary_key = this.FromTextToBinary(key);
string
key_plus
=
this.DoPermutation(binary_key,
DESData.pc_1);
string C0 = "", D0 = "";
C0 = this.SetLeftHalvesKey(key_plus);
D0 = this.SetRightHalvesKey(key_plus);
Keys keys = this.SetAllKeys(C0, D0);
#endregion
#region proses dekripsi
string binaryText = "";
if (IsTextBinary == false)
{
binaryText = this.FromHexToBinary(text);
}
else
{
Universitas Sumatera Utara
70
binaryText = text;
}
binaryText = this.setTextMutipleOf64Bits(binaryText);
StringBuilder
DecryptedTextBuilder
StringBuilder(binaryText.Length);
=
for (int i = 0; i < (binaryText.Length / 64); i++)
{
string
PermutatedText
this.DoPermutation(binaryText.Substring(i * 64, 64), DESData.ip);
new
=
string L0 = "", R0 = "";
L0 = this.SetLeftHalvesKey(PermutatedText);
R0 = this.SetRightHalvesKey(PermutatedText);
string FinalText = this.FinalEncription(L0, R0, keys,
true);
string selesai = FromBinaryToText(FinalText);
DecryptedTextBuilder.Append(selesai);
}
return DecryptedTextBuilder.ToString();
#endregion
}
#endregion
public static string BinaryStringToHexString(string binary)
{
StringBuilder result = new StringBuilder(binary.Length /
8 + 1);
int mod4Len = binary.Length % 8;
if (mod4Len != 0)
{
binary = binary.PadLeft(((binary.Length / 8) + 1) *
8, '0');
}
for (int i = 0; i < binary.Length; i += 8)
{
string eightBits = binary.Substring(i, 8);
result.AppendFormat("{0:X2}",
Convert.ToByte(eightBits, 2));
}
return result.ToString();
}
#region mengubah biner menjadi ascii
public string FromBinaryToText(string binarystring)
{
StringBuilder
text
=
StringBuilder(binarystring.Length / 8);
new
Universitas Sumatera Utara
71
for (int i = 0; i < (binarystring.Length / 8); i++)
{
string word = binarystring.Substring(i * 8, 8);
text.Append((char)Convert.ToInt32(word, 2));
}
return text.ToString();
}
#endregion
#region pembagian teks menjadi 64 bit
public string setTextMutipleOf64Bits(string text)
{
if ((text.Length % 64) != 0)
{
int maxLength = 0;
maxLength = ((text.Length / 64) + 1) * 64;
text = text.PadRight(maxLength, '0');
}
return text;
}
#endregion
#region mengubah ASCII menjadi biner
public string FromTextToBinary(string text)
{
StringBuilder
binarystring
StringBuilder(text.Length * 8);
=
new
foreach (char word in text)
{
int binary = (int)word;
int factor = 128;
for (int i = 0; i < 8; i++)
{
if (binary >= factor)
{
binary -= factor;
binarystring.Append("1");
}
else
{
binarystring.Append("0");
}
factor /= 2;
}
}
return binarystring.ToString();
}
public static string FromDeciamlToBinary(int binary)
{
if (binary < 0)
{
Console.WriteLine("It requires a integer greater than
0.");
return null;
Universitas Sumatera Utara
72
}
string binarystring = "";
int factor = 128;
for (int i = 0; i < 8; i++)
{
if (binary >= factor)
{
binary -= factor;
binarystring += "1";
}
else
{
binarystring += "0";
}
factor /= 2;
}
return binarystring;
}
public static byte FromBinaryToByte(string binary)
{
byte value = 0;
int factor = 128;
for (int i = 0; i < 8; i++)
{
if (binary[i] == '1')
{
value += (byte)factor;
}
factor /= 2;
}
return value;
}
#endregion
#region mengubah heksa ke biner
public string FromHexToBinary(string hexstring)
{
string binarystring = "";
try
{
for (int i = 0; i < hexstring.Length; i++)
{
int
hex
Convert.ToInt32(hexstring[i].ToString(), 16);
=
int factor = 8;
for(int j=0; j= factor)
{
hex -= factor;
Universitas Sumatera Utara
73
binarystring += "1";
}
else
{
binarystring += "0";
}
factor /= 2;
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message + " - wrong hexa integer
format.");
}
return binarystring;
}
#endregion
#region perulangan
public string DoPermutation(string text, int[] order)
{
StringBuilder
PermutatedText
=
StringBuilder(order.Length);
new
for (int i = 0; i < order.Length; i++)
{
PermutatedText.Append(text[order[i] - 1]);
}
return PermutatedText.ToString();
}
//untuk S box
public string DoPermutation(string text, int[,] order)
{
string PermutatedText = "";
int
rowIndex
=
Convert.ToInt32(text[0].ToString()
+
text[text.Length - 1].ToString(), 2);
int colIndex = Convert.ToInt32(text.Substring(1, 4), 2);
PermutatedText
ProcessDES.FromDeciamlToBinary(order[rowIndex, colIndex]);
=
return PermutatedText;
}
#endregion
#region memecah blok menjadi kiri dan kanan
public string SetLeftHalvesKey(string text)
{
return this.SetHalvesKey(true, text);
}
public string SetRightHalvesKey(string text)
{
return this.SetHalvesKey(false, text);
}
Universitas Sumatera Utara
74
public string SetHalvesKey(bool IsLeft, string text)
{
if ((text.Length % 8) != 0)
{
Console.WriteLine("The
key
is
not
multiple
of
8bit.");
return null;
}
int midindex = (text.Length / 2) - 1;
string result = "";
if (IsLeft)
{
result = text.Substring(0, midindex + 1);
}
else
{
result = text.Substring(midindex + 1);
}
return result;
}
#endregion
#region pergeseran ke kiri
public string LeftShift(string text)
{
return this.LeftShift(text, 1);
}
public string LeftShift(string text, int count)
{
if (count < 1)
{
Console.WriteLine("The count of leftshift
more than 1 time.");
return null;
}
is
must
string temp = text.Substring(0, count);
StringBuilder shifted = new StringBuilder(text.Length);
shifted.Append(text.Substring(count) + temp);
return shifted.ToString();
}
#endregion
#region pengmabilan semua kunci
public Keys SetAllKeys(string C0, string D0)
{
Keys keys = new Keys();
keys.Cn[0] = C0;
keys.Dn[0] = D0;
for (int i = 1; i < keys.Cn.Length; i++)
{
Universitas Sumatera Utara
75
keys.Cn[i]
=
DESData.nrOfShifts[i]);
keys.Dn[i]
=
DESData.nrOfShifts[i]);
keys.Kn[i - 1]
keys.Dn[i], DESData.pc_2);
}
this.LeftShift(keys.Cn[i
-
1],
this.LeftShift(keys.Dn[i
-
1],
=
this.DoPermutation(keys.Cn[i]
+
return keys;
}
#endregion
#region enkripsi
public string FinalEncription(string L0, string
keys, bool IsReverse)
{
string Ln = "", Rn = "", Ln_1 = L0, Rn_1 = R0;
R0,
Keys
int i = 0;
if (IsReverse == true)
{
i = 15;
}
while (this.IsEnough(i, IsReverse))
{
Ln = Rn_1;
Rn = this.XOR(Ln_1, this.f(Rn_1, keys.Kn[i]));
Ln_1 = Ln;
Rn_1 = Rn;
if (IsReverse == false)
{
i += 1;
}
else
{
i -= 1;
}
}
string R16L16 = Rn + Ln;
string
DESData.ip_1);
Encripted_Text
=
this.DoPermutation(R16L16,
return Encripted_Text;
}
public bool IsEnough(int i, bool IsReverse)
{
return (IsReverse == false) ? i < 16 : i >= 0;
}
#endregion
#region fungsi f
public string f(string Rn_1, string Kn)
{
Universitas Sumatera Utara
76
string E_Rn_1 = this.E_Selection(Rn_1);
string XOR_Rn_1_Kn = this.XOR(E_Rn_1, Kn);
string sBoxedText = this.sBox_Transform(XOR_Rn_1_Kn);
string P_sBoxedText = this.P(sBoxedText);
return P_sBoxedText;
}
#endregion
#region fungsi P
public string P(string text)
{
string PermutatedText = "";
PermutatedText = this.DoPermutation(text, DESData.pc_p);
return PermutatedText;
}
#endregion
#region transformasi s box
public string sBox_Transform(string text)
{
StringBuilder TransformedText = new StringBuilder(32);
for (int i = 0; i < 8; i++)
{
string temp = text.Substring(i * 6, 6);
TransformedText.Append(this.DoPermutation(temp,
DESData.sBoxes[i]));
}
return TransformedText.ToString();
}
#endregion
#region pemilihan E
public string E_Selection(string Rn_1)
{
string
ExpandedText
=
this.DoPermutation(Rn_1,
DESData.pc_e);
return ExpandedText;
}
#endregion
#region XOR
public string XOR(string text1, string text2)
{
if (text1.Length != text2.Length)
{
Console.WriteLine("Two data blocks for XOR are must
get same size.");
return null;
}
Universitas Sumatera Utara
77
StringBuilder
StringBuilder(text1.Length);
XORed_Text
=
new
for (int i = 0; i < text1.Length; i++)
{
if (text1[i] != text2[i])
{
XORed_Text.Append("1");
}
else
{
XORed_Text.Append("0");
}
}
return XORed_Text.ToString();
}
#endregion
}
}
Universitas Sumatera Utara
78
DAFTAR RIWAYAT HIDUP
DATA PRIBADI
Nama Lengkap
: Farid Akbar Siregar
Jenis Kelamin
: Laki-laki
Tempat, Tanggal Lahir
: Medan, 4 April 1994
Alamat
: Jl. Kapodang II No.361 P.Mandala, Medan
Agama
: Islam
E-mail
: farid_akbar_usu@yahoo.com
Pendidikan Terakhir
: Universitas Sumatera Utara Medan, Fakultas Ilmu
Komputer dan Teknologi Informasi Jurusan S1 Ilmu
Komputer
PENDIDIKAN FORMAL
2011 – 2016
: S1 Ilmu Komputer Universitas Sumatera Utara, Medan
2008 – 2011
: SMK Telkom Sandhy Putra Medan
2005 – 2008
: MTsN 2 Medan
1999 – 2005
: MIN Sei Agul Medan
PENGALAMAN ORGANISASI DAN KEGIATAN ILMIAH
Anggota Departemen Wawasan Kontemporer Ikatan Mahasiswa S1 Ilmu Komputer
(IMILKOM), 2012-2013
Ketua Komisi Pengawas KPU IMILKOM, 2013
Ketua Departemen Wawasan Kontemporer Ikatan Mahasiswa S1 Ilmu Komputer
(IMILKOM), 2013-2014
Ketua Departemen Kemahasiswaan Ikatan Mahasiswa S1 Ilmu Komputer
(IMILKOM), 2013-2014
Praktek Kerja Lapangan Biro Administrasi Pembangunan SETDAPROVSU JuliAgustus 2014
Universitas Sumatera Utara
LISTING PROGRAM
Form Utama :
using
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Net;
System.Windows;
System.Windows.Controls;
System.Windows.Navigation;
Microsoft.Phone.Controls;
Microsoft.Phone.Shell;
vigenere_des.Resources;
namespace vigenere_des
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Application.Current.Terminate();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new
Uri("/Page1.xaml",
UriKind.RelativeOrAbsolute));
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new
Uri("/Page2.xaml",
UriKind.RelativeOrAbsolute));
}
private void Button_Click_3(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new
Uri("/Page3.xaml",
UriKind.RelativeOrAbsolute));
}
private void Button_Click_4(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new
Uri("/Page4.xaml",
UriKind.RelativeOrAbsolute));
}
}
}
Universitas Sumatera Utara
60
Form Buat Pesan :
using
using
using
using
using
using
using
using
using
using
using
using
using
using
System;
System.IO;
System.Collections.Generic;
System.Linq;
System.Net;
System.Windows;
System.Windows.Controls;
System.Windows.Navigation;
Microsoft.Phone.Controls;
Microsoft.Phone.Shell;
Microsoft.Phone.UserData;
System.Security.Cryptography;
System.Text;
Microsoft.Phone.Tasks;
namespace vigenere_des
{
public partial class Page3 : PhoneApplicationPage
{
public Page3()
{
InitializeComponent();
}
string enkripsiv(string pesan, string kunci)
{
int pjgkunci = kunci.Length;
int pjgpesan = pesan.Length;
string hasil = "";
for (int i = 0; i < pjgpesan; i++)
{
hasil = hasil + Convert.ToChar((((int)pesan[i]
(int)kunci[i % (pjgkunci)]) % 95) + 32);
}
+
return hasil;
}
private void Button2_Click(object sender, RoutedEventArgs e)
{
string message = plaint.Text;
string key = plaink.Text;
ciphert.Text = enkripsiv(message, key);
}
private void Button3_Click(object sender, RoutedEventArgs e)
{
Cryptographer
cryptographer
=
new
Cryptographer(Algorithms.DES);
cipherk.Text = cryptographer.EncryptionStart(plaink.Text,
desk.Text.ToUpper(), false);
}
Universitas Sumatera Utara
61
private void Button4_Click(object sender, RoutedEventArgs e)
{
SmsComposeTask smsComposeTask = new SmsComposeTask();
smsComposeTask.To = buku_telepon.Text;
smsComposeTask.Body = ciphert.Text;
smsComposeTask.Show();
}
string data;
private void txtName_GotFocus(object sender, RoutedEventArgs
e)
{
TextBox t = sender as TextBox;
data = t.Text;
t.Text = string.Empty;
}
private void txtName_LostFocus(object sender, RoutedEventArgs
e)
{
TextBox t = sender as TextBox;
if (t.Text.Equals(string.Empty))
{
t.Text = data;
}
}
private void Button1_Click(object sender, RoutedEventArgs e)
{
Contacts cons = new Contacts();
cons.SearchCompleted
+=
new
EventHandler(Contacts_SearchCompleted);
cons.SearchAsync(String.Empty, FilterKind.None, "Contacts
Test #1");
}
void
Contacts_SearchCompleted(object
ContactsSearchEventArgs e)
{
System.Text.StringBuilder
sb
System.Text.StringBuilder();
sender,
=
new
foreach (Contact con in e.Results)
{
sb.AppendLine(con.DisplayName);
}
MessageBox.Show(sb.ToString());
}
}
}
Universitas Sumatera Utara
62
Form Dekrip Pesan :
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Net;
System.Windows;
System.Windows.Controls;
System.Windows.Navigation;
Microsoft.Phone.Controls;
Microsoft.Phone.Shell;
namespace vigenere_des
{
public partial class Page4 : PhoneApplicationPage
{
public Page4()
{
InitializeComponent();
}
string dekripsiv(string pesan, string kunci)
{
int pjgkunci = kunci.Length;
int pjgpesan = pesan.Length;
string hasil = "";
for (int i = 0; i < pjgpesan; i++)
{
if ((((int)pesan[i] - 32) - (int)kunci[i % (pjgkunci
- 1)]) < -63)
{
hasil = hasil + Convert.ToChar((((int)pesan[i] 32) - (int)kunci[i % (pjgkunci)]) + 190);
}
else if ((((int)pesan[i] - 32) - (int)kunci[i %
(pjgkunci - 1)]) < 32)
{
hasil = hasil + Convert.ToChar((((int)pesan[i] 32) - (int)kunci[i % (pjgkunci)]) + 95);
}
else
{
hasil = hasil + Convert.ToChar((((int)pesan[i] 32) - (int)kunci[i % (pjgkunci)]) % 95);
}
}
return hasil;
}
private void Button3_Click(object sender, RoutedEventArgs e)
{
string message = ciphert1.Text;
string key = plaink1.Text;
plaint1.Text = dekripsiv(message, key);
}
private void Button2_Click(object sender, RoutedEventArgs e)
Universitas Sumatera Utara
63
{
Cryptographer
cryptographer
Cryptographer(Algorithms.DES);
plaink1.Text
cryptographer.DecryptionStart(cipherk1.Text,
false);
}
private
void
TextChangedEventArgs e)
{
=
new
=
desk.Text.ToUpper(),
plaint_TextChanged(object
sender,
}
string data;
private void txtName_GotFocus(object sender, RoutedEventArgs
e)
{
TextBox t = sender as TextBox;
data = t.Text;
t.Text = string.Empty;
}
private void txtName_LostFocus(object sender, RoutedEventArgs
e)
{
TextBox t = sender as TextBox;
if (t.Text.Equals(string.Empty))
{
t.Text = data;
}
}
}
}
Class Algorithms.cs :
using System;
using System.Collections.Generic;
using System.Text;
namespace vigenere_des
{
class Algorithms
{
public static readonly int DES = 0;
}
}
Universitas Sumatera Utara
64
Class Cryptographer.cs :
using
using
using
using
System;
System.Collections.Generic;
System.Text;
System.Threading;
namespace vigenere_des
{
class Cryptographer
{
CommonProcess cProcess = null;
public Cryptographer(int algorithm_number)
{
if (Algorithms.DES == algorithm_number)
{
cProcess = new DES.ProcessDES();
}
}
public string EncryptionStart(string text, string key, bool
IsBinary)
{
return cProcess.EncryptionStart(text, key, IsBinary);
}
public string DecryptionStart(string text, string key, bool
IsBinary)
{
return cProcess.DecryptionStart(text, key, IsBinary);
}
}
}
Class Commonprocess.cs :
using System;
using System.Collections.Generic;
using System.Text;
namespace vigenere_des
{
abstract class CommonProcess
{
public abstract string EncryptionStart(string
key, bool IsTextBinary);
public abstract string
key, bool IsTextBinary);
}
}
DecryptionStart(string
text,
string
text,
string
Universitas Sumatera Utara
65
Class DESData.cs :
using System;
using System.Collections.Generic;
using System.Text;
namespace vigenere_des.DES
{
#region tabel permutasi
class DESData
{
public static readonly int[] pc_1 ={
9, 1, 58, 50,
42,
51, 43, 35,
27,
36, 63, 55,
47,
54, 46, 38,
30,
37, 29, 21,
13,
57, 49, 41, 33, 25, 17,
34, 26, 18, 10, 2, 59,
19, 11, 3, 60, 52, 44,
39, 31, 23, 15, 7, 62,
22, 14, 6, 61, 53, 45,
5, 28, 20, 12, 4 };
public static readonly int[] 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
};
public static readonly int[] 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 };
public static readonly int[] ip_1 ={ 40, 8, 48, 16,
64, 32, 39, 7,
47, 15, 55, 23,
38, 6, 46, 14,
54, 22, 62, 30,
45, 13, 53, 21,
61, 29, 36, 4,
52, 20, 60, 28,
35, 3, 43, 11,
59, 27, 34, 2,
56, 24,
63, 31,
37,
5,
44,
12,
51,
19,
Universitas Sumatera Utara
66
42, 10, 50, 18, 58, 26,
33, 1, 41, 9,
49, 17, 57, 25 };
public static readonly int[] pc_e ={ 32, 1, 2, 3,
6, 7, 8, 9, 8,
9, 10, 11, 12,
14, 15, 16,
17, 16, 17, 18,
20, 21, 22,
23, 24, 25, 24,
28, 29, 28,
29, 30, 31, 32,
4, 5, 4, 5,
13, 12, 13,
19, 20, 21,
25, 26, 27,
1 };
public static readonly int[] pc_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 };
public static readonly int[] nrOfShifts ={ 0, 1, 1, 2, 2, 2,
2, 2, 2, 1,
2, 2, 2, 2, 2, 2, 1
};
public static List sBoxes = new List();
static DESData()
{
sBoxes.Add(s1);
sBoxes.Add(s2);
sBoxes.Add(s3);
sBoxes.Add(s4);
sBoxes.Add(s5);
sBoxes.Add(s6);
sBoxes.Add(s7);
sBoxes.Add(s8);
}
public static readonly int[,] 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 } };
public static readonly int[,] s2 ={ { 15,
4, 9, 7, 2, 13, 12, 0, 5, 10 },
{ 3, 13,
12, 0, 1, 10, 6, 9, 11, 5 },
{ 0, 14,
1, 5, 8, 12, 6, 9, 3, 2, 15 },
{ 13, 8,
11, 6, 7, 12, 0, 5, 14, 9 } };
1, 8, 14, 6, 11, 3,
4, 7, 15, 2, 8, 14,
7, 11, 10, 4, 13,
10, 1, 3, 15, 4, 2,
Universitas Sumatera Utara
67
public static readonly int[,] s3 ={ { 10,
5, 1, 13, 12, 7, 11, 4, 2, 8 },
{ 13, 7,
2, 8, 5, 14, 12, 11, 15, 1 },
{ 13, 6,
11, 1, 2, 12, 5, 10, 14, 7 },
{ 1, 10,
4, 15, 14, 3, 11, 5, 2, 12 } };
0, 9, 14, 6, 3, 15,
0, 9, 3, 4, 6, 10,
4, 9, 8, 15, 3, 0,
13, 0, 6, 9, 8, 7,
public static readonly int[,] s4 ={ { 7, 13, 14, 3, 0, 6,
10, 1, 2, 8, 5, 11, 12, 4, 15 },
{ 13, 8, 11, 5, 6, 15, 0,
4, 7, 2, 12, 1, 10, 14, 9 },
{ 10, 6, 9, 0, 12, 11,
13, 15, 1, 3, 14, 5, 2, 8, 4 },
{ 3, 15, 0, 6, 10, 1, 13,
9, 4, 5, 11, 12, 7, 2, 14 } };
9,
3,
7,
8,
public static readonly int[,] 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, 6 },
{ 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 } };
public static readonly int[,] 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 } };
public static readonly int[,] 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 } };
public static readonly int[,] s8 ={ {
1, 10, 9, 3, 14, 5, 0, 12, 7 },
{ 1,
12, 5, 6, 11, 0, 14, 9, 2 },
{ 7,
0, 6, 10, 13, 15, 3, 5, 8 },
{ 2,
15, 12, 9, 0, 3, 5, 6, 11 } };
}
#endregion
13, 2, 8, 4, 6, 15, 11,
15, 13, 8, 10, 3, 7, 4,
11, 4, 1, 9, 12, 14, 2,
1, 14, 7, 4, 10, 8, 13,
Universitas Sumatera Utara
68
#region pembuatan kelas kunci
class Keys
{
public string[] Cn = new string[17];
public string[] Dn = new string[17];
public string[] Kn = new string[16];
}
#endregion
}
Class ProcessDES.cs :
using System;
using System.Collections.Generic;
using System.Text;
namespace vigenere_des.DES
{
class ProcessDES : CommonProcess
{
public ProcessDES()
{
}
#region proses enkripsi
public override string EncryptionStart(string
key, bool IsTextBinary)
{
#region pengambilan 16 kunci
text,
string
string binary_key = this.FromTextToBinary(key);
string
key_plus
=
this.DoPermutation(binary_key,
DESData.pc_1);
string C0 = "", D0 = "";
C0 = this.SetLeftHalvesKey(key_plus);
D0 = this.SetRightHalvesKey(key_plus);
Keys keys = this.SetAllKeys(C0, D0);
#endregion
#region proses enkripsi
string binaryText = "";
if (IsTextBinary == false)
{
binaryText = this.FromTextToBinary(text);
}
else
{
binaryText = text;
}
Universitas Sumatera Utara
69
binaryText = this.setTextMutipleOf64Bits(binaryText);
StringBuilder
EncryptedTextBuilder
StringBuilder(binaryText.Length);
=
new
for (int i = 0; i < (binaryText.Length / 64); i++)
{
string
PermutatedText
this.DoPermutation(binaryText.Substring(i * 64, 64), DESData.ip);
=
string L0 = "", R0 = "";
L0 = this.SetLeftHalvesKey(PermutatedText);
R0 = this.SetRightHalvesKey(PermutatedText);
string FinalText = this.FinalEncription(L0, R0, keys,
false);
string selesai = BinaryStringToHexString(FinalText);
EncryptedTextBuilder.Append(selesai);
}
return EncryptedTextBuilder.ToString();
#endregion
}
#endregion
#region proses dekripsi
public override string DecryptionStart(string
key, bool IsTextBinary)
{
#region pengambilan 16 kunci
text,
string
string binary_key = this.FromTextToBinary(key);
string
key_plus
=
this.DoPermutation(binary_key,
DESData.pc_1);
string C0 = "", D0 = "";
C0 = this.SetLeftHalvesKey(key_plus);
D0 = this.SetRightHalvesKey(key_plus);
Keys keys = this.SetAllKeys(C0, D0);
#endregion
#region proses dekripsi
string binaryText = "";
if (IsTextBinary == false)
{
binaryText = this.FromHexToBinary(text);
}
else
{
Universitas Sumatera Utara
70
binaryText = text;
}
binaryText = this.setTextMutipleOf64Bits(binaryText);
StringBuilder
DecryptedTextBuilder
StringBuilder(binaryText.Length);
=
for (int i = 0; i < (binaryText.Length / 64); i++)
{
string
PermutatedText
this.DoPermutation(binaryText.Substring(i * 64, 64), DESData.ip);
new
=
string L0 = "", R0 = "";
L0 = this.SetLeftHalvesKey(PermutatedText);
R0 = this.SetRightHalvesKey(PermutatedText);
string FinalText = this.FinalEncription(L0, R0, keys,
true);
string selesai = FromBinaryToText(FinalText);
DecryptedTextBuilder.Append(selesai);
}
return DecryptedTextBuilder.ToString();
#endregion
}
#endregion
public static string BinaryStringToHexString(string binary)
{
StringBuilder result = new StringBuilder(binary.Length /
8 + 1);
int mod4Len = binary.Length % 8;
if (mod4Len != 0)
{
binary = binary.PadLeft(((binary.Length / 8) + 1) *
8, '0');
}
for (int i = 0; i < binary.Length; i += 8)
{
string eightBits = binary.Substring(i, 8);
result.AppendFormat("{0:X2}",
Convert.ToByte(eightBits, 2));
}
return result.ToString();
}
#region mengubah biner menjadi ascii
public string FromBinaryToText(string binarystring)
{
StringBuilder
text
=
StringBuilder(binarystring.Length / 8);
new
Universitas Sumatera Utara
71
for (int i = 0; i < (binarystring.Length / 8); i++)
{
string word = binarystring.Substring(i * 8, 8);
text.Append((char)Convert.ToInt32(word, 2));
}
return text.ToString();
}
#endregion
#region pembagian teks menjadi 64 bit
public string setTextMutipleOf64Bits(string text)
{
if ((text.Length % 64) != 0)
{
int maxLength = 0;
maxLength = ((text.Length / 64) + 1) * 64;
text = text.PadRight(maxLength, '0');
}
return text;
}
#endregion
#region mengubah ASCII menjadi biner
public string FromTextToBinary(string text)
{
StringBuilder
binarystring
StringBuilder(text.Length * 8);
=
new
foreach (char word in text)
{
int binary = (int)word;
int factor = 128;
for (int i = 0; i < 8; i++)
{
if (binary >= factor)
{
binary -= factor;
binarystring.Append("1");
}
else
{
binarystring.Append("0");
}
factor /= 2;
}
}
return binarystring.ToString();
}
public static string FromDeciamlToBinary(int binary)
{
if (binary < 0)
{
Console.WriteLine("It requires a integer greater than
0.");
return null;
Universitas Sumatera Utara
72
}
string binarystring = "";
int factor = 128;
for (int i = 0; i < 8; i++)
{
if (binary >= factor)
{
binary -= factor;
binarystring += "1";
}
else
{
binarystring += "0";
}
factor /= 2;
}
return binarystring;
}
public static byte FromBinaryToByte(string binary)
{
byte value = 0;
int factor = 128;
for (int i = 0; i < 8; i++)
{
if (binary[i] == '1')
{
value += (byte)factor;
}
factor /= 2;
}
return value;
}
#endregion
#region mengubah heksa ke biner
public string FromHexToBinary(string hexstring)
{
string binarystring = "";
try
{
for (int i = 0; i < hexstring.Length; i++)
{
int
hex
Convert.ToInt32(hexstring[i].ToString(), 16);
=
int factor = 8;
for(int j=0; j= factor)
{
hex -= factor;
Universitas Sumatera Utara
73
binarystring += "1";
}
else
{
binarystring += "0";
}
factor /= 2;
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message + " - wrong hexa integer
format.");
}
return binarystring;
}
#endregion
#region perulangan
public string DoPermutation(string text, int[] order)
{
StringBuilder
PermutatedText
=
StringBuilder(order.Length);
new
for (int i = 0; i < order.Length; i++)
{
PermutatedText.Append(text[order[i] - 1]);
}
return PermutatedText.ToString();
}
//untuk S box
public string DoPermutation(string text, int[,] order)
{
string PermutatedText = "";
int
rowIndex
=
Convert.ToInt32(text[0].ToString()
+
text[text.Length - 1].ToString(), 2);
int colIndex = Convert.ToInt32(text.Substring(1, 4), 2);
PermutatedText
ProcessDES.FromDeciamlToBinary(order[rowIndex, colIndex]);
=
return PermutatedText;
}
#endregion
#region memecah blok menjadi kiri dan kanan
public string SetLeftHalvesKey(string text)
{
return this.SetHalvesKey(true, text);
}
public string SetRightHalvesKey(string text)
{
return this.SetHalvesKey(false, text);
}
Universitas Sumatera Utara
74
public string SetHalvesKey(bool IsLeft, string text)
{
if ((text.Length % 8) != 0)
{
Console.WriteLine("The
key
is
not
multiple
of
8bit.");
return null;
}
int midindex = (text.Length / 2) - 1;
string result = "";
if (IsLeft)
{
result = text.Substring(0, midindex + 1);
}
else
{
result = text.Substring(midindex + 1);
}
return result;
}
#endregion
#region pergeseran ke kiri
public string LeftShift(string text)
{
return this.LeftShift(text, 1);
}
public string LeftShift(string text, int count)
{
if (count < 1)
{
Console.WriteLine("The count of leftshift
more than 1 time.");
return null;
}
is
must
string temp = text.Substring(0, count);
StringBuilder shifted = new StringBuilder(text.Length);
shifted.Append(text.Substring(count) + temp);
return shifted.ToString();
}
#endregion
#region pengmabilan semua kunci
public Keys SetAllKeys(string C0, string D0)
{
Keys keys = new Keys();
keys.Cn[0] = C0;
keys.Dn[0] = D0;
for (int i = 1; i < keys.Cn.Length; i++)
{
Universitas Sumatera Utara
75
keys.Cn[i]
=
DESData.nrOfShifts[i]);
keys.Dn[i]
=
DESData.nrOfShifts[i]);
keys.Kn[i - 1]
keys.Dn[i], DESData.pc_2);
}
this.LeftShift(keys.Cn[i
-
1],
this.LeftShift(keys.Dn[i
-
1],
=
this.DoPermutation(keys.Cn[i]
+
return keys;
}
#endregion
#region enkripsi
public string FinalEncription(string L0, string
keys, bool IsReverse)
{
string Ln = "", Rn = "", Ln_1 = L0, Rn_1 = R0;
R0,
Keys
int i = 0;
if (IsReverse == true)
{
i = 15;
}
while (this.IsEnough(i, IsReverse))
{
Ln = Rn_1;
Rn = this.XOR(Ln_1, this.f(Rn_1, keys.Kn[i]));
Ln_1 = Ln;
Rn_1 = Rn;
if (IsReverse == false)
{
i += 1;
}
else
{
i -= 1;
}
}
string R16L16 = Rn + Ln;
string
DESData.ip_1);
Encripted_Text
=
this.DoPermutation(R16L16,
return Encripted_Text;
}
public bool IsEnough(int i, bool IsReverse)
{
return (IsReverse == false) ? i < 16 : i >= 0;
}
#endregion
#region fungsi f
public string f(string Rn_1, string Kn)
{
Universitas Sumatera Utara
76
string E_Rn_1 = this.E_Selection(Rn_1);
string XOR_Rn_1_Kn = this.XOR(E_Rn_1, Kn);
string sBoxedText = this.sBox_Transform(XOR_Rn_1_Kn);
string P_sBoxedText = this.P(sBoxedText);
return P_sBoxedText;
}
#endregion
#region fungsi P
public string P(string text)
{
string PermutatedText = "";
PermutatedText = this.DoPermutation(text, DESData.pc_p);
return PermutatedText;
}
#endregion
#region transformasi s box
public string sBox_Transform(string text)
{
StringBuilder TransformedText = new StringBuilder(32);
for (int i = 0; i < 8; i++)
{
string temp = text.Substring(i * 6, 6);
TransformedText.Append(this.DoPermutation(temp,
DESData.sBoxes[i]));
}
return TransformedText.ToString();
}
#endregion
#region pemilihan E
public string E_Selection(string Rn_1)
{
string
ExpandedText
=
this.DoPermutation(Rn_1,
DESData.pc_e);
return ExpandedText;
}
#endregion
#region XOR
public string XOR(string text1, string text2)
{
if (text1.Length != text2.Length)
{
Console.WriteLine("Two data blocks for XOR are must
get same size.");
return null;
}
Universitas Sumatera Utara
77
StringBuilder
StringBuilder(text1.Length);
XORed_Text
=
new
for (int i = 0; i < text1.Length; i++)
{
if (text1[i] != text2[i])
{
XORed_Text.Append("1");
}
else
{
XORed_Text.Append("0");
}
}
return XORed_Text.ToString();
}
#endregion
}
}
Universitas Sumatera Utara
78
DAFTAR RIWAYAT HIDUP
DATA PRIBADI
Nama Lengkap
: Farid Akbar Siregar
Jenis Kelamin
: Laki-laki
Tempat, Tanggal Lahir
: Medan, 4 April 1994
Alamat
: Jl. Kapodang II No.361 P.Mandala, Medan
Agama
: Islam
: farid_akbar_usu@yahoo.com
Pendidikan Terakhir
: Universitas Sumatera Utara Medan, Fakultas Ilmu
Komputer dan Teknologi Informasi Jurusan S1 Ilmu
Komputer
PENDIDIKAN FORMAL
2011 – 2016
: S1 Ilmu Komputer Universitas Sumatera Utara, Medan
2008 – 2011
: SMK Telkom Sandhy Putra Medan
2005 – 2008
: MTsN 2 Medan
1999 – 2005
: MIN Sei Agul Medan
PENGALAMAN ORGANISASI DAN KEGIATAN ILMIAH
Anggota Departemen Wawasan Kontemporer Ikatan Mahasiswa S1 Ilmu Komputer
(IMILKOM), 2012-2013
Ketua Komisi Pengawas KPU IMILKOM, 2013
Ketua Departemen Wawasan Kontemporer Ikatan Mahasiswa S1 Ilmu Komputer
(IMILKOM), 2013-2014
Ketua Departemen Kemahasiswaan Ikatan Mahasiswa S1 Ilmu Komputer
(IMILKOM), 2013-2014
Praktek Kerja Lapangan Biro Administrasi Pembangunan SETDAPROVSU JuliAgustus 2014
Universitas Sumatera Utara