IDEA ofb encryption of a file

This example uses the SSLeay library to encrypt a file one byte at a time.
Script started on Tue Sep 16 11:15:08 1997
sh-2.00$ cat ideaofbenc.c
/* Use OFB with IDEA to encrypt (or decrypt) a file. */
#include <stdio.h>
#include <fcntl.h>
#include "/usr/local/ssl/include/idea.h"

unsigned char  key[] = {
	0x01, 0x23, 0x01, 0x23,
	0x01, 0x23, 0x01, 0x23,
	0x01, 0x23, 0x01, 0x23,
	0x01, 0x23, 0x01, 0x23
};

unsigned char iv[] = {
	0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x01
};

void main(int argc, char * argv[])
{
	int i;
	int num = 0;
	int fd, fd2;
	unsigned char buffer[8];
	unsigned char output[8];
	IDEA_KEY_SCHEDULE enc;
	/* Argument check. */
	if(argc < 3)
	{
		printf("usage: ideaofbenc file file\n");
		exit(1);
	}
	/* Try to open both files, creating output file if necessary. */
	if((fd = open(argv[1], O_RDONLY, 0) ) < 0)
	{
		perror(argv[1]);
		exit(1);
	}
	if((fd2 = open(argv[2], O_WRONLY | O_CREAT, 0666)) < 0)
	{
		perror(argv[2]);
		exit(1);
	}
	
	/* We don't need a decryption schedule for OFB. */
	idea_set_encrypt_key(key, &enc);
	/* Try encrypting one byte at a time. */
	/* Could improve this by increasing the size of the reads
		and writes. */
	while( read(fd, buffer, 1) > 0)
	{
		idea_ofb64_encrypt(buffer, output, 1, &enc, iv, &num);
		write(fd2, output, 1);	
	}
	close(fd);
	close(fd2);
}

sh-2.00$ cc ideaofbenc.c /usr/local/ssl/lib/libcrypto.a -o ideaofbenc
sh-2.00$ cat testdata
She should have died hereafter;
There would have been a time for such a word.
To-morrow, and to-morrow, and to-morrow,
Creeps in this petty pace from day to day
To the last syllable of recorded time,
And all our yesterdays have lighted fools
The way to dusty death. Out, out, brief candle!
Life's but a walking shadow, a poor player
That struts and frets his hour upon the stage
And then is heard no more: it is a tale
Told by an idiot, full of sound and fury,
Signifying nothing.
sh-2.00$ ideaofbenc testdata test1
sh-2.00$ wc testdata
        12        90       481 testdata
sh-2.00$ wc test1
         3         9       481 test1
sh-2.00$ ideaofbenc test1 test2
sh-2.00$ cat test2
She should have died hereafter;
There would have been a time for such a word.
To-morrow, and to-morrow, and to-morrow,
Creeps in this petty pace from day to day
To the last syllable of recorded time,
And all our yesterdays have lighted fools
The way to dusty death. Out, out, brief candle!
Life's but a walking shadow, a poor player
That struts and frets his hour upon the stage
And then is heard no more: it is a tale
Told by an idiot, full of sound and fury,
Signifying nothing.
sh-2.00$ wc test2
        12        90       481 test2
sh-2.00$ exit
exit

script done on Tue Sep 16 11:16:45 1997