Breaking Codes with Genetic Algorithms
Genetic Algorithms in Elixir — by Sean Moriarity (57 / 101)
👈 Chapter 7 Preventing Premature Convergence | TOC | Understanding Mutation 👉
Imagine that you’ve been tasked with protecting the integrity of your firm’s data. One day, a hacker manages to get on your system and encrypts all of your data before demanding a ransom to decrypt it.
Luckily, the hacker decided to use a basic XOR cipher with what appears to be a 64-bit key. That means, if you’re able to determine the key, you’ll be able to easily apply the cipher in reverse to restore all of your data.
XOR ciphers are reversible ciphers that work by applying a bitwise XOR with a key on every character in a string. Unicode characters are represented with 16-bits. Given a key and a string, you can encrypt the string by applying an XOR of every character with your key. The following image demonstrates this process:
To decrypt an XOR cipher, you can apply the same process in reverse — if you know the key. XOR is the inverse of itself, so you can apply the cipher on encrypted text with the same key to obtain the decrypted version. The following image illustrates this: