Python Beginner Project: Build a Caesar Cipher Encryption App

pixegami · Beginner ·🔐 Cybersecurity ·3y ago

Key Takeaways

The video demonstrates how to build a Caesar Cipher encryption app in Python, using the Caesar Cipher algorithm to shift each letter by a fixed number for encryption and decryption. The project utilizes ASCII codes, loops, and conditional statements to encrypt and decrypt messages.

Full Transcript

hi everyone welcome to the channel my name is Jack and in this video we're going to Learn Python by building a mini project that we can use to encrypt and decrypt messages using the Caesar Cipher algorithm the Caesar Cipher is named after the Roman Emperor Julius Caesar who encrypted his handwritten messages by shifting each of the letters by some amount so that if the messages were ever intercepted by his enemies they wouldn't be able to read them to decipher the message you can shift the letters back by the same amount to get the original message now by today's standard this is actually a very weak encryption algorithm because it can be cracked really easily however it's still a great first introductory step into the world of cryptography and cyber security which are really important subjects in the tech world the project itself is quite simple but we'll get to apply a lot of different techniques so it's perfect for beginners who want to Learn Python now I'm going to assume that you at least have python installed and already knows some of the basics but you're somebody who prefers to learn by getting Hands-On with a real project if you like the sound of that then let's get started today we're building a Caesar Cipher this is an encryption algorithm that works by shifting all the letters in a message by some fixed number for example consider the letters a b c d e if we shift them by 1 then a would become B and B would become C and so on eventually Z loops around to become a so by applying the cipher with a shift F1 the word cab becomes DBC and we can apply this to any message to encrypt it in cryptography terms the original unencrypted message is called plain text the encrypted message is called the ciphertext in this example we use the shift of 1 to encrypt the message if we change the shift for example to the number 12 then the ciphertext also changes and if we want to decipher the message back to normal we'll need to know this shift number so we can just move it back the other way you can think of this number as the key so how do we go about implementing this in Python well it turns out that computers actually have a special number for each letter of the alphabet and luckily for us they are in order for example the letter a is the number 65 and B is 66. this is a universally accepted standard and it's called ASCII codes you can look it up on Wikipedia the plan here is to use Python to convert each letter in our message to this ASCII code number and then we'll shift it by just adding the shift number and we'll convert that result number back into a letter so if we do that to all the letters in our message then we'll end up with an encrypted message anyway that's the plan now let's get started with the code let's open up our editor and create a new file I'm going to call this file Caesar cipher.py and I'm going to start by creating the message that I want to encrypt I also wanted to define the shift key that I want to encrypt the message with so these two lines create two variables one is called message and one is called shift and variables are things like you can think of them as placeholders for values that I can store some information in and refer to them and use them later and the two types of values I'm storing here well the first one is a string a string is like a sequence of characters things like Words sentences or even single letters would be a string the second type is a number in this case it's an integer so python makes a distinction between round numbers which we call integers and floating Point numbers which are like decimal numbers now that I have the data I want to work with let's figure out how to go through each of these letters one by one and then actually shift it by this index just so that we don't get lost I find it really helpful to write comments along the way so to write a comment in Python you just type the hash symbol here and then whatever you write on that line will be grayed out and you can read it as a developer but it doesn't have any effect on your code so here I want to go through each of the letters in the message and I'm writing this again for my own Clarity so when I read it I know what my program is doing to go through each character in the message we're going to Loop through it and this is how we write a loop in Python so if you have a variable that can be iterated upon iterate means you can go through some element of them one by one in this case we can iterate upon the string because each element is one of these characters so we if we do this for x and message each time we iterate X is going to be equal to one of these characters one by one until it reaches the end of the string and then in the scope of this statement which is one indentation level in we can do something with x and something we can do really basic is just to print it so the print function is a built-in function in Python and that would just make this variable show up in the terminal let's actually run this now and see what happens I've opened up my integrated terminal which is on a Windows that's control backtick or on a Mac that's command backtick and you can run your Python program by typing Python and then space and then you the name of your file that you created so in this case Caesar cipher.py and if we run it we see that each print statement is on a separate line so we're actually going through each of these and printing one character at a time so that's pretty good and I'm gonna constantly run this at each step in the development just so you see how the application changes as we work on it so I'm just going to clear my terminal and and then we can move on the first thing I want to do is convert this character to the ASCII code and python actually has an inbuilt function to help us do this the function is spelled ORD which I think stands for ordinal and it Returns the Unicode for that one character string so luckily in this case X is going to be a one character string by the way we don't have to name this x we can call it anything else we want and typically I like to use short variable names for things that are obvious but it's also really good to use descriptive variable names that help us understand what x actually is so in this case I'm just going to change that to char so that we know that this is a single character in this Loop and I'm going to create another variable to store this output which I'm going to call Char code so instead of printing just Char on its own I can print Char and then I'll put a comma here and also print the Char code let's run that again now in our print statement next to the letter we also get the ASCII number or the Unicode number for each character and now that we have this Char code we can just add this number the shift offset to that Char code and we'll get a new Char code which is the Caesar Cipher encrypted charcoal so let's do that so new charcoal equals charcoal plus shift and these are both integers so we can actually do a arithmetic on them let's print that out as well and so in our printed terminal you can now see the three characters the letter the original charcoal and the Caesar Cipher shifted Char code we now have to convert the new charcoal back into a string because it's a number right now again python has a helper function to let us do this and this time the function is CHR and then we'll just put in our new charcoal in there and we'll get the string again we'll need a new variable to store this so let's call it new chart equals Char new Char code log that out as well and now when we run it again we actually see the whole transformation of this letter so the letter e for example the charcoal is 101 we shift it by 7 so it becomes 108 and when we map that back to an alphabet uh it becomes the letter L now to finally get the full result of our encryption we need to add all of these characters back together to form the encrypted message to do that we can just create an empty string first and I'm going to call it result and it's just going to be double quotes and nothing in between because it's an empty string and each time I Loop through this I'm going to append this new chart to the empty string so the result string is going to become whatever the result was before plus the new character and now I'm just going to remove this print line and instead only print the result at each iteration so this time every time we go through a character in the message we should see the result getting built up slowly so you can see here it starts adding o and then o l and then the rest of the characters and we finally have the encrypted string as our output and I don't need this to be uh within this Loop anymore so I'm just going to take it out of the scope of the loop if I backspace it it's no longer indented on the level of the loop so when I run it again it's not going to print each time it's only going to print once okay so I think the Caesar Cipher is working at a very basic level but you could see that there's still some bugs for example we get some really weird characters here a couple of weird characters and this parentheses so that's because we actually also try to encrypt Unicode characters that are not letters like this comma the space and this exclamation mark so the first thing we want to do to fix that is to make this Loop ignore any character that isn't a part of the alphabet if it's not part of the alphabet we just want to add that to the result as it is so how do we do that it turns out that python also has a helper function that we can call on a string to check whether or not it's part of the alphabet so if we just do Char and then is Alpha this statement will return a Boolean a Boolean is a value that is either true or false that will tell us whether this is part of the alphabet so we can check if the character is part of the alphabet this is something called a condition statement and if it is we'll do all of this stuff so I'm going to indent that to make all of this code only execute in the scope of this condition only if this becomes true so let's clean that up a little bit and let's run that again and see what happens so now it works um you can see that it completely skips any character that isn't an alphabet but now the ciphertext result is shorter than the original string because we actually dropped the characters instead of just preserving them what if we wanted to preserve them so here the problem is that if the character that I'm looking through is not part of the alphabet I don't do anything to it this condition is going to be false and I just skip this part of the code and go through the next character that is why our exclamation mark and our space bar is dropped from the encrypted message and if that's not what we want we can add an else condition to the statement and have it do something else so we can do it like this and if the character is not part of the alphabet we can just add that character directly to the result without having to do all this stuff here so in this case I'm adding the original character not the new character there is no new character here and let's run that and see what happens so now the encrypted message actually preserves the non-alphabetical characters like the comma the space bar and the exclamation mark by the way we can actually make this line look a little bit nicer we don't have to write result equals result plus new chart there is a shortcut for this and we can write it like this instead so result plus equals new chart and it means the same thing it's just a little easier and cleaner to look at and python has many shortcuts like this and this is what we call in Python syntactic sugar it's just kind of shortcuts and little abbreviations that make things hopefully easier to write and read okay so running it again I have yet another problem which is one of my characters is still translating weirdly to this um carrot sign and that's because this character is actually the W character but when I shift it by seven it actually it goes past the letter Z and it sort of lands in these weird symbol characters here W is character number 87 and Zed is number 90. so when it goes plus seven it actually goes all the way to 94 which is the carrot symbol that's not what we want though we want it so that when it reaches Zed it kind of Loops back around goes through a and starts counting from there and that's the proper Caesar Cipher behavior that we want so how do we go about doing that let's just take a really simple approach first so let's say that we get an offset a new charcoal that is greater than 90. well in this case we know that it's gone beyond Zed and we have to sort of loop it back over to a so we could do that by just subtracting 26 which is the range of the alphabet here and that kind of brings it back uh lets it loop around let's just try that really quickly and and see if it works so here if the new charcoal is greater than 90 which is the charcoal of the letter Z we're going to subtract 26 and hopefully that will make it loop around okay and running this again I see that my w is fixed but funky things start happening to some of my other characters well the reason is it turns out that all the lowercase characters have a different Char code than the uppercase ones and all of the lowercase ones are actually greater than 90. so this 26 shift is actually applying to all of the lowercase letters whether or not it's beyond the actual lowercase z instead of trying to solve that problem directly we can actually work around it because if the lowercase characters are causing us trouble we can just convert the whole message to uppercase first and then perform the Caesar Cipher that's probably the simpler solution so we don't have to solve the same problem twice so let's go ahead with that first and to do that we'll use another python input function called upper and this will if you can see here this will return a copy of the string converted to the uppercase so now instead of looping through the original message We're looping through the uppercase version only and now when I run this the Caesar Cipher looks correct at this point our application works but we can still do things to make it a little bit nicer for instance uh these things that we're using here they're called Magic numbers they're basically numbers that we use as part of the code without any kind of logical explanation about why they're there so to fix that it's usually better to Define these as a variable as well we can call it a constant variable so it's something that we don't ever change but we just it's easier to read so this number 90 it's actually what it means is it's the last character index it's the ASCII character code of the letter z so let's actually give that a descriptive name so now I'm calling this last Char code and this is a variable as well but um by python convention when I write it with all caps it usually indicates to the reader that this is a constant variable and I'm not expecting it to change and it's better than using this number magically inside the actual code itself so let's go replace this and then we'll do the same for uh the 26 here and if I run it the program should still work the same except that this logic is just a little bit more readable and more maintainable now what if I wanted to reuse this code maybe as part of another application or maybe I just want to encrypt a lot of different messages at once or even if I want to reverse the shift and use it to decrypt messages to do that I'll need to organize this code into a logical unit that I can reuse and that it has an interface that's easy to understand so in Python we're going to do that by putting this code into a function and a function in Python is basically a block of code that we we give it a name and then anytime we call that function we can invoke this entire piece of code with different parameters different inputs and get the result out of that so that sounds exactly like what I need to do here to create a python and function we write def which stands for Define and then we write the name of the function in this case I'm going to name the function Caesar shift and this is how you create a function in Python this function does nothing because there's no actual logic in there yet and we also need to have these parentheses to tell python what arguments it can accept so the arguments are like input to a function now in this case the arguments we have are the message and the shift and so those are going to be the arguments for our function those are the only things we care about that could possibly change every time that we run this but everything else the structure even these constants we want it to stay the same that's why only these things are going to be the arguments with that I can actually just move this entire block of code into the function and again to make it within the scope of this function I have to indent it okay so now I have this function what happens if I run my program well actually there's nothing being output or printed out that's because even though I've created the function I actually haven't used it yet so let's go ahead and use it to use a function we just write the name of the function and open these brackets up and if I run it like this it's going to fail because I'm not passing it any arguments when it's expecting two arguments and I've actually defined my arguments here message and shift because I have this function there's no need for me to even store these as variables anymore I could just delete these entirely and then write it in here instead and if I run the python script again it should work see now I'm back at my same result except that now I have this nice function and I can reuse it to call the same piece of code with different inputs so for example I'll do something like ABCDE and then maybe I'll change the shape to that so here I've called it different ways and I can even use it to decode a Caesar Cipher so for example let's copy this uh ciphertext over here and let's call Caesar shift again except this time we'll pass in the cipher text and this time we'll pass in the negative value of the key so we're shifting it back to the um to the plain text form see if that works and this actually fails I mean you can see that some of the letters are shifted properly but again we have some problems with the characters that are at the boundary of the alphabet that's because our condition here only checks if it's bigger than Z it doesn't check if it's less than the first charcoal which is a so we can add that condition as well and see if we can fix that bug and we have to also Define first Char code which if you look in the ASCII table the charcoal for a is 65. and now when I run this again you can see that the decryption works properly because now I'm clamping uh the shift both ways by the way um just as a nice thing so that we don't actually have to look up the first and the last Char code and have these magic numbers again appear in a constants like this we just actually could call the ORD function with a here and then call it with Z there uh this way we don't even have to look up the table because you know we know that this is going to give us the value we want and the same with range we don't even have to hard code this anymore we could do it with the same we could do it with the arithmetic here except that with this we actually have to add one to it because when we do this the index start counts as zero so it counts the first entry as zero instead of one so it will end up being 25 it would just do this on its own to get it to 26 we do have to add one but now let's just save that and run it and yes everything still works except that everything is also more logical and more readable which is actually a really important part of development as well especially if you want to work in a team now for the last part of this project I want to turn this into an interactive application so that when I run it I want to prompt the user to type in a message and then I want to run Caesar shift on that message how do we do that so first let's get rid of all of this stuff we don't need it anymore we'll have our Caesar shift function here I'm just going to collapse that so it's easier to read to capture user input in Python 3 we use an inbuilt function called input whatever we put in here is going to be the prompt that the user sees so I'm just going to write message to encrypt and I'll put a colon there and if I run this again I'm going to see that it prompts me with this message to encrypt and I can type you know whatever I want I might enter that nothing happens because we're not doing anything with this input yet so the first thing we have to do is actually store this message and I'm going to call this user message here just not to confuse it with this variable name again I would recommend avoiding reusing variable names as possible even if it means the same thing just add some kind of like prefix to it it's going to save you a lot of trouble debugging because most of the bugs I see at the beginner level is you know when you reuse variable names and you're not aware of it and it just makes your application do unexpected things so now we have the user message we'll run Caesar shift on that user message and we'll just hard code the number seven for now and see if that works first okay so now I can type in a message and it will run a Caesar shift on it with the key of seven but let's say that I want to also pass in the key here so let's try that again I'm going to call this user shift key just to make it clear that this is the value coming from the user [Music] okay so let's run that again and I get an error because it says supported operand types for plus and string it's really helpful to learn how to read error messages in Python this one it means that you can't plus together two different data types ins and a string we if we open this we see that we use the shift and then we try to add to the Char code the Char code we know is an integer because that hasn't changed but what has changed is this shift value that we're passing to it why has that changed because now we're passing user shift key as the input instead of the number seven but something that I didn't tell you was that when you call input whatever we get from the result of this is always going to be a string even if it's a number like this and this string 7 is different from the number seven because a string seven would be like actually you know it would be in the quotes and you can add that together with a real number like 12 or 13 or whatever it just doesn't know how to do that so we actually have to convert this string back into an in it's really easy to in Python you just type int and then you wrap that around and that will convert whatever string this is if it can convert it if it's not something totally crazy it can convert it that to an INT and now this will be an INT as well so try that again and this should work okay so that fixes the problem for us and the application seems to work pretty nicely now congratulations you've completed the project if you have any feedback or if there's anything you struggled with or if there is anything was unclear then please please let me know in the comments below it's my goal to make coding accessible and fun for everyone who wants to learn so your feedback would also help a lot of other people if you enjoyed this project and you want to try something a little bit more challenging then I recommend you check out this video where I show you how to make a Wordle puzzle game in Python otherwise thank you for watching see you next time

