DAA Report
DAA Report
DAA Report
Members:
Yusra Ali Shaikh (13573)
Khizar Waseem (16738)
Muhammad Ahmed (14571)
Problem
To develop Client-Server chat application in which users can create a group
chat by either creating a server or joining an already created server by some
other user. The main problem is to apply a security algorithm which will
encrypt and decrypt the text messages in order to provide secure data transfer.
(Fig. 1)
Complexity
To encrypt and decrypt messages we use DES algorithm. Since DES is a block
cipher, that is, the data is encrypted in form of blocks, therefore, the size of a
single message will always be a 64-bit block encrypted with a key of 64-bit key.
Since the size of message and key is fixed, this algorithm has complexity of
O(1) for a single block of text and O(m) for multiple blocks where m is the
number of messages encrypted.
Algorithm
DES (Data Encryption Standard) is a block cipher encryption algorithm. It is a
symmetric key algorithm which means it shares same key with sender and
receiver of the message to encrypt/decrypt. DES takes 64-bit plaintext as input
PAGE 1
and encrypts it with a 64-bit key and sends the resulting cipher text to
receiver.
(Fig. 2)
PAGE 2
Key Generation:
A 64-bit binary number is used which goes through a number of steps of
Permutation, Circular Left-Shifts etc. to generate 16 sub-keys. These sub-keys
are used in each of 16 rounds of encryption and decryption.
Encryption:
After generation of 16 sub-keys, a block of 64-bits is encrypted by applying
following steps:
IP(Initial Permutation)
A Function (16 rounds)
Swapping of left and right 32-bits
IP-1(Inverse Initial Permutation)
Decryption:
The decryption part is same as the encryption except the order of sub-keys
application. In decryption, the generated 16 sub-keys are applied in reverse
order i.e. K16 first, then K15, then K14 and so on.
IP
Algorithm Correctness
The correctness of this algorithm can be proved in a way that, the fact of DES
being an encryption algorithm and that too being symmetric key, it will encrypt
a plain text and always decrypt its cipher text into correct plaintext because
the steps of decryption are no different from encryption except that they are
reversed only. Therefore, this algorithms correctness is proved.
Pseudo Code
Cipher (plainBlock[64], RoundKeys[16, 48], cipherBlock[64])
{
permute (64, 64, plainBlock, inBlock, InitialPermutationTable)
split (64, 32, inBlock, leftBlock, rightBlock)
for (round = 1 to 16)
{
mixer (leftBlock, rightBlock, RoundKeys[round])
if (round!=16) swapper (leftBlock, rightBlock)
}
combine (32, 64, leftBlock, rightBlock, outBlock)
permute (64, 64, outBlock, cipherBlock, FinalPermutationTable)
}
PAGE 3
Cost Analysis
The cost of implementing this algorithm depends on number of factors, having
said that, weve compared the time and speed of this algorithm on two
different platforms i.e. C# and C++ and both perform differently as we increase
or decrease the size of data. Graphs in following figures show the comparison:
PAGE 4
Implementation
Since DES algorithm is used in chat application, the implementation part breaks
into following two major parts:
Chat App
DES Algorithm
Chat App:
The chat application is a GUI based application developed on C# WinForms
platform. Socket Programming is used to send and receive messages on the LAN
network.
There are 3 classes in this app, Form1.cs, Server.cs and Client.cs.
Form1.cs is the main class i.e. the program starts from this class.
Server.cs class is called when user clicks on Create Server button. This class
has all the functionality required to start server like getting ready to accept
incoming client connections on a certain port number and starting new thread
for each client that connects to server. As the server connects to a client, it
can start chatting with the client and the messages sent/received are
encrypted/decrypted on backend.
Client.cs class is started when user decides to join an existing server on the
network by giving IP(Internet Protocol) and Port number of server. In this class,
an object of DES class is created to apply the algorithm in the chat app.
DES Algorithm:
There is another class called DES.cs in which the DES algorithm is
implemented. The methods are created in a way that they take plain and
cipher texts as input and output encrypted/decrypted text. Client.cs and
Server.cs classes create object of this (DES.cs) class and invoke methods when
user wants to send/receive messages.
Correctness Runs
For checking the correctness of this algorithm we used multiple strings as test
cases which we matched with some of the online DES encryption tools to check
if the algorithm is correctly working in encrypting and decrypting messages.
Test Cases:
Since this is a chat application, we used common messages to start a
conversation like hello, hey etc. and a randomly generated 64-bit binary
PAGE 5
Cost Runs
To check the cost, we run test cases with texts H,HEL and HELLO on two
different platforms i.e. C# and C++ and check how they perform in terms of
time as the data size increases.
PAGE 6
References
1. Fig. 1 (Page 2) http://www01.ibm.com/software/webservers/hostondemand/library/infocenterg
afinal/hod/en/doc/redbook/images/6182ax013.gif
2.
3.
Fig. 2 (Page 3)
http://azmadagreen.blogspot.com/2009_08_01_archive.html
Pseudo code (Page 4)
http://highered.mheducation.com/sites/dl/free/0072870222/385981
/Student_Solution_Chap_06.pdf
Running Code
Since this program is written in C# language, it requires you to have Visual
Studio IDE to run its code. Below are the instructions to run the code of this
program:
1. First, import the project folder in Visual Studio 2013.
2. Press F5 button to run the code.
3. A form will show up with two buttons, each for Creating or Joining
Server respectively.
4. When you go for Create Server button, a new window will be shown in
which there is an IP address of your network and textArea and textField
for chatting with clients joining this server.
5. If Join Server button is clicked, the user will be shown a new window
where he/she may provide existing servers IP and port number and click
Connect button. This will result in a message that youre connected to
server and Keys are exchanged between client and server as soon as the
connection is established, and the key is used for later
encryption/decryption of messages.
There are following three main classes in this project:
DES.cs
Server.cs
Client.cs
PAGE 7