Compare commits

...

2 Commits

Author SHA1 Message Date
110f298bbf aufgabe-3 classy 2026-06-06 16:24:39 +02:00
7624caaf6c aufgabe_3 2026-06-06 15:57:28 +02:00
2 changed files with 9 additions and 37 deletions

View File

@ -1,14 +1,3 @@
# Assignment 2 - Caesar Cipher
This is my code for the OOP homework. I chose the Caesar Cipher Helper.
- **Link:** https://www.codewars.com/kata/526d42b6526963598d0004db
### How it works:
- The `CaesarCipher` class takes a `shift` number.
- `encode` changes text to uppercase and moves letters forward. It uses `% 26` so letters stay in the A-Z alphabet.
- `decode` moves letters backward to fix the text.
- Spaces and punctuation do not change.
### Tools:
I set up black and ruff with pre-commit hooks. They check and fix my code format before every commit.
The `Animal` base class sets up the `name` attribute.
- The `Cat` class inherits from `Animal` so it automatically gets the name property.
- I added the `speak` method to the `Cat` class to make it return a str.

View File

@ -1,25 +1,8 @@
class CaesarCipher:
class Animal:
def __init__(self, name:str):
self.name=name
def __init__(self, shift: int):
self.shift = shift
self.alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
class Cat(Animal):
def encode(self, st: str) -> str:
result = []
for char in st.upper():
if char in self.alphabet:
new_index = (self.alphabet.index(char) + self.shift) % 26
result.append(self.alphabet[new_index])
else:
result.append(char)
return "".join(result)
def decode(self, st: str) -> str:
result = []
for char in st.upper():
if char in self.alphabet:
new_index = (self.alphabet.index(char) - self.shift) % 26
result.append(self.alphabet[new_index])
else:
result.append(char)
return "".join(result)
def speak(self) -> str:
return f"{self.name} meows."