This project is part of The Odin Project curriculum. It implements a Caesar Cipher, a simple encryption technique where each letter in a string is shifted a certain number of places down the alphabet.
For example:
Original: Hello
Shift: 5
Encrypted: Mjqqt
Non-letter characters like spaces, punctuation, and numbers are left unchanged.
- Encrypts both uppercase and lowercase letters
- Handles wrap-around (e.g., "z" → "a")
- Preserves non-alphabetic characters
- Written in Ruby using basic string and ASCII manipulation
- Loop through each character in the input string.
- Check if the character is a letter.
- Determine if it’s uppercase or lowercase to use the correct alphabet base (
Aora). - Convert the letter to its alphabet position (0–25).
- Add the shift amount and wrap around using modulo 26.
- Convert the shifted position back to a letter.
- If the character is not a letter, keep it unchanged.
- Return the new encrypted string.
# Call the Caesar cipher method with a string and a shift value
puts caesar_cipher("Hello, World!", 5)
# Output: Mjqqt, Btwqi!- Working with ASCII codes using
.ordand.chr - Using modulo arithmetic to handle wrap-around
- Handling uppercase and lowercase letters separately
- Preserving non-letter characters
- Structuring a method in Ruby with clean loops and conditional logic