Simple Caesar Encryption in Python
Vložit
- čas přidán 27. 07. 2024
- In this video we build a simple Caesar cipher in Python.
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
💻 The Algorithm Bible Book: www.neuralnine.com/books/
🐍 The Python Bible Book: www.neuralnine.com/books/
👕 Programming Merch: www.neuralnine.com/shop
💻 Exclusive Content 💻
👥 Patreon: / neuralnine
🌐 Social Media & Contact 🌐
📱 Website: www.neuralnine.com/
📷 Instagram: / neuralnine
🐦 Twitter: / neuralnine
🤵 LinkedIn: / neuralnine
📁 GitHub: github.com/NeuralNine
🎵 Outro Music From: www.bensound.com/ - Věda a technologie
dude.. i advise you to start makin'/workin' on Udemy. i would like to buy a Python course from you!
You are so good and the channel is underated ;( you deserve a lot,thc for the content!!!
i wish i deserved a lot of thc for my content
Awesome encription brother.
Thank you soo much.
So many tips such as nesting functions in functions and string methods. Very helpful.
You just got yourself a new subscriber 🤠
I'm looking forward to more topics on encryption, and digital signatures
A+ tutorials, training products and content creation.
That was amazing im gonna give you a subscribe for that!
I'm in 1st year of high school and your videos are so much awesome, amazing, and informative. Love from INDIA❤
Thanks for the information bro
He is the best python tutorial guy!
I was just thinking of creating a gui that encrypts a message, when your notification came in
Awesome video bro! I have done a script that makes the same, but I didn't use the string module. I did it "manually" 😂😂
great job pro keep Going : )
Thank you for what you do! Your films are very interesting and I teach a lot. I have been learning to program in Python for several months, I am currently 12 years old :)
By the way, I come from Poland, so even there it is helpful!
If you really want to get fancy, you can use "frequency analysis" to decode the message:
Let's assume that the message is in English for this example.
1. Look at the distribution of how often the letters come up.
2. The most common letter in English is the letter E.
3. So, at least if the message is long enough, one of the most common letters in the encrypted message should map to E.
4. So we can get the shift by simply looking at the distance between E and the most common letter, because that would map the most common letter back to E.
Yes true! This is why the Caesar cipher is not really useful in a real scenario.
@@NeuralNine You can make it useful by applying different shifts in different cases. For example, add 7 when i is even and subtract 3 when it's odd. If you make up more complex rules, it would be very difficult if not impossible to brute-force it.
Hi, I'm having trouble with digits. I've added "string.digits" to 'alphabets' at the end where we print using the shift_alphabet function, but nothing happens with the digits, any help?
Thank you !
That's was cool.
5:31 I particularly don't understand what is going on with the 26-80 thing, I have seen other blog tutorials too where this something is subtracted from 26 in order to get back to the original value from an encrypted value; but I found an easy solution. Just use negative numbers. Put shift = -5 and it will work fine to give the original result back. (But thanks to the tutorial tho)
Suppose I want to convert the space as well? Or in stead of jumping from w to a, I enter a range of special characters?
Thank you for making this video. I found the decryption was fine for string.lowercase but when I tried it with string.printable the results started to get a bit inconsistent. Any ideas?
Super information bro
thanks :)
You are fire bro
thanks :D
Hello do you use atom or similar ? That 'play' buttons like standalone mode is usefull i see
Hello There!
Is there a way to decrypt the encrypted word/sentence?
And is there a way for the user to choose how many shift they want?
I would appreciate if anyone can answer me!
I just want to point out that you're not actually implementing a "Caesar" cipher. You're using a shift value of 7, so you're actually implementing a ROT-7 cipher. Caesar cipher is specifically when the shift value is 3. All other values of the shift produce rotation ciphers, but not a Caesar cipher.
You don't make sense.Caesar cipher means shifting the letters.It's actually better than original.
@@yes-ls1rf I've always been taught that a shift of 3 letters is a Caesar cipher, which is a special case of the general family of rotation ciphers.
@@_zelatrix While Julius Caesar himself did use a shift of 3 letters, Augustus Caesar only used a shift of one. The shifting of the letters in this way is noted as the Caesar Cipher but can also be noted as a ROT-7 or ROT-5. Neither is technically incorrect. The script itself is a Caesar Cipher as it can be changed to rotate a different amount so it could be 3 it could be 12 etc, so the script isnt a rot-7 cipher he just happens to only demonstrate a shift of 7.
Thanks ;)
thanks for watching :)
What program do you use in this video?
Thanks for the video but can you make a decryption video on your latest codes fro caesar cipher, cause im having difficulties decrypting it using python
Is there a function/method that would print all 26 possible shifts?
I did this one in C, it was a lot harder
Yeah C is a different level ^^
Ok but how do you decrypt it? Could you make a short video telling us how to?
shift it back
@@mrrage2265 basically in encryption you need to + but in decrypt you just need to -
finally :D
More is coming! :)
This is how you create a new language
when there are comments before anyone has had time to watch the video
hahahaha best community ^^
What about brute_force?
Now the hard part: learning how it works. Like i get the big picture but if i want to change something on my own im stuck
luv u
^^
After coding it myself I saw your video and learned It can be done a lot shorter with your methods, Thank you!
Just one thing - Is it just me or does the shift is limited to 25, and not above it?
try shift %= 26 - that should solve the problem where the shift gets limited to 25 and reverting back to the normal alphabet when the shift is higher than 25
can you build a vigenere encryption pleaseeee
i do not understand line 9 to 12. Can anyone explain these lines for me pls?
But what is the "string"?
I'm using pycharm it says 'no module named string' , though it seems to be working fine when I tried to import it in Pydroid in my phone. Can anyone help?
I tried pip install but it says
ERROR: Could not find a version that satisfies the requirement string (from versions: none) ERROR: No matching distribution found for string
There seems to be a _string tho
def caesarCipher(s, k):
ans = ''
for char in s:
if char.isupper(): ans += chr((ord(char)+k-65) % 26+65)
elif char.islower(): ans += chr((ord(char)+k-97) % 26+97)
else: ans += char
return ans
s = input().strip() # Input String
k = int(input().strip()) # key
print(caesarCipher(s, k))
please zoom in your videos it is really hard to see
شفرة قيصر
Yea I'm 2nd
:D
why it's not working:
text = input("Enter the text:")
cipher = ''
for char in text:
if not char.isalpha():
continue
char = char.upper()
code = ord(char) + 1
if char > ord('Z'):
code = ord('A')
cipher = chr(code)
print(cipher)
Do you find solution ? I have maybe some clue
HA HA, when you suddenly realise that POW
shifted_alphabet is not defined
can you gave me the code
Can u do a video about what’s on the dark web cause my bro got hacked on it
no more videos of that kind on this channel. Take a look at my Twitter statement.
This gay can hack NASA using his mind
I think you meant `guy`
Why have you removed your trojan making video. 😭😭😭
Bring it back plzzz🙏🙏🙏🙏
youtube deleted them because in their opinion videos violated the rules by showing people how to create trojan for example
theyre available on patreon where you can see them for 5$ and he doesnt want to share them without possibility of earning money
@@isomane7911 good summary. Full explanation on Twitter
@@NeuralNine not necessarily happy with the fact that i can no longer watch them for free (or technically free since watching ads is a payment) but imo it's mostly youtube to blame and I also somewhat admire when people are open about the fact that it's business instead of trying to act like they're doing stuff out of goodness of their heart
@@isomane7911 Yeah it sucks. But I can also openly and transparently tell you that I would make more money, more subscribers etc. if it was on CZcams. I am always for Win / Win situations where the audience can watch everything for free and I can still grow the business. However, the best content (machine learning etc.) will still be on CZcams for free and the quality will increase over time.
I was going to study that after my exams, too bad it's removed...🥺
Man, what a coincidence, i just started learning cryptography from " Serious Cryptography, a practical introduction" and wrote the Caesar and Vigenere encryptions in python a couple days ago! Thanks for your videos, they are amazing :-)
thanks :)
Thnks man for suggesting the book👍😅
I also want to learn crypto
@@RahulSahni_-gj8ez It's a good book, but when i started reading i realised that if you want to be expert in crypto, you need to advance your mathematical understanding to a relatively high level. The book is not made particularly for software developers, but it also has a lot for them, including code examples. When all the math started around the time the one time padlock was introduced, i had to read the same pages about 10 times in the span of a couple days to get a vague understanding of what the author meant :P And the book is considered to be light-weight on math jargon (!!!). Looks like i forgot quite a bit of math. Crypto is very difficult, but that makes an engineer with crypto knowledge much valued :-)
Why doesn't it shift the punctuations and numbers for me?
import string
def caesar(text,shift,alphabets):
'''Algorithm to encrypt password'''
global shifted_alphabets,table,final_shifted_alphabets, final_alphabets
def shift_alphabets(alphabets):
return alphabets[shift:] + alphabets[:shift]
shifted_alphabets = tuple(map(shift_alphabets, alphabets))
final_alphabets = ''.join(alphabets)
final_shifted_alphabets = ''.join(shifted_alphabets)
table = str.maketrans(final_alphabets, final_shifted_alphabets)
return text.translate(table)
plain_text = "This is a new test..."
shift_interval = 7
encrypt = caesar(plain_text,shift_interval ,[string.ascii_lowercase, string.ascii_uppercase, string.punctuation])
print(encrypt)
decrypt = caesar(encrypt,26-shift_interval ,[string.ascii_lowercase, string.ascii_uppercase, string.punctuation])
print(decrypt)