Caesar Cipher | Python Class example

preview_player
Показать описание
#CaesarCipher #Python

I use The Caesar Cipher as an example of how to use a Class. More interesting (to me anyway) is the find method, and the process of how to convert a character to it's index, add or subtract from it's index and then convert back. Python is just a language, the concept/design of what the program does is the most important part here...

No point knowing every phrase, and being fluent in a foreign language if you go around asking for a Helicopter Sandwich with Cheese is there?

Apologies if it's not quite as comedy as normal, guess we're all a bit subdued right now.

Nvertheless, KBO, and stay tuned, there may be a part 2 to this real soon, plus more great shit.

Don't forget to subscribe.

See you around yeah?
Dr fkin Pi

Check out the Minimalist online python IDE :

Рекомендации по теме
Комментарии
Автор

Hi Dr Pi, here're a couple of notes:


1. It's a nice program to implement in BRAINF*CK, btw ROT13 has it's classical BRAINF*CK implementation. You heard about BRAINF*CK programming language, didn't you)


2. One of ideas behind OOP is encapsulation. It's good that you're encapsulating the encrypt method within the class but you also have lots of global variables outside of your class which ruins all the beuaty of the OOP approach, so here're some fixes:
- you can init variables in the inner class field if they are static, e.g.

class DrPiChannel:
oop_playlists = [
]

def get_info(self):
print('Channel URL:', self.channel_url)
print('OOP Playlist:', self.oop_playlist)


- OR you can init variables dynamically within the __init__(self) method, e.g.


class DrPiChannel:
def __init__(self, channel_url, oop_playlist):
self.channel_url = channel_url
self.oop_playlist = oop_playlist


and then to pass these variables to the class constructor you need to say:

oop_playlists = [
]



- OR you can init data within the constructor. e.g.

class DrPiChannel:
def __init__(self, channel_url, oop_playlist):
self.oop_playlist = [
]


The core gist of encapsulation is to manage all the data/methods related to a particular thing within the single class, the idea of encapsulation is not only logical grouping of related data but also granting the access to that thing, e.g. in the last example self.channel_url and self.oop_playlist can be changed only from within a DrPiChannel class instance (python has some inner class fields(variables) access managing on top of encapsulation principle, don't remember how exactly to limit it to class only methods, probably via "self.__var__ = 0" enclosing variable into double underscores, not sure, need to check out the docs)


Overall I LIKED this video, you're doing really great. And sorry for this annoying OOP lecture. I'm self tought and may explain things in a non-standard manner, but I tried to bring the gist.

monkey_see_monkey_do