Time for action – implementing a device to encrypt data
Let's implement a really simple device that encrypts or decrypts the data that is streamed through it using a very simple algorithm—the Caesar cipher. What it does is that when encrypting, it shifts each character in the plaintext by a number of characters defined by the key and does the reverse when decrypting. Thus, if the key is 2
and the plaintext character is a
, the ciphertext becomes c
. Decrypting z
with the key 4
will yield the value v
.
We will start by creating a new empty project and adding a class derived from QIODevice
. The basic interface of the class is going to accept an integer key and set an underlying device that serves as the source or destination of data. This is all simple coding that you should already understand, so it shouldn't need any extra explanation, as shown:
class CaesarCipherDevice : public QIODevice { Q_OBJECT Q_PROPERTY(int key READ key WRITE setKey) public: explicit CaesarCipherDevice(QObject...