-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.cpp
executable file
·66 lines (66 loc) · 1.52 KB
/
client.cpp
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
66
#include<iostream>
#include<client.h>
void client::SetDefaults()
{
key[0]='B', key[1]='A', key[2]='D', key[3]='C',key[4]='F',key[5]='E',key[6]='H',key[7]='G',key[8]='J',key[9]='I',key[10]='L',key[11]='K',key[12]='N',key[13]='M',key[14]='P',key[15]='O',key[16]='R',key[17]='Q',key[18]='T',key[19]='S',key[20]='V',key[21]='U',key[22]='X',key[23]='W',key[24]='Z',key[25]='Y';
message.clear();
possesKey=false;
fp = fopen("out.txt", "w");
fclose(fp);
}
client::client()
{
SetDefaults();
SetID(1); //default client id is 1
}
client::client(int id) {
SetDefaults();
SetID(id);
}
client::~client()
{
}
int client::GetID(void) {
return ID;
}
void client::SetID(int id) {
ID = id;
}
std::string client::GetMessage()
{
Decode();
return message;
}
void client::SetMessage(std::string msg)
{
std::string stn = std::string("");
if(msg.compare(stn)==0)
return;
message.assign(msg);
fp = fopen("out.txt", "a");
fprintf(fp,"%s%d%s%s%s","Client ",GetID(),":",msg.c_str(),"\n"); //file
//fprintf(fp,"%s%d%s%s%s","Client ",GetID(),":",GetMessage().c_str(),"\n"); //file
fclose(fp);
}
void client::SetPossesKey(bool state)
{
possesKey = state;
}
void client::Decode()
{
if (possesKey)
{
std::string codedstring("");
const char *cptr = message.c_str();
char tarr[100];
int tarrindex = 0;
for (register int i = 0; i < message.length(); i++)
{
int index = (int)cptr[i] - 65;
char c = key[index];
tarr[tarrindex++] = c;
}
tarr[tarrindex] = '\0';
message=tarr;
}
}