Дослідження та порівняльний аналіз алгоритмів кодування даних

Історія створення мови С#. Аналіз алгоритмів кодування даних. Розробка системи в середовищі Visual Studio 2008 Express. Схема шифрування алгоритму DES. Дослідження алгоритму RC2. Приклади хешів RIPEMD-160. Програмна реалізація основних процедур системи.

Рубрика Программирование, компьютеры и кибернетика
Вид дипломная работа
Язык украинский
Дата добавления 25.10.2012
Размер файла 1,7 M

Отправить свою хорошую работу в базу знаний просто. Используйте форму, расположенную ниже

Студенты, аспиранты, молодые ученые, использующие базу знаний в своей учебе и работе, будут вам очень благодарны.

keysize = rij.KeySize;

key = saveFileDialog1.FileName;

FileStream fkey = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.Write);

fkey.Write(rij.Key, 0, rij.Key.Length);

fkey.Close();

}

if (key != "" & IV != "")

{

panel1.Enabled = true;

}

}

private void button4_Click(object sender, EventArgs e)

{

saveFileDialog1.FileName = "";

saveFileDialog1.Filter = "RIJNDAEL IV file| *.rijIV";

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

RijndaelManaged rij = new RijndaelManaged();

rij.GenerateIV();

FileStream fiv = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.Write);

IV = saveFileDialog1.FileName;

fiv.Write(rij.IV, 0, rij.IV.Length);

fiv.Close();

}

if (key != "" & IV != "")

{

panel1.Enabled = true;

}

}

private void button5_Click(object sender, EventArgs e)

{

openFileDialog1.FileName = "";

openFileDialog1.Filter = "RIJNDAEL key file| *.rijkey";

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

key = openFileDialog1.FileName;

}

if (key != "" & IV != "")

{

panel1.Enabled = true;

}

}

private void button6_Click(object sender, EventArgs e)

{

openFileDialog1.FileName = "";

openFileDialog1.Filter = "RIJNDAEL IV file| *.rijIV";

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

IV = openFileDialog1.FileName;

}

if (key != "" & IV != "")

{

panel1.Enabled = true;

}

}

private void button2_Click(object sender, EventArgs e)

{

openFileDialog1.FileName = "";

openFileDialog1.Filter = "All file| *.*";

saveFileDialog1.FileName = "";

saveFileDialog1.Filter = "RIJNDAEL file| *.rij";

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

tim = DateTime.Now;

EncryptData(openFileDialog1.FileName, saveFileDialog1.FileName, key, IV);

label1.Text = (DateTime.Now - tim).ToString();

}

}

}

private void button3_Click(object sender, EventArgs e)

{

openFileDialog1.FileName = "";

openFileDialog1.Filter = "RIJNDAEL file| *.rij";

saveFileDialog1.FileName = "";

saveFileDialog1.Filter = "All file| *.*";

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

tim = DateTime.Now;

DecryptData(openFileDialog1.FileName, saveFileDialog1.FileName, key, IV);

label2.Text = (DateTime.Now - tim).ToString();

}

}

}

}

}

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Security.Cryptography;

using System.IO;

namespace diplom

{

public partial class RIPEMD160 : Form

{

public static int keysize;

public static long output;

private DateTime tim;

public RIPEMD160()

{

InitializeComponent();

}

public void Hash(string inName,string outName)

{

FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);

FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);

fout.SetLength(0);

byte[] hashValue;

RIPEMD160Managed rip = new RIPEMD160Managed();

hashValue = rip.ComputeHash(fin);

keysize = rip.HashSize;

fout.Write(hashValue,0,hashValue.Length);

output = fout.Length + fin.Length;

fout.Close();

fin.Close();

}

public string Chek(string inName, string outName)

{

string s=string.Empty;

FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);

FileStream fout = new FileStream(outName, FileMode.Open, FileAccess.Read);

byte[] hashValue;

byte[] hashValue1 = new byte[fout.Length];

RIPEMD160Managed rip = new RIPEMD160Managed();

hashValue = rip.ComputeHash(fin);

fout.Read(hashValue1, 0, (int)fout.Length);

fout.Close();

fin.Close();

foreach (var i in hashValue.Except(hashValue1))

{

s = "Не идентичные";

}

if (s == string.Empty) { s = "Идентичные"; }

return s;

}

private void button1_Click(object sender, EventArgs e)

