
ASCII encryptor I want to develop a program that encrypt and decrypt. The messages stored in a file should be in the corresponding ASCII format. And if it?s a word, concatenate a letter w to show that the word still continues. When a space is encountered, add a word space. Change word by word until the end of the message which is later stored in a file. This is called encryption. When one wants to read the contents of the file, It should display the encrypted form and also the original version. Changing the copy to the original will be called decrypting. Eg

#include <stdio.h>
#include <string.h>
#define MAX_LINE_LEN 256
#define MIN_PRINTABLE_ASCII 32
#define MAX_PRINTABLE_ASCII 126
#define NUM_PRINTABLE (MAX_PRINTABLE_ASCII - MIN_PRINTABLE_ASCII + 1)
typedef enum { false = 0, true } bool;
typedef unsigned char uchar;
void encode(uchar *,int);
void decode(uchar *,int);
int main(int argc, char *argv[]) {
uchar line[MAX_LINE_LEN];
int n;
bool inputOk;
for (inputOk = false; inputOk == false; ) {
printf("Enter offset: ");
fgets((char *)line,MAX_LINE_LEN,stdin);
inputOk = (sscanf((char *)line,"%d",&n) == 1);
}
n %= NUM_PRINTABLE;
printf("Enter line of text: ");
fgets((char *)line,MAX_LINE_LEN,stdin);
*strchr((char *)line,'\n') = '\0';
encode(line,n);
printf("\nEncoded: \"%s\"\n",line);
decode(line,n);
printf("Decoded: \"%s\"\n",line);
return 0;
}
void encode(uchar *s,int x) {
uchar *p = s;
int z;
while (*p != '\0') {
z = (int)*p + x;
if (z > MAX_PRINTABLE_ASCII) {
z -= NUM_PRINTABLE;
} else if (z < MIN_PRINTABLE_ASCII) {
z += NUM_PRINTABLE;
}
*p++ = (uchar)z;
}
}
void decode(uchar *s, int x) {
encode(s,x *= -1);
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.