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