 Hey, what's going on everybody? Audio testing. That's all Hey, what's going on everybody? My name is John Hammond. Welcome back to another YouTube video and tutorial and just a little bit ago I was looking through my logic book like the logic puzzles thing and I saw something look like a Caesar cypher So I was like, okay, sure I can do that. I figured I want to write my own Caesar cypher So I looked up, you know, easy ways to do a Caesar cypher in Python If you don't know what the Caesar cypher is, I mean you can obviously do a little bit of research on your own Really it just shifts one letter in the alphabet or at least every single letter in the alphabet to a different position By a number So you can see that that kind of demonstration or at least that picture Shows it pretty well over there So you can get a plain text and all it's doing is just shifting the position of one letter in the alphabet To a different position and the cypher text that comes out looks pretty crazy So it's very very easy to reverse obviously because you just have to figure out what that key is and then That kind of thing so anyway, I want to look up how I could do this really easily in Python so I looked up Caesar cypher in Python and There was some stuff like I found a lot of stuff on it But it all looked like it was writing a whole lot more code that it needed to actually write at least I thought this could be done pretty easily and pretty pretty simply in Python Like I saw an 8-minute video. I had to do this thing on YouTube So I feared there's got to be way that's easy thought about well All it really is it's like shifting letters and letters in a string or like you could have a letter being alphabet in Python And although that's really just an array All assuming is shifting it so I looked up ways to shift a list or an array in Python and this guy Responded there's the DQ or deck or whatever this is in the collections module and looks like it's Totally meant to be able to do that that has a rotate function that allows you to shift an array Just like that and wraps it really easily in Python, so I figured okay. I could totally put that together with some stuff So I started a poke at it. Here we go in idle. I imported collections and From that I worked with this DEQ thing So right now it has nothing in it, but if I were to you if I actually take a look at its documentation, sorry Can be an array pretty much that's you can append to it. You can clear it you can remove and reverse and obviously rotate So it looks like just exactly an array Or a list so I could obviously add stuff to it Then a and b that kind of thing and I'd be able to rotate it, right? Rotate by one and now it's shifted. It's just like that. So if I gave it the whole alphabet ASCII uppercase And I said I wanted a deck of that whole thing Sorry should be collections Now I have all of it and I can rotate Just like I did before by one and I get the whole thing rotated So it gives us to us though in this like interesting deck Format, but I wanted that as a list or at least a list, right? So I Can take the list of that and that gives me to be as a list. That's awesome But I wanted that as a string So I took the list of the string of a but that just took a String with the list like the braces and the commas and everything in it That's not what I wanted. I wanted to be a string. So I had to to Join it with an empty string. Oh Had an extra parentheses there So now I have a full rotated uppercase string and I can like put that together with the rotate and Function like we had done before and I can put it together with the string.translate function to actually Translate one alphabet to this new alphabet rotated to any certain position So we could write that really easily. Let's do it. If I get some blind text open Create a new script call mine Caesar cypher dot pi Add my shebang line and Let's just define a function that can do this for us. I'll call mine Caesar and We're gonna need the string to rotate by Rotate string and we're gonna need a number to rotate by So let's import this stuff. We need we need obviously the string Library to get all of those letters and we need collections So now we can actually create those uppercase strings that we wanted and since the number to rotate by is now a variable We can make this whatever we want. We could just have upper be collections dot deck of string dot ASCII upper case Right The pep8 center wants two lines for a new function. So I'll add that there and Now we'll do the same thing with lower Right because we want to be able to rotate lower case letters as well And now we'll rotate both of these upper dot rotate by the number to rotate by we'll do the same thing for lower and Now let's actually convert these to a string just like we had done before we can say upper equals The list form of upper so we converted it and now we'll actually make that a string by joining with empty string Right. We'll do the same thing for lower Now well all we have to do we can actually print these out I'll show you that it works just fine for us If I run Caesar Since I'm just demonstrating you don't actually have to pass in a string here But if I pass in zero it gives us a rotated uppercase by zero If I rotated it by one now it rotates it just like that we rotate it by negative two Rotates it just like that etc etc So easy easy these these strings are working the way we want them to now all we have to do is actually make that Translation with the string that we're working with so our rotate string We can go ahead and translate If you've never seen that function We'll do a little bit of research for you Python string translate looks like You can translate Certain values to something else, but you have to use this make trans function it will allow you to Actually put these all together in a proper table that the translate function can work with So if we did rotate string dot translate string dot make trans By dawn string make trans. Let's take a look at what that actually is Return to translation table suitable for passing into translate that maps each character from the from and to Arguments that are passed into it and then must have the same like well since we're working with the whole alphabet That works just fine for us right now. We can use make trans with our original alphabet string that ASCII uppercase and our new translated out uppercase variables and We've done this now with just the uppercase letters, but we're gonna have to do it again with the lowercase variables So if I do a Dot translate if I just copy what we have so far and I just change it to use lowercase It will now use lower and Now we can simply run Caesar We'll print out what Caesar returns us This is too easy Without being shifted now once we shifted it it changes it same thing by shifting it again and again and again So what we can do at this point is actually brute force the entire thing if we were given a set Caesar cipher And just hand it to us for I in range length of string that ASCII uppercase so the whole length of the alphabet We can print out Caesar. Let's just say our Our string can you pull? This is too easy Let's just print the current iteration we're on right now Caesar and just a little bar to divide it and then our string Let's fix that pet page centered and Then I just rotate it by all of these and now we've literally just gone through every single iteration of This is too easy string with our Caesar cipher and all is is one simple function That's like literally probably ten lines of code. It literally says in sublime text right now That's just ten lines of code. We didn't do any disgusting plus or minus all on our own We just let Python kind of handle it in the background. So there it is Thanks for watching guys real simple But kind of an interesting way to translate our string and make trans and rotate around the whole alphabet really easily So thanks for watching Now you have a whole Caesar cipher brute-forcer and you can multiply or I'm sorry Supply whatever offset you want to and create your own Caesar ciphers are really easy. Thanks guys Adios