/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
  int i;
  char plain[] = "Dette er en lille test";
  char key[] = "TBFRGFARFM";
  char *cipher;
  int l = strlen(plain);
  cipher = (char *)malloc(l);
  for(i=0;i<l;i++) cipher[i] = plain[i] ^ key[i % strlen(key)];
  cipher[l] = '\0';
  printf("%s -> %s\n",plain,cipher);
  for(i=0;i<l;i++) plain[i] = cipher[i] ^ key[i % strlen(key)];
  plain[l] = '\0';
  printf("%s -> %s\n",cipher,plain);
}
