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. When encrypting, it shifts each character in the plaintext by a number of characters defined by the key. It 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.

First, create a new empty project by selecting the Empty qmake Project template from the Other Project category. Next, add a main.cpp file and a new CaesarCipherDevice class derived from QIODevice. The basic interface of the class will accept an integer key and set ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.