aboutsummaryrefslogtreecommitdiffstats
path: root/utilities/ciphertest.cpp
blob: 26d3495a16cca32253905adaffc47470b797318d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <ctype.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>

#ifndef __GNUC__
#include <io.h>
#else
#include <unistd.h>
#endif

#include <swcipher.h>
#include <versekey.h>
#include <rawverse.h>
#ifndef NO_SWORD_NAMESPACE
using sword::SWCipher;
using sword::VerseKey;
using sword::RawVerse;
#endif

int main(int argc, char **argv) {
	SWCipher *zobj;
	VerseKey key;
	RawVerse *rawdrv;
	long offset;
	unsigned short size;
	unsigned int len;
	char *tmpbuf;
	
	if (argc != 3) {
		fprintf(stderr, "usage: %s <datapath> \"<key>\"\n", argv[0]);
		exit(1);
	}

	rawdrv = new RawVerse(argv[1]);
	zobj = new SWCipher((unsigned char *)argv[2]);

#ifndef O_BINARY
#define O_BINARY 0
#endif


	printf("\n");

	key.AutoNormalize(0);
	key.Headings(1);
	for (key.Index(0); (!key.Error()); key++) {
		rawdrv->findoffset(key.Testament(), key.Index(), &offset, &size);
		tmpbuf = (char *) calloc(size + 2, 1);
		rawdrv->readtext(key.Testament(), offset, size + 2, tmpbuf);
		len = size;
		zobj->cipherBuf(&len, tmpbuf);
		printf("%s\n", zobj->Buf());
				free(tmpbuf);
	}
	delete zobj;
	return 0;
}