Hybrid Cryptography Application Code
Hybrid Cryptography Application Code
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link]
{
public partial class mainForm : Form
{
2. Form Enkripsi
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link]
{
public partial class encryptForm : Form
{
long jum;
int nckey;
int n = 0;
long[] nil_w = new long[1000];
int[,] tempval = new int[4, 4];
int a;
int[,] kunci = new int[4, 4];
private String fileExt;
DoubleMatrix k = null;
/// <summary>
/// Set default
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void encryptForm_Load(object sender, EventArgs e)
{
[Link] = 0;
}
/// <summary>
/// Cari file yang akan di enkripsi
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnPilihSumberFile_Click(object sender, EventArgs e)
{
OpenFileDialog FileDialog = new OpenFileDialog();
if ([Link]() == [Link])
{
[Link] = [Link]();
fileExt =
[Link]([Link]).Substring(1);
[Link] = fileExt;
}
}
/// <summary>
/// Generate matrix kunci
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnGenerateKunci_Click(object sender, EventArgs e)
{
[Link]();
if ([Link] == "2x2")
{
a = 2;
for (int i = 2; i < ((32 / 2) + 1); i++)
{
if (32 % i == 0)
{
[Link]([Link]());
}
}
}
else if ([Link] == "3x3")
else if (a == 3)
{
}
else if (selectedIndexKeyMatrix == 3) // 4x4
{
k = new DoubleMatrix(4, 4);
// baris 0
k[0, 0] = kunci[0, 0];
k[1, 0] = kunci[0, 1];
k[2, 0] = kunci[0, 2];
k[3, 0] = kunci[0, 3];
// baris 1
k[0, 1] = kunci[1, 0];
k[1, 1] = kunci[1, 1];
k[2, 1] = kunci[1, 2];
k[3, 1] = kunci[1, 3];
// baris 2
k[0, 2] = kunci[2, 0];
k[1, 2] = kunci[2, 1];
k[2, 2] = kunci[2, 2];
k[3, 2] = kunci[2, 3];
// baris 3
k[0, 3] = kunci[3, 0];
k[1, 3] = kunci[3, 1];
k[2, 3] = kunci[3, 2];
k[3, 3] = kunci[3, 3];
}
[Link](k);
}
/// <summary>
/// Ambil tujuan file enkripsi
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnPilihTujuanFile_Click(object sender, EventArgs e)
{
SaveFileDialog saveDialog = new SaveFileDialog();
[Link] = fileExt;
[Link] = true;
[Link] = fileExt + " (*." + fileExt + ")|" +
fileExt;
if ([Link]() == [Link])
{
/// <summary>
/// Lakukan enkripsi cipher hill
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnEnkripsi_Click(object sender, EventArgs e)
{
//lama enkripsi
[Link] = [Link] + " ms
".ToString();
//ukuran file
FileBitReader fileAsli = new FileBitReader([Link]);
[Link] = [Link]() + " byte ".ToString();
[Link]();
//ukuran cipherfile
FileBitReader fileTerenkrip = new
FileBitReader([Link]);
[Link] = [Link]() +" byte
".ToString();
/// <summary>
/// Pilih jumlah w
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cbJumlahW_SelectedIndexChanged(object sender,
EventArgs e)
{
//int bitnil = 0;
if ([Link] == "2x2")
{
// bitnil = 32;
}
else if ([Link] == "3x3")
{
// bitnil = 72;
}
else if ([Link] == "4x4")
{
// bitnil = 128;
}
//else
}
// bitnil = 32;
// }
/// <summary>
/// Bangkitkan w,q,r
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnGenerate_Click(object sender, EventArgs e)
{
if ([Link] == "")
{
[Link]("piih terlebih dahulu banyak item w");
}
else
{
Random rand = new Random();
long temp = 0;
n = Convert.ToInt32([Link]);
nil_w[0] = 1;
jum = nil_w[0];
[Link] = nil_w[0].ToString();
for (int i = 1; i < n; i++)
{
for (int j = 0; j < i; j++)
{
temp += nil_w[j];
}
nil_w[i] = temp + 1;
jum += nil_w[i];
[Link] += " " + nil_w[i].ToString();
temp = 0;
}
{
long r = Convert.ToInt32([Link]), q =
Convert.ToInt64([Link]);
n = Convert.ToInt32([Link]);
long[] nilpublic = new long[n];
[Link] = "";
for (int i = 0; i < n; i++)
{
nilpublic[i] = ((nil_w[i] * r) % q);
[Link] += nilpublic[i].ToString() + "
";
}
}
{
[Link] = [Link];
}
}
// dr sini
}
/// <summary>
/// Pilih tujuan key disimpan
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnPilihTujuanKey_Click(object sender, EventArgs e)
{
SaveFileDialog saveDialog = new SaveFileDialog();
[Link] = "cipherkey";
[Link] = true;
[Link] = "cipherkey (*.cipherkey)|cipherkey";
if ([Link]() == [Link])
{
[Link] = [Link]();
}
}
/// <summary>
/// Lakukan enkripsi pada key (Knapsack)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_EnkripsiKunci_Click(object sender, EventArgs e)
/// <summary>
/// Keluar dari form enkripsi
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnBatal_Click(object sender, EventArgs e)
{
Close();
}
3. Form Dekripsi
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link]
{
public partial class decryptForm : Form
{
// long jum;
//int n = 0;
long[] nil_w = new long[1000];
int[,] tempval = new int[4, 4];
//int a;
int[,] kunci = new int[4, 4];
private String fileExt;
// DoubleMatrix k = null;
#region VAR ############
// private Boolean bIsExit = false;
#endregion
#region KONSTRUKTOR ###################
public decryptForm()
{
InitializeComponent();
}
#endregion
/// <summary>
/// Pilih file cipher key dan baca w,q,r,cipherkey ke textbox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnPilihFileCipherKey_Click(object sender, EventArgs
e)
{
OpenFileDialog openKey = new OpenFileDialog();
[Link] = "cipherkey(*.cipherkey)|*.cipherkey";
if ([Link]() == [Link])
{
string read = "";
StreamReader objReader = new
StreamReader([Link]);
[Link] = [Link];
int count = 0;
while (read != null)
{
if (count == 0)
{
txt_Q.Text = read;
}
else if (count == 1)
{
txt_R.Text = read;
}
else if (count == 3)
{
txt_KunciPrivat.Text = read;
}
else if (count == 4)
{
[Link] = read;
}
count++;
read = [Link]();
}
[Link]();
}
}
/// <summary>
/// Lakukan dekripsi knapsack terhadap cipherkey, q, w, r
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_DekripsiCipherkey_Click(object sender, EventArgs
e)
{
try
{
Stopwatch stopwatch = new Stopwatch();
[Link]();
String result = [Link](txt_KunciPrivat.Text,
[Link], txt_Q.Text, txt_R.Text);
txt_CipherMatrix.Text = result;
[Link]();
[Link]("Dekripsi Key Berhasil! ");
[Link] = [Link] + " ms
".ToString();
}
catch (Exception TerjadiKesalahan)
{
[Link]("Error\n" + [Link]());
}
/// <summary>
/// Pilih sumber file yang sudah terenkripsi
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <summary>
/// Pilih dimana file hasil dekripsi disimpan (Cipherhill)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnPilihTujuanFile_Click(object sender, EventArgs e)
{
SaveFileDialog saveDialog = new SaveFileDialog();
[Link] = fileExt;
[Link] = true;
[Link] = fileExt + " (*." + fileExt + ")|"+fileExt;
if ([Link]() == [Link])
{
[Link] =
[Link]();
}
}
/// <summary>
/// Lakukan proses dekripsi dan simpan file hasil dekripsi
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Dekripsi_Click(object sender, EventArgs e)
{
Stopwatch stopwatch = new Stopwatch();
[Link]();
String key = txt_CipherMatrix.Text; // 45 34 54 23 45 23 45 23
//buang spasi terakhir
key = [Link](0, [Link] - 1); // posisi terakhir
adalah spasi
//lama dekripsi
[Link] = [Link] + " ms
".ToString();
}
//[Link](identifier);
[Link]();
[Link]();
}
else
{
[Link]("Key yang anda masukkan salah! Key harus
berupa 2x2; 3x3; 4x4");
}
}
#endregion
}
}
}
namespace [Link]
{
public partial class HelpForm : Form
{
public HelpForm()
{
InitializeComponent();
}
}
}
5. Form Tentang
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link]
{
public partial class programmerForm : Form
{
public programmerForm()
{
InitializeComponent();
}
}
}
}
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link]
{
class HillCipher
{
public static void encrypt(FileBitReader reader, FileBitWriter
writer, DoubleMatrix k)
{
// ambil jenis matrix
int jenisMatrix; // total baris = total kolom
jenisMatrix = [Link];
// ambil ukuran file
long fileSize = [Link]();
// variabel count jumlah byte yang sudah dibaca
long readedByte = 0;
// lakukan pembacaan sampai seluruh file terbaca
while (readedByte < fileSize) {
// ambil sebanyak jumlah matrix dan ciptakan matrix
DoubleMatrix matrixP = new DoubleMatrix(1, jenisMatrix);
int readedP = 0;
while (readedP < jenisMatrix)
{
if (readedByte < fileSize)
{
matrixP[0, readedP] = [Link]();
readedByte++;
}
else
{
matrixP[0, readedP] = 0;
}
readedP++;
if (x == 0) {
throw new Exception("Tidak bisa menemukan nilai invers Det
K");
}
// pembuktian
DoubleMatrix bukti = k * invK;
[Link](256);
for (int baris = 0; baris < [Link]; baris++)
{
for (int kol = 0; kol < [Link]; kol++)
{
if (baris == kol)
{
if (bukti[kol, baris] != 1) {
7. Class Knapsack
using System;
using [Link];
using [Link];
using [Link];
using [Link];
//int to Biner
temp = "";
for (int i = 0; i < jnsMatrix; i++)
{
for (int j = 0; j < jnsMatrix; j++)
{
temp += Knapsack.int2bin(kunci[i, j], 8);
}
}
//[Link]([Link]);
//Pisah Menjadi Blok Biner
indeks = 0;
kTempPub = "";
nckey = ([Link] / jlhW);
int counter = 0;
string[] sesiKeyCipher = new string[nckey];
//[Link]([Link]+" "+[Link]);
indeks = 0;
kTempPub = "";
int counter = 0;
string[] sesiKeyCipher = new string[100];
int[] KeyCipher = new int[100];
temp = "";
nInv = (1 + (q * k)) / r;
dataDec[i] = 0;
for (int j = 0; j < n_bit; j++)
{
dataDec[i] +=
(Convert.ToInt32(dataBit[i][j].ToString()) *
kPrivate[j]);
}
}
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link]
{
class FileBitReader
{
private String fileName;
private FileStream fileIn;
private BufferedStream buffFileIn;
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link]
{
class FileBitWriter
{
private String fileName;
private FileStream fileOut;
private BufferedStream buffFileOut;
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link]
{
public class DoubleMatrix
{
public double determinant() {
if ([Link] != [Link])
{
throw new Exception("Determinan berlaku pada matrix NxN");
}
if ([Link] == 1)
{
return this[0, 0];
}
if ([Link] != 2)
{
throw new NotImplementedException("Fungsi hanya bisa
melakukan determinant n=2");
}
int n = [Link];
if (n == 2) {
//(kunci[0, 0] * kunci[1, 1]) - (kunci[1, 0] * kunci[0,
1]);
return (this[0, 0] * this[1, 1]) - (this[0, 1] * this[1,
0]);
}
using System;
using [Link];
using [Link];
using [Link];
namespace [Link]
{
class GCD
{
public static long GCD1(long a, long b)
{
while (b != 0)
{
long tmp = b;
b = a % b;
a = tmp;
}
return a;
}
}
}
Keterangan :
No : Nilai byte
DETAIL PROFIL
Telp/Handphone : - / 082304593490
e-mail :hannasihombing90@[Link]/marlina_sihombing@[Link]
SEBAGAI SEMINAR