1
/******************************************************************************
3
* cipherfil - SWFilter descendant to decipher a module
5
* Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
6
* CrossWire Bible Society
10
* This program is free software; you can redistribute it and/or modify it
11
* under the terms of the GNU General Public License as published by the
12
* Free Software Foundation version 2.
14
* This program is distributed in the hope that it will be useful, but
15
* WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
* General Public License for more details.
23
#include <cipherfil.h>
29
CipherFilter::CipherFilter(const char *key) {
30
cipher = new SWCipher((unsigned char *)key);
34
CipherFilter::~CipherFilter() {
39
SWCipher *CipherFilter::getCipher() {
44
char CipherFilter::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
45
if (text.length() > 2) { //check if it's large enough to substract 2 in the next step.
46
unsigned long len = text.length();
47
if (!key) { // hack, using key to determine encipher, or decipher
48
cipher->cipherBuf(&len, text.getRawData()); //set buffer to enciphered text
49
memcpy(text.getRawData(), cipher->Buf(), len);
50
// text = cipher->Buf(); //get the deciphered buffer
52
else if ((unsigned long)key == 1) {
53
cipher->Buf(text.getRawData(), len);
54
memcpy(text.getRawData(), cipher->cipherBuf(&len), len);
55
// text = cipher->cipherBuf(&len);