Skip to content

Resource · Guide or article

Caesar Cipher Algorithm

Short explainer of the Caesar shift cipher, where every letter moves a fixed number of places along the alphabet. A warm-up for character-shift string problems.

Reviewed

Open the original: Caesar Cipher Algorithm (opens the original site in a new tab)

Add to a roadmap

Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.

Source content: English

In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence. The transformation can be represented by aligning two alphabets; the cipher alphabet is the plain alphabet rotated left or right by some number of positions. For instance, here is a Caesar cipher using a left rotation of three places, equivalent to a right shift of 23 (the shift parameter is used as the key): When encrypting, a person looks up each letter of the message in the "plain" line and writes down the corresponding letter in the "cipher" line.

PrepKit overview

PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.

Suited to
The source does not state a level
Format
Reference

What it covers

  • Aligned plain and cipher alphabets for a left rotation of three, which equals a right shift of 23
  • Worked encryption of the pangram THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
  • Time and space complexity both given as O(|n|)

How to use it

PrepKit study advice, not a claim made by the source.

Write encrypt and decrypt functions that accept any shift, including negative values, and check that decrypting the README's ciphertext restores the sentence.

Scope and limitations

Very brief: there is no decryption walkthrough, nothing on breaking the cipher, and further reading is a single Wikipedia link.

Access and format

Free English README on GitHub in the MIT-licensed trekhleb/javascript-algorithms repository.

Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88

Evidence behind this overview
  • src/algorithms/cryptography/caesar-cipher/README.md

Pages that include this

Get the PrepKit newsletter

Optional. You don't need it to use PrepKit.

How we handle your email