Simple Caesar Encryption in Python

Sdílet
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

Komentáře • 88

  • @simon3431
    @simon3431 Před 3 lety +25

    dude.. i advise you to start makin'/workin' on Udemy. i would like to buy a Python course from you!

  • @whipyyy
    @whipyyy Před 3 lety +4

    You are so good and the channel is underated ;( you deserve a lot,thc for the content!!!

    • @van4195
      @van4195 Před rokem +1

      i wish i deserved a lot of thc for my content

  • @subhankarchakraborty3866
    @subhankarchakraborty3866 Před 3 lety +1

    Awesome encription brother.
    Thank you soo much.

  • @StephenEhrlichPhotos
    @StephenEhrlichPhotos Před 3 lety

    So many tips such as nesting functions in functions and string methods. Very helpful.

  • @tibish
    @tibish Před 3 lety +1

    You just got yourself a new subscriber 🤠

  • @judeleon8485
    @judeleon8485 Před 3 lety +1

    I'm looking forward to more topics on encryption, and digital signatures

  • @pitman0727
    @pitman0727 Před 3 lety +2

    A+ tutorials, training products and content creation.

  • @ronneljayag4018
    @ronneljayag4018 Před 2 lety

    That was amazing im gonna give you a subscribe for that!

  • @neelaynaman6481
    @neelaynaman6481 Před 3 lety +4

    I'm in 1st year of high school and your videos are so much awesome, amazing, and informative. Love from INDIA❤

  • @nooblogs2408
    @nooblogs2408 Před 3 lety +1

    Thanks for the information bro

  • @emperorj4783
    @emperorj4783 Před 2 lety

    He is the best python tutorial guy!

  • @hasaranger9845
    @hasaranger9845 Před 3 lety +2

    I was just thinking of creating a gui that encrypts a message, when your notification came in

  • @luislima7212
    @luislima7212 Před 3 lety +1

    Awesome video bro! I have done a script that makes the same, but I didn't use the string module. I did it "manually" 😂😂

  • @thelover2392
    @thelover2392 Před 2 lety

    great job pro keep Going : )

  • @ryszard83
    @ryszard83 Před 3 lety +20

    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!

  • @SimonTiger
    @SimonTiger Před 3 lety +2

    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.

    • @NeuralNine
      @NeuralNine  Před 3 lety +2

      Yes true! This is why the Caesar cipher is not really useful in a real scenario.

    • @gustavgans9082
      @gustavgans9082 Před 2 lety

      @@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.

  • @Jarqueivies
    @Jarqueivies Před 2 lety

    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?

  • @visuss1
    @visuss1 Před 3 lety

    Thank you !

  • @Plu3e
    @Plu3e Před 3 lety

    That's was cool.

  • @sudarshandas4270
    @sudarshandas4270 Před 2 lety +2

    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)

  • @tatiannalindsay8602
    @tatiannalindsay8602 Před rokem

    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?

  • @wfra9486
    @wfra9486 Před 9 měsíci

    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?

  • @s.aravindh6227
    @s.aravindh6227 Před 3 lety +3

    Super information bro

  • @souravbhardwaj8551
    @souravbhardwaj8551 Před 3 lety +1

    You are fire bro

  • @Silent_Chief
    @Silent_Chief Před 2 lety

    Hello do you use atom or similar ? That 'play' buttons like standalone mode is usefull i see

  • @mr_wavey07
    @mr_wavey07 Před 2 lety +1

    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!

  • @_zelatrix
    @_zelatrix Před 3 lety +13

    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.

    • @yes-ls1rf
      @yes-ls1rf Před rokem

      You don't make sense.Caesar cipher means shifting the letters.It's actually better than original.

    • @_zelatrix
      @_zelatrix Před rokem

      @@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.

    • @evantyler7727
      @evantyler7727 Před rokem

      @@_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.

  • @mati2103
    @mati2103 Před 3 lety +3

    Thanks ;)

  • @winterchillzv2188
    @winterchillzv2188 Před 2 lety

    What program do you use in this video?

  • @jadenyjteng5740
    @jadenyjteng5740 Před 2 lety +2

    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

  • @theempath508
    @theempath508 Před rokem

    Is there a function/method that would print all 26 possible shifts?

  • @victoralmeida5528
    @victoralmeida5528 Před 3 lety +4

    I did this one in C, it was a lot harder

  • @danasgudaitis370
    @danasgudaitis370 Před 3 lety +8

    Ok but how do you decrypt it? Could you make a short video telling us how to?

    • @mrrage2265
      @mrrage2265 Před 2 lety

      shift it back

    • @BlizzardWind99
      @BlizzardWind99 Před 2 lety

      @@mrrage2265 basically in encryption you need to + but in decrypt you just need to -

  • @__3093
    @__3093 Před 3 lety +2

    finally :D

  • @Girtharmstrong69
    @Girtharmstrong69 Před 2 lety

    This is how you create a new language

  • @harrybestfriend5282
    @harrybestfriend5282 Před 3 lety +1

    when there are comments before anyone has had time to watch the video

  • @MadChristoph
    @MadChristoph Před rokem

    What about brute_force?

  • @GameDev_Master
    @GameDev_Master Před 2 lety

    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

  • @kxkl_
    @kxkl_ Před 3 lety +1

    luv u

  • @vadim969
    @vadim969 Před rokem

    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?

    • @LA-my8jg
      @LA-my8jg Před rokem

      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

  • @costantinoanea682
    @costantinoanea682 Před 3 lety

    can you build a vigenere encryption pleaseeee

  • @Kablan_6161
    @Kablan_6161 Před rokem

    i do not understand line 9 to 12. Can anyone explain these lines for me pls?

  • @shitzu4429
    @shitzu4429 Před 2 lety

    But what is the "string"?

  • @pythonicd1239
    @pythonicd1239 Před 3 lety

    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?

    • @pythonicd1239
      @pythonicd1239 Před 3 lety

      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

    • @pythonicd1239
      @pythonicd1239 Před 3 lety

      There seems to be a _string tho

  • @gopalnarayanan5585
    @gopalnarayanan5585 Před 3 lety

    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))

  • @alialavizadeh2775
    @alialavizadeh2775 Před 3 lety +1

    please zoom in your videos it is really hard to see

  • @user-qq4gv8mz4s
    @user-qq4gv8mz4s Před 3 lety

    شفرة قيصر

  • @manoramapatra8091
    @manoramapatra8091 Před 3 lety +2

    Yea I'm 2nd

  • @shikderal-amin5644
    @shikderal-amin5644 Před 2 lety

    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)

    • @Silent_Chief
      @Silent_Chief Před 2 lety

      Do you find solution ? I have maybe some clue

  • @mrboyban
    @mrboyban Před 2 lety

    HA HA, when you suddenly realise that POW

  • @yes-ds3yp
    @yes-ds3yp Před rokem

    shifted_alphabet is not defined

  • @mhsamhsa5456
    @mhsamhsa5456 Před rokem

    can you gave me the code

  • @marshallhickey3746
    @marshallhickey3746 Před 3 lety +1

    Can u do a video about what’s on the dark web cause my bro got hacked on it

    • @NeuralNine
      @NeuralNine  Před 3 lety +1

      no more videos of that kind on this channel. Take a look at my Twitter statement.

  • @semeremanchawi1228
    @semeremanchawi1228 Před 3 lety

    This gay can hack NASA using his mind

    • @tips1483
      @tips1483 Před 3 lety +2

      I think you meant `guy`

  • @anonymousninja986
    @anonymousninja986 Před 3 lety +1

    Why have you removed your trojan making video. 😭😭😭
    Bring it back plzzz🙏🙏🙏🙏

    • @isomane7911
      @isomane7911 Před 3 lety +2

      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

    • @NeuralNine
      @NeuralNine  Před 3 lety +2

      @@isomane7911 good summary. Full explanation on Twitter

    • @isomane7911
      @isomane7911 Před 3 lety

      @@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

    • @NeuralNine
      @NeuralNine  Před 3 lety

      @@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.

    • @Kriz_Griffin
      @Kriz_Griffin Před 3 lety +1

      I was going to study that after my exams, too bad it's removed...🥺

  • @cz_czan
    @cz_czan Před 3 lety +1

    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 :-)

    • @NeuralNine
      @NeuralNine  Před 3 lety

      thanks :)

    • @RahulSahni_-gj8ez
      @RahulSahni_-gj8ez Před 3 lety

      Thnks man for suggesting the book👍😅
      I also want to learn crypto

    • @cz_czan
      @cz_czan Před 3 lety

      @@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 :-)

  • @suawdthedude8583
    @suawdthedude8583 Před 2 lety

    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)