I\'ve written a program to encrypt a given message by XOR. It works, but It doesn\'t end. Here is the code.(I have created 3 files):
encrypt.h :
void
Just run
$> kill -l
To see the list of signals in Linux. You will not find SIGKILL (Ctrl + D) signal there :(
Ctrl + D is SIGKILL (0) signal in Linux which is not documented anywhere. Ctrl + Z is for Windows which tell EOF and we need to press "Enter" to close.
When I pressed Ctrl+D to stop it (in cmd)
If that's the cmd
from Windows you probably want Ctrl+Z
.
isprint()
can help:
#include <stdio.h>
#include <ctype.h>
void encrypt(char *message)
{
while (*message) {
*message = *message ^ 31;
message++;
}
}
int main(void)
{
char msg[80];
while (fgets(msg, 80, stdin) != NULL) {
if (!isprint((unsigned char)*msg)) break;
encrypt(msg);
printf("%s", msg);
}
return 0;
}
Add an exit condition:
if( c < 0x20 ) break;
You may need to add other checks also to support backspace without encoding it...
http://www.asciitable.com/
Ctrl-D is used for the console EOF on Unix systems.
Ctrl-Z is used for the console EOF on Windows systems.