-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.cpp
More file actions
65 lines (58 loc) · 1.26 KB
/
Copy pathserver.cpp
File metadata and controls
65 lines (58 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<stdio.h>
#include<sys/types.h>//socket
#include<sys/socket.h>//socket
#include<string.h>//memset
#include<stdlib.h>//sizeof
#include<netinet/in.h>//INADDR_ANY
#define PORT 8000
#define SERVER_IP "127.0.0.1"
#define MAXSZ 100
static const char key[]="BDUFGH";
void encrypt(char* input, char key[])
{
int k=0;
for(int i=0;i<6;i++)
{
input[i]=input[i]^key[i];
cout<<input[i];
}
cout<<endl;
}
void decrypt(char* input,char key[])
{
for(int i=0;i<6;i++)
{
input[i]=input[i]^key[i];
cout<<input[i];
}
cout<<endl;
}
int main()
{
int sockfd;
struct sockaddr_in serverAddress;
int n;
char input[100000];
sockfd=socket(AF_INET,SOCK_STREAM,0);
memset(&serverAddress,0,sizeof(serverAddress));
serverAddress.sin_family=AF_INET;
serverAddress.sin_addr.s_addr=inet_addr(SERVER_IP);
serverAddress.sin_port=htons(PORT);
connect(sockfd,(struct sockaddr *)&serverAddress,sizeof(serverAddress));
while(1)
{
printf("\nEnter message to send to server:\n");
fgets(input,MAXSZ,stdin);
if(input[0]=='#')
break;
n=strlen(msg1)+1;
encrypt(input,key);
send(sockfd,input,n,0);//SEND
n=recv(sockfd,msg2,MAXSZ,0);//RECV
decrypt(input,key);
n=strlen(input)+1;
send(sockfd,input,n,0);//SEND
cout<<"Sent Message Successfully";
}
return 0;
}