/***********************************************************
 * crypt                                                   *
 * simple cryptographic library                            *
 * Verteilte Systeme II Kapitel 11                         *
 ***********************************************************
 * 1999 by Frank Kargl (frank.kargl@informatik.uni-ulm.de) *
 ***********************************************************/

#include <stdlib.h>
#include <stdio.h>
#include "crypt.h"

/* debug flag */
#undef DEBUG

/***********************************************************
 *                                                         *
 * Function:                                               *
 * void encrypt(char key, char* plain, char* cipher)       *
 * encrypts a plaintext                                    *
 * Parameters:                                             * 
 *  key - the secret key                                   *
 *  plain - plain text                                     *
 *  cipher - buffer for cipher text                        *
 * Return:                                                 *
 *  -                                                      *
 *                                                         *
 ***********************************************************/

void encrypt(char key, char* plain, char* cipher) {
    int i;
    /*while (strlen(key) < strlen(plain)) {
        strcat(key, key);
    }*/
    for (i = 0; i < strlen(plain); i++) {
	cipher[i] = key ^ plain[i];
    }
    cipher[i] = '\0';
}

/***********************************************************
 *                                                         *
 * Function:                                               *
 * void decrypt(char key, char* cipher, char* plain)       *
 * decrypts a plaintext                                    *
 * Parameters:                                             * 
 *  key - the secret key                                   *
 *  cipher - cipher text                                   *
 *  plain - buffer for cipher text                         *
 * Return:                                                 *
 *  -                                                      *
 *                                                         *
 ***********************************************************/

void decrypt(char key, char* cipher, char* plain) {
    int i;
    /*while (strlen(key) < strlen(plain)) {
        strcat(key, key);
    }*/
    for (i = 0; i < strlen(cipher); i++) {
	plain[i] = key ^ cipher[i];
    }
    plain[i] = '\0';
}