/* 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[] = "ONETIMEPAD";
    char key[] = "TBFRGFARFM";
    char *cipher;
    int l = strlen(plain);
    cipher = (char *)malloc(l);
    for(i=0;i<l;i++) cipher[i] = 'A' + ((plain[i] - 'A') + (key[i % strlen(key)] - 'A') + 1) % 26;
    cipher[l] = '\0';
    printf("%s -> %s\n",plain,cipher);
    for(i=0;i<l;i++) plain[i] = 'A' + ((cipher[i] - 'A') - (key[i % strlen(key)] - 'A') + 25) % 26;
    plain[l] = '\0';
    printf("%s -> %s\n",cipher,plain);
}
