--- In [email protected], "jagomaniak" <[EMAIL PROTECTED]> wrote: > > I'd like a little guidance as to what functions I should use that are > most effective. > > For encoding and decoding, I have this piece of code: > > int code(char c) > { > if(c >= 'A' && c <= 'Z') > return 10 + c - 'A'; > else if(c >= '0' && c <= '9') > return c - '0'; > } > > > int decode(char c) > { > if(c >= '0' && c <= '9') > return c + '0'; > else if(c >= 10) > return c - 10 + 'A'; > } > > char encode(char c, char k) > { > return decode((code(c) + code(k)) % CBASE); > } > > int main(int argc, char *argv[]) > int key_length = strlen(argv[2]); > int key_count = 0; > int c; > > > while((c = getchar()) != EOF) > { > putchar(encode((char) c, argv[2][key_count%key_length])); > key_count++ ; > > } > > return EXIT_SUCCESS; > > } > > It sort of works but it always returns one letter/number more than it > was given in the input text. > > So, when I have a key HELLO and input text MORNING, it will give me > 32C864U, while it should be only 32C864. > > I haven't yet found out what piece of code adds the extra letter > there, any ideas? >
Sorry, I made a typo. Key HELLO and text MORNING should give me 32C864U, but it gives me one character more, always it's 'P'.