Original Description

In this video, we're going to learn Python by building a mini project that can encrypt and decrypt messages using the Caesar Cipher algorithm. 🔗 Code: https://github.com/pixegami/python-caesar-cipher The Caesar Cipher is named after the Roman Emperor, Julius Ceasar, who encrypted handwritten messages by shifting each of the letters so that his enemies couldn't read them if they were intercepted. This project itself is quite simple, but we'll get to apply a lot of different techniques, so it's perfect for beginners who want to learn Python. 00:00 Introduction 01:09 What is the Caesar cipher? 02:43 Looping through the message 05:45 Shifting the ASCII code 09:28 Using if/else conditions 12:26 Fixing edge cases 16:06 Creating a function in Python 20:12 How to get user input in Python 24:39 Wrapping up #python #pixegami
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from pixegami · pixegami · 25 of 60

1 How to Build an AWS Lambda Function in Python in Just 7 Minutes!
How to Build an AWS Lambda Function in Python in Just 7 Minutes!
pixegami
2 AWS CDK Tutorial: Deploy a Python Lambda Function using AWS
AWS CDK Tutorial: Deploy a Python Lambda Function using AWS
pixegami
3 I used GPT-3 to Write Poetry • Is AI the Future of Creative Writing?
I used GPT-3 to Write Poetry • Is AI the Future of Creative Writing?
pixegami
4 Create NFT Generative Art with Python! (Full Tutorial)
Create NFT Generative Art with Python! (Full Tutorial)
pixegami
5 Build an AI-driven SaaS Application: FULLSTACK Tutorial with Python, React, and AWS
Build an AI-driven SaaS Application: FULLSTACK Tutorial with Python, React, and AWS
pixegami
6 NextJS and TailwindCSS: How to Build a Portfolio Site from Scratch
NextJS and TailwindCSS: How to Build a Portfolio Site from Scratch
pixegami
7 Python Web Scraping Tutorial • Step by Step Beginner's Guide
Python Web Scraping Tutorial • Step by Step Beginner's Guide
pixegami
8 Build Wordle in Python • Word Game Python Project for Beginners
Build Wordle in Python • Word Game Python Project for Beginners
pixegami
9 How to create 1000+ unique NFT-style images (like Cryptopunk) | Python Tutorial
How to create 1000+ unique NFT-style images (like Cryptopunk) | Python Tutorial
pixegami
10 Top 10 Python Modules 2022
Top 10 Python Modules 2022
pixegami
11 How to Send SMS Text Messages with Python & Twilio - Quick and Simple!
How to Send SMS Text Messages with Python & Twilio - Quick and Simple!
pixegami
12 How To Write Unit Tests in Python • Pytest Tutorial
How To Write Unit Tests in Python • Pytest Tutorial
pixegami
13 How to Style Your React Landing Page with Tailwind CSS
How to Style Your React Landing Page with Tailwind CSS
pixegami
14 FastAPI Python Tutorial - Learn How to Build a REST API
FastAPI Python Tutorial - Learn How to Build a REST API
pixegami
15 How to Deploy FastAPI on AWS EC2: Quick and Easy Steps!
How to Deploy FastAPI on AWS EC2: Quick and Easy Steps!
pixegami
16 PyScript • How to run Python in a browser
PyScript • How to run Python in a browser
pixegami
17 My Custom Ubuntu Linux Terminal with Themes and Plug-ins 💻
My Custom Ubuntu Linux Terminal with Themes and Plug-ins 💻
pixegami
18 Deploy FastAPI on AWS Lambda ⚡ Serverless hosting!
Deploy FastAPI on AWS Lambda ⚡ Serverless hosting!
pixegami
19 NextJS Firebase Auth Tutorial • How to Authenticate Users for Your App
NextJS Firebase Auth Tutorial • How to Authenticate Users for Your App
pixegami
20 AWS Lambda Python functions with a database (DynamoDB)
AWS Lambda Python functions with a database (DynamoDB)
pixegami
21 How To Build a CRUD (TO-DO) App on AWS using FastAPI and Python
How To Build a CRUD (TO-DO) App on AWS using FastAPI and Python
pixegami
22 How to Make a Discord Bot with Python
How to Make a Discord Bot with Python
pixegami
23 How To Use GitHub Copilot (with Python Examples)
How To Use GitHub Copilot (with Python Examples)
pixegami
24 PyTest • REST API Integration Testing with Python
PyTest • REST API Integration Testing with Python
pixegami
Python Beginner Project: Build a Caesar Cipher Encryption App
Python Beginner Project: Build a Caesar Cipher Encryption App
pixegami
26 Decorators in Python: How to Write Your Own Custom Decorators
Decorators in Python: How to Write Your Own Custom Decorators
pixegami
27 NextJS 13 Tutorial: Create a Static Blog from Markdown Files
NextJS 13 Tutorial: Create a Static Blog from Markdown Files
pixegami
28 Exploring ChatGPT for Coding and Business ✨ 8 Real Examples!
Exploring ChatGPT for Coding and Business ✨ 8 Real Examples!
pixegami
29 How I Would Learn Python (if I had to start over) • A Roadmap for 2023
How I Would Learn Python (if I had to start over) • A Roadmap for 2023
pixegami
30 Build an AI Pokemon Generator with Python and Midjourney
Build an AI Pokemon Generator with Python and Midjourney
pixegami
31 Why You Should Learn Python in 2023 (as your first programming language)
Why You Should Learn Python in 2023 (as your first programming language)
pixegami
32 ChatGPI API in Python ✨ How to Build a Custom AI Chat App
ChatGPI API in Python ✨ How to Build a Custom AI Chat App
pixegami
33 Learn Python • #1 Installation and Setup • Get Started With Python!
Learn Python • #1 Installation and Setup • Get Started With Python!
pixegami
34 Learn Python • #2 Variables and Data Types • Python's Building Blocks
Learn Python • #2 Variables and Data Types • Python's Building Blocks
pixegami
35 Learn Python • #3 Operators • Add, Subtract and More...
Learn Python • #3 Operators • Add, Subtract and More...
pixegami
36 Learn Python • #4 Conditions • If / Else Statements
Learn Python • #4 Conditions • If / Else Statements
pixegami
37 Learn Python • #5 Lists • Storing Collections of Data
Learn Python • #5 Lists • Storing Collections of Data
pixegami
38 Learn Python • #6 Loops • How to Repeat Code Execution
Learn Python • #6 Loops • How to Repeat Code Execution
pixegami
39 Learn Python • #7 Dictionaries • The Most Useful Data Structure?
Learn Python • #7 Dictionaries • The Most Useful Data Structure?
pixegami
40 Learn Python • #8 Tuples and Sets • More Ways To Store Data!
Learn Python • #8 Tuples and Sets • More Ways To Store Data!
pixegami
41 Learn Python • #9 Functions • Python's Most Important Concept?
Learn Python • #9 Functions • Python's Most Important Concept?
pixegami
42 Learn Python • #10 User Input • 4 Ways To Get Input From Your User
Learn Python • #10 User Input • 4 Ways To Get Input From Your User
pixegami
43 Learn Python • #11 Classes • Create and Use Classes in Python
Learn Python • #11 Classes • Create and Use Classes in Python
pixegami
44 Learn Python • #12 Final Project • Build an Expense Tracking App!
Learn Python • #12 Final Project • Build an Expense Tracking App!
pixegami
45 Stripe & Firebase Tutorial • Add Payments To Your NextJS App
Stripe & Firebase Tutorial • Add Payments To Your NextJS App
pixegami
46 How To Use GitHub Actions • Automate Your AWS Deployments
How To Use GitHub Actions • Automate Your AWS Deployments
pixegami
47 How to Run a Python Docker Image on AWS Lambda
How to Run a Python Docker Image on AWS Lambda
pixegami
48 My MacOS Terminal Setup for HIGH Productivity
My MacOS Terminal Setup for HIGH Productivity
pixegami
49 Host a Python Discord Bot on AWS Lambda (Free and Easy)
Host a Python Discord Bot on AWS Lambda (Free and Easy)
pixegami
50 Python FastAPI Tutorial: Build a REST API in 15 Minutes
Python FastAPI Tutorial: Build a REST API in 15 Minutes
pixegami
51 Pydantic Tutorial • Solving Python's Biggest Problem
Pydantic Tutorial • Solving Python's Biggest Problem
pixegami
52 How to Get Started with AWS • Crash Course
How to Get Started with AWS • Crash Course
pixegami
53 Python Requests Tutorial: HTTP Requests and Web Scraping
Python Requests Tutorial: HTTP Requests and Web Scraping
pixegami
54 Amazon Bedrock Tutorial: Generative AI on AWS
Amazon Bedrock Tutorial: Generative AI on AWS
pixegami
55 How to Publish a Python Package to PyPI (pip)
How to Publish a Python Package to PyPI (pip)
pixegami
56 Langchain: The BEST Library For Building AI Apps In Python?
Langchain: The BEST Library For Building AI Apps In Python?
pixegami
57 RAG + Langchain Python Project: Easy AI/Chat For Your Docs
RAG + Langchain Python Project: Easy AI/Chat For Your Docs
pixegami
58 Python Dataclasses: Here's 7 Ways It Will Improve Your Code
Python Dataclasses: Here's 7 Ways It Will Improve Your Code
pixegami
59 Build a Custom AI RPG Game with OpenAI GPTs
Build a Custom AI RPG Game with OpenAI GPTs
pixegami
60 Create a Custom AI Assistant + API in 10 Mins
Create a Custom AI Assistant + API in 10 Mins
pixegami

