Академический Документы
Профессиональный Документы
Культура Документы
Submitted By
SANJUKTA MISHRA
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
BRAINWARE UNIVERSITY
398, RAMAKRISHNAPUR ROAD, BARASAT
KOLKATA-700124
TO WHOM IT MAY CONCERN
Prepared By
Have completed their Minor Project work entitled Encrypted Chat Server. They
have fulfilled these requirements and the project can be successfully implemented. To
far my knowledge goes their work was not submitted to any other
University/Institution for the award of any degree, diploma, fellowship or other
similar titles or prizes and the work has not been published in any journal or
magazine.
Date: 08-06-2019
---------------------------------------------
SANJUKTA MISHRA
Assistant Teacher
Department Of Computer Science and
Engineering(CSE)
BRAINWARE UNIVERSITY
398,RAMAKRISHNAPURROAD,BARASAT
KOLKATA-700124
TO WHOM IT MAY CONCERN
This is to certify that Utpal Debnath, Shyamal Saha, Ramkrishna Maity, Alok Barik,
2nd year(4thSemester) students of the BCA course of Brainware University undertook
a project as ‘MINOR PROJECT’, entitled Encrypted Chat Server under the
supervision of Sanjukta Mishra, Assistant Teacher during 2019 using C Language.
They worked sincerely and regularly on this project and completed their assigned
work satisfactorily.
Date: 08-06-2019
---------------------------------------------
Head of the Department
Department of Computational Science
BRAINWARE UNIVERSITY
398,RAMAKRISHNAPURROAD,BARASAT
KOLKATA-700124
-------------------------------------------- ---------------------------------------------
Project Coordinator External Examiner
BCA
Department of Computer Science and
Engineering
BRAINWARE UNIVERSITY
398,RAMAKRISHNAPURROAD,BARASAT
KOLKATA-700124
DECLARATION
This is here by declared that We, Utpal Debnath, Shyamol Saha, Ramkrishna Maity,
Alok Barik, student of 4th semester of BCA, have carried out our 4th semester project
work entitled Encrypted Chat Server under the guidance of Sanjukta Mishra
Assistant Teacher Department of Computer Science and Engineering Brainware
University is done by ourselves in the fulfillment for the 4th semester of BCA. It is
further declared that the project work has not been submitted to any other academic
university for the award of any degree of examination.
The said project work will not be under any circumstances be used for any university
examination except for BCA of Brainware University.
We have received the assistance and cooperation of quite a number of people during
our project Encrypted Chat Server. So we hereby take the opportunity to extend our
sincere gratitude to all those who have provided their assistance and cooperation and
valuable suggestion from time to time in spite of their busy schedule.
First, we would like to thank our project guide Sanjukta Mishra. She has not just
helped us but provided her valuable suggestion from time to time. We would like to
extend our sincere gratitude to Sanjukta Mishra and all other faculty members, entire
Technical Assistant team of Department of Computational Science for their
encouraging support and for providing us a pleasant atmosphere during the period of
project development.
Lastly, we would like to thank our parents for their overall support.
2. INTRODUCTION
Implementing a chat server application which provides a goof opportunity for a beginner to design
and implement a network based system. The design is very simple and implemented in C. The
encryption and decryption method which is used in the project is also easy to understand and
develop and it provides security to both side, server and client. To start chatting client should get
connected to server. It is made up of 2 applications the client application and the server application.
We will focus on TCP socket connections which are a fundamental part of socket programming.
Keywords: sockets, client-server, C network programming-socket functions.
3. METAMORPHOSIS
3.1. STATEMENT OF THE PROBLEM
The client-server communication model is used in a wide variety of software applications. The main
weakness of client-server chat application is that there is no security provided to data which is
transferred between clients. Any unauthorized client can hack the client access and can change the
data. This is the main objective of this project (To develop a secured Client-Server Chat
Application).
1
4. DESIGN
TCP is used as the transport layer protocol, since it provides reliable delivery which is critical for
the given application. TCP does not provide timing guarantee, which is not very important in the
given scenario.
4.1 SERVER
The server is implemented as a singleton class. The main thread opens a server socket on the local
inet address and port 2000, which has been arbitrarily chosen and hard coded. It then waits for
clients to connect to it. When a client connects to the server, it creates a separate thread. The thread
dedicated to the client opens a buffered stream to read input messages from the client and a print
writer stream to send messages to the client.
The message going from a client to the sever are string with at least one word. The thread dedicated
to the client waits for the incoming massage.
4.2 CLIENT
A client is a system that accesses or desires for a service made accessible by a server.
The Client is implemented using two threads, one each for incoming and outgoing messages. The
main thread opens the socket and connects to the server. It then opens input buffered stream and
print writer for incoming and outgoing messages respectively.
When exit is requested, the client sends exit message to the server, waits for its response, and
closes the streams and exits.
Here is a quick example of the encryption and decryption steps involved with the Caesar
cipher. The text we will encrypt is ‘Hello', with a shift (key) of 1.
2
H e l l O
i f m m p
Basically these things are happening.
Figure: 2
When client get a message from the serve, client will be asked for the key to decrypt the message.
Similarly when client send a message to the server the message will be first encrypted and then send
to the server.
TCP: TCP is a transport layer protocol used by applications that require guaranteed delivery of
data. Basically, it is a connection-oriented protocol. To communicate over TCP one must first have
to establish a connection between pair of sockets, where one socket is client and the other belongs
to server. After the connection is established between them then they can communicate with each
other.
PORT: Port is a software mechanism that allows the centralized connected Servers to listen for
requests made by clients. Port is actually purposed as a gateway to listen for the requested
parameters by the server terminals or other machines. It is a software address on a system that is on
the network. Entire request response proceeding among this Application is carries through machine
ports.
IP: This refers to Internet Protocol; it is the reasonable network address of device on a network. It is
notational called dotted-decimal (for instance: 128.1.0.1)
3
5. SYSTEM ANALYSIS
5.1 FLOW CHART
client server
Massage from Key Encryption Key Decrypted
client Message message
server server
Decrypted Key Encryption Key Message from
message Message server
Figure 3
4
5.2 PROJECT WORK
Before sending and receiving any massages from server to client or client to server, we have to
make the connection between them. So the first thing have to do is to connection of two nodes. One
is server and another is client. Firstly we have created two socket in server and client using socket().
Then in the both side (server and client) initialize the address structure as per the server and bind the
socket to the address of the server using the bind(); Then server will listen the connection with the
listen() function. After that connection is established between server and client means we can now
send data.
Here the first massage will go from client to server. As we have implemented encryption method in
the client part, so the message will encrypt the message with the help of a key. And the key will be
known to both the server and the client. In the server side there a decryption method is
implemented, so before server receives the message, there will be a print like “Enter the key to
decrypt the message:”. According to the encryption and decryption method if sever is able to enter
the right key (which was given by client) then only the actual message will be shown. If wrong key
is entered it will not throw any error, it will just print some another words which is meaningless.
Encryption and decryption method is implemented in the both side of server and client. Before
sending any message form server/client to client/server, we have to give a key to encrypt the
message then to decrypt the message.
5
6. USER MANUAL
6.1 ESTABLISH THE CONNECTION
Step 1: Type the massage and enter the encryption key. End hit enter.
Figure 4
6
Step 2: Program control will go to the Server terminal. Give the decryption key there
(Client’s provided key).
Figure 5
Step 3: After hitting the enter the massage will be decrypted and shown.
Figure 6
7
Step 4: Type message again in the server box. Provide the key and hit enter.
Figure 7
Step 5: Enter the decryption key in the client terminal and decrypted message will be printed.
Figure 8
8
7. SOURCE CODE
Server code
#include "inetu.h"
#include <stdio.h>
bzero((char *)&serv_addr,sizeof(serv_addr));
serv_addr.sin_family=AF_INET;
serv_addr.sin_port=htons(SERV_TCP_PORT);
serv_addr.sin_addr.s_addr=htonl(INADDR_ANY);
listen(sockfd,5);
printf("\n\n\n\n::::::::::::::::::::::::::::Server Portal:::::::::::::::::::::::::::::::::\n\n\n\n");
for(;;)
{
clilen=sizeof(cli_addr);
newsockfd=accept(sockfd,(struct sockaddr *)&cli_addr,&clilen);
if(newsockfd<0)
perror("Error in accept");
if((childpid=fork())<0)
perror("Error in fork");
else if(childpid==0) /*child*/
{
//close(sockfd);
for(;;)
{
n=readline(newsockfd,line,MAXLINE);
if(n==0)
return;
else if(n<0)
perror("error");
9
printf("\nEnter key to dycrypt the massage: ");
scanf("%d",&key);
for(u = 0; line[u] != '\0'; ++u)
{
ch = line[j]; //encryption code
if((ch >= 'a' || ch >= 'A') && (ch <= 'z' || ch <= 'Z'))
{
ch = ch - key;
line[j] = ch;
}
}
printf("\n\::Message from Client:: IP Address: %s:: %s
",inet_ntoa(cli_addr.sin_addr),line);
printf("\nMessage to client: ");
getchar();
fgets(sline,MAXLINE,stdin);
n=strlen(sline);
sline[n]=0;
if(writen(newsockfd,sline,n)!=n)
perror("error");
}
close(sockfd);
exit(0);
// memset(mm,'\0',200);
}
close(newsockfd); /*parent*/
}
}
Client code
#include "inetu.h"
if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0)
perror("Error in socket");
bzero((char *)&serv_addr,sizeof(serv_addr));
serv_addr.sin_family=AF_INET;
serv_addr.sin_port=htons(SERV_TCP_PORT);
serv_addr.sin_addr.s_addr=htonl(INADDR_ANY);
printf("\n\n\n\n::::::::::::::::::::::::::::Client Portal:::::::::::::::::::::::::::::::::\n\n\n\n");
printf("\nEnter message to server: ");
//while(fgets(sendline,MAXLINE,stdin) != NULL)
for(;;)
{
fgets(sendline,MAXLINE,stdin);
printf("Enter key to encrypt the massage: ");
scanf("%d",&key);
for(u = 0; sendline[u] != '\0'; ++u)
{
ch = sendline[j]; //encryption code
if((ch >= 'a' || ch >= 'A') && (ch <= 'z' || ch <= 'Z'))
{
ch = ch + key;
sendline[j] = ch;
}
}
n=strlen(sendline);
if(writen(sockfd,sendline,n) != n)
perror("error");
n=readline(sockfd,recvline,MAXLINE);
if(n<0)
perror("error");
//getchar();
recvline[n]=0;
}
close(sockfd);
exit(0);
}
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<netdb.h>
#include<fcntl.h>
#include<malloc.h>
#include<stdlib.h>
#include<string.h>
12
#define TRUE 1
#define FALSE 0
#define MAXLINE 50
char *pname;
int value,val;
for(n=1;n<maxlen;n++)
{
if( (rc=read(fd,&c,1) )== 1)
{
*ptr++=c;
if(c=='\n')
break;
}
else if(rc==0)
{
if(n==1)
return 0;
else break;
}
else return(-1);
}
*ptr=0;
return(n);
}
nleft=nbytes;
while(nleft>0)
{
nwritten=write(fd,ptr,nleft);
nleft=nleft-nwritten;
ptr=ptr+nwritten;
}}
13
8. CONCLUSION
8.1 LIMITATION
There is no graphical user interface (GUI). So there are no chat windows and the user needs to
compile the code through GCC compiler. And only one user can connected at a time with the
server.
The encryption and decryption method used in this code is secure but not the hardest.
14
References:
1. W. Richard Stevens, TCP/IP Illustrated, Volume 1: The Protocols.
3. Cryptography and Network Security, Atul Kahate, McGraw Hill Education; Third edition.
Website:
[1] https://www.geeksforgeeks.org/tcp -server-client-implementation-in-c/
[2] https://www.tutorialspoint.com/unix_sockets/client_server_model.html
[3] www.wikipedia.com
[4] https://github.com/hasanuzzaman2013/java_windowbuilder
15
16