2012
IT352 : Network Security | Najwa AlGhamdi
[MINI PROJECT 1] Instructions about mini-project1 programming assignments
IT352: Security System, Najwa AlGhamdi Page 2
Programming environment
1. Programming language : C#.net
2. Programming environment: Visual Studio.net, you can download an express version
of c# from here.
Part 1 – Encryption
Project Setup
Go to File>New>Project. The following dialog box will appear.
Select “Console Application” template. Name the project part_Encryption. Place the file
ciphertext.dat and key.dat in your project folder>bin>debug.
Code
In “program.cs” header add using System.Security.Cryptography;
using System.IO;
add the following functions befor main.
IT 352 :Network Security
2nd Semester 1432/33 H
Mini Project1 : Encryption
Due:Fri, 2 March @ Midnight
King Saud University
College of Computer and Information Sciences
Department of Information Technology
IT352: Security System, Najwa AlGhamdi Page 3
static string decrypt ( byte[] key , byte[] data)
{
// write the decryption code here
}
Use this function to read data
static byte[] read_data( string filename)
{
Byte[] bytes;
FileStream stream = new FileStream(filename, FileMode.Open,
FileAccess.Read);
BinaryReader br = new BinaryReader(stream);
//read the stream
bytes = br.ReadBytes( Convert.ToInt16 (stream.Length));
//store data in array of bytes
br.Close();
stream.Close();
return bytes;
}
in “program.cs” static void Main(string[] args) add
string cipherfile= "";
string key_file = "" ;
string output = "" ;
// read input from console
cipherfile = args[0];
key_file = args[1];
output = args[2];
// read data and key from file
byte[] data= read_data(cipherfile);
byte[] key = read_data(key_file);
// write output in file
StreamWriter writer =new StreamWriter(output);
writer.WriteLine(decrypt(key, data);
writer.Close();
To view the output, go to your project folder >bin>debug, copy all files there in a folder
named “EXE-FILE” . Then open the command line prompt window and do as it shown in the
figure below.
IT352: Security System, Najwa AlGhamdi Page 4
I placed the EXE-FILE folder under the D to easy access it. Now, open EXE-FILE folder, you should find
a text file called “output” containing the decrypted message.
Part2- Brute Force
Project Setup
Go to File>New>Project. The following dialog box will appear.
IT352: Security System, Najwa AlGhamdi Page 5
Select “Console Application” template. Name the project “findk”. Place the file ciphertext2.dat
and partial_key.dat in your project folder>bin>debug.
Code
In “program.cs” header add using System.Security.Cryptography;
using System.IO;
add the following functions befor main.
static string decrypt ( byte[] key , byte[] data)
{
// use the same decryption function in part1
}
Use this function to read data
static byte[] read_data( string filename)
{
Byte[] bytes;
FileStream stream = new FileStream(filename, FileMode.Open,
FileAccess.Read);
BinaryReader br = new BinaryReader(stream);
//read the stream
bytes = br.ReadBytes( Convert.ToInt16 (stream.Length));
//store data in array of bytes
br.Close();
stream.Close();
return bytes;
}
static string findkey(byte[] cipher_text, byte[]partial_key)
{
//write your brute force function here
}
use this function for output
static void print_resaults(string resault , byte[] key)
{ //' function objective : to print the decrypted message , the missing
bytes and the time spend in searching process
//' parametter : resault that hold the decrypted message
//' key that hold the decryption key
IT352: Security System, Najwa AlGhamdi Page 6
string hex ;
byte[] missingbytes = {0,0,0,0} ;
Array.Copy (key, 12, missingbytes, 0, 4);
Console.WriteLine(" The message = " + resault);
span = date2.Subtract(date1);
//' convert the missing bytes to hex
hex = System.BitConverter.ToString(missingbytes, 0, 4);
Console.WriteLine("The key = " + System.BitConverter.ToString(key, 0,
16));
Console.WriteLine(" The missing bytes in hex = " + hex);
// print the time spent
Console.WriteLine(" press any key to continue ");
Console.Read();
}
in “program.cs” static void Main(string[] args) add
string cipherfile = "";
string partial_key_file = "";
string plain_text ;
cipherfile = args[0];
partial_key_file = args[1];
byte[] data= read_data(cipherfile);
byte[] partial_key = read_data(partial_key_file);
byte[] fullkey = {0,0,0,0, 0,0,0,0 ,0,0,0,0, 0,0,0,0};
System.Array.Copy(partial_key, 0, fullkey, 0, 12);
plain_text = findkey(data, fullkey);
print_resaults(plain_text, fullkey);
To view the output, go to your project folder >bin>debug, copy all files there in the folder
“EXE-FILE” . Then open the command line prompt window and do as it shown in the figure
below.
IT352: Security System, Najwa AlGhamdi Page 7
What to submit A zipped folder contains the following
1. EXE-FILE : contains the two-parts’ EXE files.
2. Source-code : contains the two projects.
3. Report: tell your story in how did decrypt and implement the brute force with screen shots of
the results.
Top Related