Cryptography: Caesar Cipher Python

Aladdin Persson · Beginner ·⚡ Algorithms & Data Structures ·6y ago

Key Takeaways

The video demonstrates a simple cryptography algorithm, the Caesar Cipher, implemented in Python, covering the basics of encryption and decryption using a shift value.

Full Transcript

hello and welcome back to a little project of making the best cipher in the world just kidding but in this video we try to code the Caesar cipher in Python so let's get started and I've actually already started writing the alphabet I didn't want to mess that part up not on camera but so what we want to do after having our alphabet I included a space because it makes that messages more readable so what we want to do after every one we want to have a dictionary that map's each letter to a number and then we also want to have a mapping back so we can have a dictionary that map's a number to a letter one way we can do this is we create a letter to index want to make a dictionary and so this is one way of doing that we use for each in the alphabet we have a letter which is the range of the Len length of the alphabet so this will be 0 1 2 etc and so a for example would be mapped to 0 B would be mapped to 1 and that this is what the zip function does is that it maps a 2-0 etc and then we make a dictionary out of that now we need to have one more dictionary that map's the letter the index to a letter right this maps a letter to a index and essentially the same thing except ever now we want to do the reverse so it should be something like this and then what is it that we want to do well we want to have a function that encrypts and it should encrypt a message and it should do it with a shift that we could set a standard to make perhaps as we did in the last video that the shift should be 3 and then we want to also have a function of decrypt and it should decrypt a cipher ciphered text and also with a shift and they want to have a main function that perhaps runs runs these function so just a little skeleton of the code we want to write so in if we start with the encrypt function then we want to first have a so the cipher text is empty from the beginning or if you're just writing cipher then we want to for we want to go to each letter in our message so for letter in message then we want to first map that specific letter to a number then we use letter to index of that specific letter then we add a shift the shift that's specified in the input and then we take that modulus the length of our alphabet and we can call this the number or perhaps index we call this index and then what we want to do is that we want to call our index to letter of that specific index and then we wanted what we can do is that we can call this the shifted letter and then the cipher will be added that that shifted letter will be added to our cipher so shifted letter and then at the end we just want to return the cipher so for example if we have a message that is attack at noon and notice that we can write this because we included spaces in our alphabet then we can say that our encrypted message will be encrypt of the message and we don't have to write the shift since we use a shift of 3 but we can write it just to be clear and then we can say that we can just print the encrypted message and the code seems to be working and this so we can see at least at a becomes D makes sense and let's just make sense T becomes X yeah no way it should be at W all right I said I didn't want to mess this up on camera and I still messed it up i SUV W yeah this this should make sense yeah all right so we want to now after we've done that is that we want to run the decryption so decrypted start with a empty message empty string so for letter in our cipher text we now want to do essentially the exact same thing as we did previously right so we can just probably copy this know what we want to do is that we want to subtract this and that's that should be it so then we have a decrypted now we really turn a decrypted and some of the ultimate test let's see if we when we run the decrypt of our encrypted message we should get back the original message so a decrypted message and then let's just say print original message or string or mess it will actually it's just already a string so just plus message copies encrypted message and decrypted message all right let's hope that it works all right so it seems to be working original message attack at noon and then we get this and then the decrypted becomes again attack at noon so hopefully you were able to follow of that if you have any questions about the code or anything then please leave them below thank you so much for watching and I hope you have a great day

Original Description

In this video I go through a simple cryptography algorithm in Python. I try to explain everything in simple terms and make it beginner friendly! Github repository: https://github.com/AladdinPerzon/Algorithms-Collection-Python Check out my previous video on the Caesar cipher also if you have any questions about this algorithm.
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Aladdin Persson · Aladdin Persson · 16 of 60

