How to encrypt messages (Caesar cipher) - C Programming

Sdílet
Vložit
  • čas přidán 9. 05. 2020
  • Going over a coding problem which requires us to encrypt text using a Caesar cipher, and solving it with the help of the C programming language.
    Please Like & Subscribe if you found this interesting.
    Looking forward to your comments below.
    Code: github.com/BudacaB/yt/tree/ma...
    Caesar cipher: en.wikipedia.org/wiki/Caesar_...
    #cprogramming #cprogrammingtutorial #cprogrammingforbeginners #programming #coding #developer #howto #tutorial #cs #bogdanbudaca
  • Věda a technologie

Komentáře • 45

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

    If you enjoyed the video and what I am doing on this channel, consider buying me a warm cup of coffee ☕❤️
    www.paypal.com/donate?hosted_button_id=R8EXVLT5HFBYE

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

    Awesome video, please keep doing more videos like this one!!

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

    Thanks for ur clear n straightforward approach, much easier to understand.

  • @LucasSilva-mg1nt
    @LucasSilva-mg1nt Před 3 lety +2

    Excelent explanation! Very clear on your thoughts! It was very helpful!

  • @tobalaba
    @tobalaba Před 4 lety +2

    Thanks, man, you are very clear.

  • @osmanyobregon805
    @osmanyobregon805 Před rokem

    Muy buena tu forma de explicar,no entiendo como alguien tan genial tiene tan poco reconocimiento,te deseo éxitos y muchas gracias por la explicación :)

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

    I am so grateful!!! May lord bless you mr. Bogdan : )

    • @abeermoeed2256
      @abeermoeed2256 Před 3 lety

      but i have a doubt, what if the user enters 'x' as a key, so the atoi converts it to an int value 0...so keeping that in mind conversion of key to int shouldnt be done before we validate the key. am i right? please help :(

    • @BogdanBudaca
      @BogdanBudaca  Před 3 lety

      Cheers, Abeer

    • @BogdanBudaca
      @BogdanBudaca  Před 3 lety

      Yes, you are right, it would be better to check if the key is made of digits first, I didn't know that atoi returns 0 if it can't convert. Thank you for pointing it out

  • @UGH_ZEREF3431
    @UGH_ZEREF3431 Před rokem

    thank you sir

  • @green-coder
    @green-coder Před 3 lety +1

    thanks sir i appreciate your efforts

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

    How to Implement Caesar cipher using programming language C, It should
    include the functions for both encryption and decryption. Includes comments to explain
    the important steps in the algorithm

    • @vincentarasaratnam4742
      @vincentarasaratnam4742 Před 3 lety

      can you please clear this question to me?

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

      Hi Vincent, might try and do a video for decryption as well soon, thank you for the idea, haven't really looked into it yet

    • @vincentarasaratnam4742
      @vincentarasaratnam4742 Před 3 lety

      @@BogdanBudaca thankyou try it soon because I want to know this answer

  • @paulahoha8475
    @paulahoha8475 Před 2 lety

    Thanks a lot for this video, it was really helpful and learned a lot!
    Just one thing I didn't really get, why do we have to subtract and add 65 and 97 when we are applying the formula? Could you please point to some more detailed explanation?

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

      Thank you, glad you liked it. It might help testing for an upper edge, say Z is 90 in ASCII. The trick is that having 26 letters in the alphabet, we want our new value, with the key, to land in the same range. So if we deduct 65 from 90 to take it to the 0-26 range, then add say a key of 3, we get 28. If we add back the 65 now, we'd get 93 for ASCII. That would give us ']', instead of circling back to a letter, this is where the modulo 26 comes in. So basically this is a way to circle back to letters for the upper edge letters, or a big key; hope this makes some sense. Cheers

  • @alibe4582
    @alibe4582 Před 2 lety

    please in this part
    // check validity of the key
    for (int i = 0; i < strlen(argv[1]); i++)
    {
    if (isdigit(argv[1][i]))
    {
    valid_key = true;
    he gives
    [Error] Initial 'for' loop declarations are only allowed in C99 or C11 mode

    • @BogdanBudaca
      @BogdanBudaca  Před 2 lety

      Hey there, please google your error, stackoverflow should be the first result, with a fix 🤙

  • @winnieip9851
    @winnieip9851 Před 4 lety +2

    1 question : the purpose of
    fgets(input, sizeof(input), stdin);
    How this differs with get string ? Thanks

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

      They serve the same purpose, getting string input, but get_string() is provided only by Harvard's cs50.h library to be a bit more friendly.
      Outside of that environment you might look at fgets()
      man.cs50.io/3/get_string
      www.geeksforgeeks.org/fgets-gets-c-language/

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

      Thanks for ur replies. I better understand now

  • @emilym1029
    @emilym1029 Před 2 lety

    How would I incorporate opening an existing file and writing the results to a new file before the offset?

    • @BogdanBudaca
      @BogdanBudaca  Před 2 lety

      Hi, if you're on Linux for example it's pretty easy with redirection, pass the key, input from a file and output to some other file, e.g. ./caesar [key] < [input.txt] > [output.txt].
      Hope this is what you mean, you could also tweak the code to include some file reading / writing capabilities and you could pass the input file as an argument, this could help www.programiz.com/c-programming/c-file-input-output

  • @yousefali652
    @yousefali652 Před 2 lety

    why we use return 1 ????????????

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

    I don't believe this works properly if the user inputs a negative integer for their key. Any suggestions?

    • @BogdanBudaca
      @BogdanBudaca  Před 3 lety

      Hi and thank you, yup that wasn't in the scope of the exercise, I think you could mitigate it in the arguments check, or in some other way you see fit.

  • @winnieip9851
    @winnieip9851 Před 4 lety +1

    1 more : difference between
    Return 0;
    Return 1;
    When to use which ? Thanks

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

      By convention, when a program terminates successfully, it returns 0; anything other than 0, including 1, means there's an error and that could be the error code (returned also with an error description)

  • @saaraluthra5034
    @saaraluthra5034 Před 3 lety

    Why is it saying "called object type 'bool' is not a function or function pointer" for me?

    • @BogdanBudaca
      @BogdanBudaca  Před 3 lety

      Are you trying to call a variable of type 'bool' as a function? Found this on Google: stackoverflow.com/questions/19733090/error-called-object-type-int-is-not-a-function-or-function-pointer

  • @TheXpdf
    @TheXpdf Před 3 lety

    This wouldn't work if the key was -100, can someone explain why?

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

      It has to do with the isdigit() function which does the checking, it can't receive a '-' character

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

    which os is that

  • @andreidumitrascu5041
    @andreidumitrascu5041 Před 4 lety

    ‘Scuse me Mr. Bald friendly Guy, Hey There, can you do some simple, run of the mill, basic of the basic stuff, like what is a { and what program are you using, and btw why do you have that piercing?

    • @BogdanBudaca
      @BogdanBudaca  Před 4 lety

      Hi Andrei, thank you for the suggestion, I might be looking at going over basic notions in a video
      The piercing is just a personal thing :)

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

    but how to decript? text

    • @BogdanBudaca
      @BogdanBudaca  Před 3 lety

      Oh that might be a good idea for a vid, thank you