I want to implement #if (DEBUG==1) I want an entering and exiting message to print before and after invoking decrypt()
I have no clue to how to do it...my books I so confusing and hopeless!!!
I need help!!
here is my program: A bit long it is basically encrypting and then decrypting a text using a scramble and unscramble key
Code:
#include <stdio.h>
#include <string.h>
#define LINESIZE 60
#define MIN(a,b) (((a)<(b))?(a):(b))
static const char KEY[]="qazxswedcvfrtgbnhyujmkiolp";
void decrypt(const char in[],char out[]);
void encrypt(const char in[],char out[]);
void printtext(const char t[]);
char scramble(const char c);
char unscramble(const char c);
int main(void)
{
const char plaintext[]="Fourscore and seven years ago our fathers \
brought forth upon this continent a new nation, conceived in liberty, \
and dedicated to the proposition that all men are created equal.";
char decrypttext[sizeof(plaintext)/sizeof(char)];
char encrypttext[sizeof(plaintext)/sizeof(char)];
printtext(plaintext);
encrypt(plaintext,encrypttext);
printtext(encrypttext);
decrypt(encrypttext,decrypttext);
printtext(decrypttext);
if (strcmp(plaintext,decrypttext)==0)
puts("plain same decrypttext");
else puts("not identical");
return 0;
}
/*encrypt*/
void encrypt(const char in[],char out[])
{
int k;
for (k=0;in[k];k++)
out[k]=scramble(in[k]);
out[k]='0';
return;
}
/*decrypt*/
void decrypt(const char in[],char out[])
{
int k;
for (k=0;in[k];k++)
out[k]=unscramble(in[k]);
out[k]='0';
return;
}
/*scramble*/
char scramble(const char c)
{
if ((c<'a')|| (c>'z')) return c;
return KEY[c-'a'];
}
/*unscramble*/
char unscramble(const char c)
{
int k;
char alphabet[]="abcdefghijklmnopqrstuvwxyz";
if ((c<'a')||(c>'z')) return c;
for (k=0;k<strlen(KEY);k++)
if (c==KEY[k]) break;
return alphabet[k];
}
/*printtext*/
void printtext(const char t[])
{
int start;
int finish;
int k, tmp;
start =0;
while (start<strlen(t))
{
tmp=MIN((start+LINESIZE),strlen(t));
for (finish=tmp;finish>start;finish--)
if ( (t[finish]==' ') || (t[finish]=='\0') ) break;
for(k=start;k<finish;k++)
putchar(t[k]);
printf("\n");
start=finish+1;
}
printf("\n");
return;
}