I have a simple C Program which is more like a "Echo" Server, for this i want to use encryption, with following requirement,
- From Client side after sending plain text to Server, Client will "encrypt this string" with "predefined password" and keep it ready
- Server will receive plain text, and encrypt this string using pre-defined password and send it back
- Client will receive the encrypted text, compare it with encrypted text on it's side, and if both match, no error, else show error
Been trying lot of options, but here are other requirements, which keeps failing,
- No external libs dependencies
- Encrypted text should be printable and be savable to file (HEX Is fine too)
- This code is run very frequently (like chat server). So needs to be as fast as possible, yet not too easy to guess.
Can i please get some help on completing this code, with Encrypted text needs to be in plain ASCII (or HEX).
Following is the sample of my existing code,
ON CLIENT SIDE
char *randomAllowchar = "abcdefghijklmnopqrstuvwxyz";
char plainStrToServer[30];
// generating 20 char random string
for (n = 0;n < 20;n++) {
key = rand() % 26;
plainStrToServer[n] = randomAllowchar[key];
}
... other code to send this plainStrToServer to server side
// Receiving response from server
char server_reply[200];
if( recv(sock , server_reply , 200 , 0) < 0){
...
}
// comparing if server response matched with sent string
if (strcmp(plainStrToServer,server_reply) != 0) {
// Error
}
ON SERVER SIDE
char buffer[30];
int rc1;
while (1) {
rc1 = read(fd, buffer, sizeof(buffer));
// write back original received message back to client
write(fd , buf, strlen(buffer));
}