1 computeCost.m Linear Regression Cost Function - Machine Learning
computeCost.m Linear Regression Cost Function - Machine Learning
Aladdin Persson
2 gradientDescent.m Gradient Descent Implementation -  Machine Learning
gradientDescent.m Gradient Descent Implementation - Machine Learning
Aladdin Persson
3 Neural Network from scratch - Part 1 (Standard Notation)
Neural Network from scratch - Part 1 (Standard Notation)
Aladdin Persson
4 Neural Network from scratch - Part 2 (Forward Propagation)
Neural Network from scratch - Part 2 (Forward Propagation)
Aladdin Persson
5 Neural Network from scratch - Part 3 (Backward Propagation)
Neural Network from scratch - Part 3 (Backward Propagation)
Aladdin Persson
6 Neural Network from scratch - Part 4 (With Python)
Neural Network from scratch - Part 4 (With Python)
Aladdin Persson
7 sigmoid.m - Programming Assignment 2 Machine Learning
sigmoid.m - Programming Assignment 2 Machine Learning
Aladdin Persson
8 costFunction.m - Programming Assignment 2 Machine Learning
costFunction.m - Programming Assignment 2 Machine Learning
Aladdin Persson
9 predict.m - Programming Assignment 2 Machine Learning
predict.m - Programming Assignment 2 Machine Learning
Aladdin Persson
10 costFunctionReg.m - Programming Assignment 2 Machine Learning
costFunctionReg.m - Programming Assignment 2 Machine Learning
Aladdin Persson
11 lrCostFunction.m - Programming Assignment 3 Machine Learning
lrCostFunction.m - Programming Assignment 3 Machine Learning
Aladdin Persson
12 oneVsAll.m - Programming Assignment 3 Machine Learning
oneVsAll.m - Programming Assignment 3 Machine Learning
Aladdin Persson
13 predictOneVsAll.m - Programming Assignment 3 Machine Learning
predictOneVsAll.m - Programming Assignment 3 Machine Learning
Aladdin Persson
14 predict.m - Programming Assignment 3 Machine Learning
predict.m - Programming Assignment 3 Machine Learning
Aladdin Persson
15 Caesar Cipher Encryption and Decryption with example
Caesar Cipher Encryption and Decryption with example
Aladdin Persson
Cryptography: Caesar Cipher Python
Cryptography: Caesar Cipher Python
Aladdin Persson
17 Vigenere Cipher Explained (with Example)
Vigenere Cipher Explained (with Example)
Aladdin Persson
18 Cryptography: Vigenere Cipher Python
Cryptography: Vigenere Cipher Python
Aladdin Persson
19 Hill Cipher Explained (with Example)
Hill Cipher Explained (with Example)
Aladdin Persson
20 Cryptography: Hill Cipher Python
Cryptography: Hill Cipher Python
Aladdin Persson
21 Interval Scheduling Greedy Algorithm: Python
Interval Scheduling Greedy Algorithm: Python
Aladdin Persson
22 Weighted Interval Scheduling Algorithm Explained
Weighted Interval Scheduling Algorithm Explained
Aladdin Persson
23 Weighted Interval Scheduling Python Code
Weighted Interval Scheduling Python Code
Aladdin Persson
24 Sequence Alignment | Needleman Wunsch Algorithm
Sequence Alignment | Needleman Wunsch Algorithm
Aladdin Persson
25 Sequence Alignment | Needleman Wunsch in Python
Sequence Alignment | Needleman Wunsch in Python
Aladdin Persson
26 Codility BinaryGap Python
Codility BinaryGap Python
Aladdin Persson
27 Codility CyclicRotation Python
Codility CyclicRotation Python
Aladdin Persson
28 Derivation Linear Regression with Gradient Descent
Derivation Linear Regression with Gradient Descent
Aladdin Persson
29 Linear Regression Gradient Descent From Scratch in Python
Linear Regression Gradient Descent From Scratch in Python
Aladdin Persson
30 Pytorch Neural Network example
Pytorch Neural Network example
Aladdin Persson
31 Pytorch CNN example (Convolutional Neural Network)
Pytorch CNN example (Convolutional Neural Network)
Aladdin Persson
32 Pytorch LeNet implementation from scratch
Pytorch LeNet implementation from scratch
Aladdin Persson
33 Pytorch VGG implementation from scratch
Pytorch VGG implementation from scratch
Aladdin Persson
34 Pytorch GoogLeNet / InceptionNet implementation from scratch
Pytorch GoogLeNet / InceptionNet implementation from scratch
Aladdin Persson
35 How to save and load models in Pytorch
How to save and load models in Pytorch
Aladdin Persson
36 How to build custom Datasets for Images in Pytorch
How to build custom Datasets for Images in Pytorch
Aladdin Persson
37 Pytorch Transfer Learning and Fine Tuning Tutorial
Pytorch Transfer Learning and Fine Tuning Tutorial
Aladdin Persson
38 Pytorch Data Augmentation using Torchvision
Pytorch Data Augmentation using Torchvision
Aladdin Persson
39 Pytorch Quick Tip: Weight Initialization
Pytorch Quick Tip: Weight Initialization
Aladdin Persson
40 Pytorch Quick Tip: Using a Learning Rate Scheduler
Pytorch Quick Tip: Using a Learning Rate Scheduler
Aladdin Persson
41 Pytorch ResNet implementation from Scratch
Pytorch ResNet implementation from Scratch
Aladdin Persson
42 Pytorch TensorBoard Tutorial
Pytorch TensorBoard Tutorial
Aladdin Persson
43 Pytorch DCGAN Tutorial (See description for updated video)
Pytorch DCGAN Tutorial (See description for updated video)
Aladdin Persson
44 Naive Bayes from Scratch - Machine Learning Python
Naive Bayes from Scratch - Machine Learning Python
Aladdin Persson
45 Spam Classifier using Naive Bayes in Python
Spam Classifier using Naive Bayes in Python
Aladdin Persson
46 K-Nearest Neighbor from scratch - Machine Learning Python
K-Nearest Neighbor from scratch - Machine Learning Python
Aladdin Persson
47 Linear Regression Normal Equation Python
Linear Regression Normal Equation Python
Aladdin Persson
48 SVM from Scratch - Machine Learning Python (Support Vector Machine)
SVM from Scratch - Machine Learning Python (Support Vector Machine)
Aladdin Persson
49 Neural Network from Scratch - Machine Learning Python
Neural Network from Scratch - Machine Learning Python
Aladdin Persson
50 Pytorch RNN example (Recurrent Neural Network)
Pytorch RNN example (Recurrent Neural Network)
Aladdin Persson
51 Pytorch Bidirectional LSTM example
Pytorch Bidirectional LSTM example
Aladdin Persson
52 Pytorch Text Generator with character level LSTM
Pytorch Text Generator with character level LSTM
Aladdin Persson
53 Logistic Regression from Scratch - Machine Learning Python
Logistic Regression from Scratch - Machine Learning Python
Aladdin Persson
54 K-Means Clustering from Scratch - Machine Learning Python
K-Means Clustering from Scratch - Machine Learning Python
Aladdin Persson
55 Pytorch Torchtext Tutorial 1: Custom Datasets and loading JSON/CSV/TSV files
Pytorch Torchtext Tutorial 1: Custom Datasets and loading JSON/CSV/TSV files
Aladdin Persson
56 Pytorch Torchtext Tutorial 2: Built in Datasets with Example
Pytorch Torchtext Tutorial 2: Built in Datasets with Example
Aladdin Persson
57 Pytorch Torchtext Tutorial 3: From Textfiles to Dataset
Pytorch Torchtext Tutorial 3: From Textfiles to Dataset
Aladdin Persson
58 Paper Review: Sequence to Sequence Learning with Neural Networks
Paper Review: Sequence to Sequence Learning with Neural Networks
Aladdin Persson
59 Pytorch Seq2Seq Tutorial for Machine Translation
Pytorch Seq2Seq Tutorial for Machine Translation
Aladdin Persson
60 Pytorch Seq2Seq with Attention for Machine Translation
Pytorch Seq2Seq with Attention for Machine Translation
Aladdin Persson

This video teaches the implementation of the Caesar Cipher in Python, covering encryption and decryption using a shift value. It provides a beginner-friendly introduction to cryptography and programming concepts.

Key Takeaways
  1. Create an alphabet mapping using a dictionary
  2. Implement the encryption function using a shift value
  3. Implement the decryption function by subtracting the shift value
  4. Test the encryption and decryption functions with a sample message
💡 The Caesar Cipher is a simple encryption technique that can be implemented using a shift value and alphabet mapping.

Related Reads

Up next
Webhooks & Callbacks For Beginners in Python
NeuralNine
Watch →