{

openFileDialog1.FileName = "";

openFileDialog1.Filter = "All file| *.*";

saveFileDialog1.FileName = "";

saveFileDialog1.Filter = "RIPEMD160 file| *.rip";

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

tim = DateTime.Now;

Hash(openFileDialog1.FileName, saveFileDialog1.FileName);

label1.Text = (DateTime.Now - tim).ToString();

}

}

}

private void button2_Click(object sender, EventArgs e)

{

openFileDialog1.FileName = "";

openFileDialog1.Filter = "All file| *.*";

openFileDialog2.FileName = "";

openFileDialog2.Filter = "RIPEMD160 file| *.rip";

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

if (openFileDialog2.ShowDialog() == DialogResult.OK)

{

label1.Text = Chek(openFileDialog1.FileName, openFileDialog2.FileName);

}

}

}

}

}

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.IO;

using System.Security.Cryptography;

namespace diplom

{

public partial class SHA512 : Form

{

public static int keysize;

public static long output;

private DateTime tim;

public SHA512()

{

InitializeComponent();

}

public void Hash(string inName, string outName)

{

FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);

FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);

fout.SetLength(0);

byte[] hashValue;

SHA512CryptoServiceProvider sha = new SHA512CryptoServiceProvider();

hashValue = sha.ComputeHash(fin);

keysize = sha.HashSize;

fout.Write(hashValue, 0, hashValue.Length);

output = fout.Length + fin.Length;

fout.Close();

fin.Close();

}

public string Chek(string inName, string outName)

{

string s = string.Empty;

FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);

FileStream fout = new FileStream(outName, FileMode.Open, FileAccess.Read);

byte[] hashValue;

byte[] hashValue1 = new byte[fout.Length];

SHA512CryptoServiceProvider sha = new SHA512CryptoServiceProvider();

hashValue = sha.ComputeHash(fin);

fout.Read(hashValue1, 0, (int)fout.Length);

fout.Close();

fin.Close();

foreach (var i in hashValue.Except(hashValue1))

{

s = "Не идентичные";

}

if (s == string.Empty) { s = "Идентичные"; }

return s;

}

private void button1_Click(object sender, EventArgs e)

{

openFileDialog1.FileName = "";

openFileDialog1.Filter = "All file| *.*";

saveFileDialog1.FileName = "";

saveFileDialog1.Filter = "SHA512 file| *.sha512";

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

tim = DateTime.Now;

Hash(openFileDialog1.FileName, saveFileDialog1.FileName);

label1.Text = (DateTime.Now - tim).ToString();

}

}

}

private void button2_Click(object sender, EventArgs e)

{

openFileDialog1.FileName = "";

openFileDialog1.Filter = "All file| *.*";

openFileDialog2.FileName = "";

openFileDialog2.Filter = "SHA512 file| *.sha512";

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

if (openFileDialog2.ShowDialog() == DialogResult.OK)

{

label1.Text = Chek(openFileDialog1.FileName, openFileDialog2.FileName);

}

}

}

}

}

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Security.Cryptography;

using System.IO;

namespace diplom

{

public partial class tdes : Form

{

public static string key="", IV="";

public static int keysize = 0;

DateTime tim;

public static long output = 0;

public tdes()

{

InitializeComponent();

}

//

public void Encrypt(String inName, String outName)

{

FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);

FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);

fout.SetLength(0);

byte[] bin = new byte[100];

long rdlen = 0;

long totlen = fin.Length;

int len;

TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();

CryptoStream encStream = new CryptoStream(fout, tdes.CreateEncryptor(), CryptoStreamMode.Write);

keysize = tdes.KeySize;

while (rdlen < totlen)

{

len = fin.Read(bin, 0, 100);

encStream.Write(bin, 0, len);

rdlen = rdlen + len;

}

output = fout.Length + tdes.Key.Length + tdes.IV.Length;

encStream.Close();

}

//

private static void EncryptData(String inName, String outName, String tdesKey, String tdesIV)

{

byte[] key, IV;

//Create the file streams to handle the input and output files.

FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);

FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);

FileStream fkey = new FileStream(tdesKey, FileMode.Open, FileAccess.Read);

FileStream fIV = new FileStream(tdesIV, FileMode.Open, FileAccess.Read);

fout.SetLength(0);

key = new byte[fkey.Length];

IV = new byte[fIV.Length];

fkey.Read(key, 0, (int)fkey.Length);

fIV.Read(IV, 0, (int)fIV.Length);

//Create variables to help with read and write.

byte[] bin = new byte[100]; //This is intermediate storage for the encryption.

long rdlen = 0; //This is the total number of bytes written.

long totlen = fin.Length; //This is the total length of the input file.

int len; //This is the number of bytes to be written at a time.

TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();

CryptoStream encStream = new CryptoStream(fout, tdes.CreateEncryptor(key, IV), CryptoStreamMode.Write);

keysize = tdes.KeySize;

//Read from the input file, then encrypt and write to the output file.

while (rdlen < totlen)

{

len = fin.Read(bin, 0, 100);

encStream.Write(bin, 0, len);

rdlen = rdlen + len;

}

output = fout.Length;

encStream.Close();

}

private static void DecryptData(String inName, String outName, String tdesKey, String tdesIV)

{

byte[] key, IV;

//Create the file streams to handle the input and output files.

FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);

FileStream fkey = new FileStream(tdesKey, FileMode.Open, FileAccess.Read);

FileStream fIV = new FileStream(tdesIV, FileMode.Open, FileAccess.Read);

FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);

fout.SetLength(0);

key = new byte[fkey.Length];

IV = new byte[fIV.Length];

fkey.Read(key,0,(int)fkey.Length);

fIV.Read(IV, 0, (int)fIV.Length);

//Create variables to help with read and write.

byte[] bin = new byte[100]; //This is intermediate storage for the encryption.

long rdlen = 0; //This is the total number of bytes written.

long totlen = fin.Length; //This is the total length of the input file.

int len; //This is the number of bytes to be written at a time.

TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();

CryptoStream encStream = new CryptoStream(fout, tdes.CreateDecryptor(key, IV), CryptoStreamMode.Write);

keysize = tdes.KeySize;

//Read from the input file, then encrypt and write to the output file.

while (rdlen < totlen)

{

len = fin.Read(bin, 0, 100);

encStream.Write(bin, 0, len);

rdlen = rdlen + len;

}

encStream.Close();

}

private void Form1_Load(object sender, EventArgs e)

{

}

private void button1_Click(object sender, EventArgs e)

{

saveFileDialog1.FileName = "";

saveFileDialog1.Filter = "TDES key file| *.tdeskey";

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();

tdes.GenerateKey();

key = saveFileDialog1.FileName;

FileStream fkey = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.Write);

fkey.Write(tdes.Key, 0, tdes.Key.Length);

fkey.Close();

}

if (key != "" & IV != "")

{

panel1.Enabled = true;

}

}

private void button4_Click(object sender, EventArgs e)

{

saveFileDialog1.FileName = "";

saveFileDialog1.Filter = "TDES IV file| *.tdesIV";

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();

tdes.GenerateIV();

FileStream fiv = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.Write);

IV = saveFileDialog1.FileName;

fiv.Write(tdes.IV, 0, tdes.IV.Length);

fiv.Close();

}

if (key != "" & IV != "")

{

panel1.Enabled = true;

}

}

private void button5_Click(object sender, EventArgs e)

{

openFileDialog1.FileName = "";

openFileDialog1.Filter = "TDES key file| *.tdeskey";

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

key = openFileDialog1.FileName;

}

if (key != "" & IV != "")

{

panel1.Enabled = true;

}

}

private void button6_Click(object sender, EventArgs e)

{

openFileDialog1.FileName = "";

openFileDialog1.Filter = "TDES IV file| *.tdesIV";

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

IV = openFileDialog1.FileName;

}

if (key != "" & IV != "")

{

panel1.Enabled = true;

}

}

private void button2_Click(object sender, EventArgs e)

{

openFileDialog1.FileName = "";

openFileDialog1.Filter = "All file| *.*";

saveFileDialog1.FileName = "";

saveFileDialog1.Filter = "TDES file| *.tdes";

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

tim=DateTime.Now;

EncryptData(openFileDialog1.FileName, saveFileDialog1.FileName,key,IV);

label1.Text = (DateTime.Now - tim).ToString();

}

}

}

private void button3_Click(object sender, EventArgs e)

{

openFileDialog1.FileName = "";

openFileDialog1.Filter = "TDES file| *.tdes";

saveFileDialog1.FileName = "";

saveFileDialog1.Filter = "All file| *.*";

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

tim = DateTime.Now;

DecryptData(openFileDialog1.FileName, saveFileDialog1.FileName, key, IV);

label2.Text = (DateTime.Now - tim).ToString();

}

}

}

}

}

Размещено на Allbest.ru


Подобные документы

Работы в архивах красиво оформлены согласно требованиям ВУЗов и содержат рисунки, диаграммы, формулы и т.д.
PPT, PPTX и PDF-файлы представлены только в архивах.
Рекомендуем скачать работу.