Trouble Encoding with Different Alphabet

Joined
Feb 4, 2009
Messages
2
Reaction score
0
Hi, everybody. I can't figure out how to use a different alphabet. My code is below and the trouble is in the encode4 and decode4 functions, although if I can get encode4 to work, decode4 shouldn't be a problem. I'm supposed to use the ciphertext "THEQUICKBROWNFXJMPSVLAZYDG" in place of the alphabet and I'm not sure how to do so. My code is below.


#include <stdio.h>
#include <string.h>
#define Key t

char encode( char in )
{
char out;
out = in;
out = out - 32;
return out;

}

char decode( char in )
{
char out;
out = in;
out = out + 32;
return out;

}

char encode3( char in, int shift )
{
char out;
out = in + shift;
out = out - 32;
return out;

}

char decode3( char in, int shift )
{
char out;
out = in - shift;
out = out + 32;
return out;

}

char encode4( char in )
{
int i;
char out;
out = in;
//out = out - 32;
char str[26] = "THEQUICKBROWNFXJMPSVLAZYDG";
char str2[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (out = str2)
out = str;

//ABCDEFGHIJKLMNOPQRSTUVWXYZ
//THEQUICKBROWNFXJMPSVLAZYDG



}

char decode4( char in )
{
char out;
out = in;

int i;

char str[26] = "THEQUICKBROWNFXJMPSVLAZYDG";
char str2[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (out = str)
out = str2;

out = out + 32;
return out;

}

char encode5( char in, char key )
{
char out;
out = in;
//out = out - 32;
out = out ^ key;



return out;

}

char decode5( char in, char key )
{
char out;
out = in;
//out = out + 32;
out = out ^ key;


return out;

}


void FilterInput( char s[], char t[] )
{
int i, j, len;
char c;
len = strlen( s );
j = 0;
for ( i = 0; i < len; ++i)
{
c = s;
if ((c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') )
{
if ( c >= 'a' && c <= 'z')
c = c - 32;

t[j] = c;
j++;
}
}
t[j] = '\0';
}

int main()
{
char str1[80], str2[80];
int i, j, len, shift;
char key;
char secret[80], show[80];

fgets(str1, 70, stdin);
/*printf("How much would you like to shift each character? "); //Version 3
scanf("%i", &shift);*/ //Version 3
/*printf("What character would you like to XOR the string against?"); //Version 5
scanf("%c", &key);*/ //Version 5
printf("Original: %s\n", str1);
FilterInput( str1, str2);
printf("Filtered: %s\n", str2);


len = strlen(str2);
/*for (i = 0; i < len; ++i)
secret = encode3( str2, shift);*/ //Version 3
for (i = 0; i < len; ++i)
secret = encode4( str2);
/*for (i = 0; i < len; ++i)
secret = encode5( str2, key);*/ //Version 5
secret = '\0';
printf("Encoded: %s\n", secret);

len = strlen( secret );
/*for (i = 0; i < len; ++i)
show = decode3( secret, shift);*/ //Version 3
for (i = 0; i < len; ++i)
show = decode4( secret);
/*for (i = 0; i < len; ++i)
show = decode5( secret, key);*/ //Version 5
show = '\0';
printf("Decoded: %s\n", show);


return 0;

}

I've been working on this problem for 3 days and have ran out of ideas. Thanks in advance to anyone who can help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top