This video teaches you how to build a Caesar Cipher encryption app in Python, covering the basics of encryption and decryption, and utilizing ASCII codes and loops. By following the steps, you'll understand how to shift each letter by a fixed number for encryption and decryption, and apply cybersecurity concepts to AI projects.

Key Takeaways
  1. Create a new file and name it Caesar cipher.py
  2. Define the message and shift variables
  3. Use ASCII codes to shift letters by adding the shift number
  4. Encrypt and decrypt messages by shifting letters by a fixed number
  5. Use a loop to iterate over each character in the message
  6. Use the ORD function to get the ASCII code of a character
  7. Add the shift offset to the ASCII code to get the Caesar Cipher encrypted character
  8. Use the CHR function to convert a number back to a character
  9. Capture user input using the input function in Python 3
  10. Convert user input to an integer using the int() function
💡 The Caesar Cipher algorithm is a simple encryption technique that shifts each letter by a fixed number, and can be implemented using ASCII codes and loops in Python.

Related AI Lessons

Why the EC-Council 312-41 Practice Test Is Essential for Certification Success
Boost your EC-Council 312-41 certification chances with practice tests, essential for assessing knowledge and understanding of exam objectives
Dev.to AI
Short-lived, scoped, challenge-based: designing safer service tokens for agents
Design safer service tokens for agents by limiting their scope and lifetime to reduce the impact of credential leaks
Dev.to · Steve Emmerich
BioShocking: How AI Browsers Were Tricked Into Handing Over Your Passwords
Learn how AI browsers can be tricked into handing over passwords using adversarial framing techniques and why it matters for cybersecurity
Dev.to · Cor E
Cyber Hygiene: The Everyday Habits That Protect Your Digital Life
Learn everyday habits to protect your digital life from cyber threats and data breaches
Medium · Cybersecurity

Chapters (9)

Introduction
1:09 What is the Caesar cipher?
2:43 Looping through the message
5:45 Shifting the ASCII code
9:28 Using if/else conditions
12:26 Fixing edge cases
16:06 Creating a function in Python
20:12 How to get user input in Python
24:39 Wrapping up
Up next
Cyber security threats @FameWorldEducationalHub #cybersecurity #threats #shorts #ytshorts
FAME WORLD EDUCATIONAL HUB
Watch →