DEV Community

Maximilian Torggler
Maximilian Torggler

Posted on

2 2

Micropost: Encrypted messages to my future self

Two years ago, when I was still in school, I wrote a letter to my future self (it was a school project). It contained a few encrypted messages, so that my present me could do a fun exercise now.

The message was encrypted using Caesar Cipher, which just increases every letter by a specified number, producing unreadable text (I mean, you could also decrypt this in your head by just looking at the the text for some time, but this way it's more fun).

Turns out out it was a really fun 10 min coding challenge. I should do more of them as I often tend to forget how much fun programming actually is and always was.

Maybe this was the most important message to my future self: Never stop enjoy coding.

Here is the code needed to decrypt a Caesar encrypted message using brute force.

function caesar(str, increment) {
const letters = 'abcdefghijklmnopqrstuvwxyz';
return str
.toLowerCase()
.split('')
.map(c => {
const index = letters.indexOf(c);
if (index === -1) return c;
let newIndex = index + increment;
if (newIndex < 0) {
newIndex = letters.length - 1;
} else if (newIndex >= letters.length) {
newIndex = newIndex- letters.length;
}
return letters[newIndex];
})
.join('');
}
function allCaesar(str) {
for (let i = 0; i < 26; i++) {
console.log(caesar(str, i));
}
}
allCaesar('pbqr vf neg. Nanepul fubhyq gnxr bire gur jbeyq. wninfpevcg sbe gur shgher?')
view raw julius.js hosted with ❤ by GitHub

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay