Why are you complicating things so much?
#include <QtConcurrentMap>
#include <QStringList>
#include <QByteArray>
#include <QFile>
struct Decrypter {
result.reserve(f.size());
int keyIndex = 0;
char input;
char keyByte;
while(!f.atEnd()) {
f.getChar(&input);
keyByte = m_key.at(keyIndex);
keyIndex = (keyIndex+1) % m_key.size();
result.append( input ^ keyByte );
}
return result;
}
private:
};
int main() {
QStringList filesToDecrypt
= { "file1",
"file2",
"file3" };
QFuture<QByteArray> future = QtConcurrent::mapped(filesToDecrypt, Decrypter("abcdef"));
return 0;
}
#include <QtConcurrentMap>
#include <QStringList>
#include <QByteArray>
#include <QFile>
struct Decrypter {
Decrypter(const QByteArray &key) : m_key(key) {}
typedef QByteArray result_type;
QByteArray operator()(const QString &fileName) {
QFile f(fileName);
if(!f.open(QIODevice::ReadOnly)) return QByteArray();
QByteArray result;
result.reserve(f.size());
int keyIndex = 0;
char input;
char keyByte;
while(!f.atEnd()) {
f.getChar(&input);
keyByte = m_key.at(keyIndex);
keyIndex = (keyIndex+1) % m_key.size();
result.append( input ^ keyByte );
}
return result;
}
private:
QByteArray m_key;
};
int main() {
QStringList filesToDecrypt = { "file1", "file2", "file3" };
QFuture<QByteArray> future = QtConcurrent::mapped(filesToDecrypt, Decrypter("abcdef"));
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks