Simple RNN Deciphers Code

Kat He
The Startup
Published in
7 min readDec 6, 2020

--

Table of Contents

  1. Overview
  2. Pipeline
  3. Tokenization
  4. Padding
  5. Define RNN
  6. Postprocessing
  7. Output at Every Step
  8. Conclusion

Overview

In this article, we will define a simple RNN to decrypt a Caesar Cipher. If you’re not familiar with RNNs, take a look at RNN Numerical Walkthrough + Code.

Caesar Cipher

A Caesar Cipher is a cipher that encodes sentences by replacing the letters by other letters shifted by a fixed size. For example, a Caesar Cipher with a left shift value of 3 will result in the following:

Input:    ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher: DEFGHIJKLMNOPQRSTUVWXYZABC

Notice that there is a 1-to-1 mapping for every character, where every input letter maps to the letter below it. Because of this property, we will use a character-level RNN for this cipher, although word-level RNNs may be more common in practice.

Why use an RNN?

A Caesar Cipher can be solved as a multiclass classification problem using a fully-connected feedforward neural network since each letter X maps to its cipher value Y. However, an…

--

--

Kat He
The Startup

Software engineer who enjoys learning about anything new, whether that be about machine learning, swe, or miscellaneous facts about the universe.