Compare commits

..

No commits in common. "aufgabe-3" and "aufgabe-oop" have entirely different histories.

2 changed files with 32 additions and 15 deletions

View File

@ -1,10 +1,14 @@
# Assignment 3 - Adam & Eve Subclasses
# Assignment 2 - Caesar Cipher
This is my code for the Task 3 assignment using inheritance.
This is my code for the OOP homework. I chose the Caesar Cipher Helper.
- **Link:** https://www.codewars.com/kata/547274e24481cfc469000416
- **Link:** https://www.codewars.com/kata/526d42b6526963598d0004db
### How it works:
- I created a base class called `Human`.
- `Man` and `Woman` are subclasses that inherit everything from `Human`.
- The `God` function creates and returns an array with the first man and woman.
- 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.

View File

@ -1,12 +1,25 @@
class Human:
class CaesarCipher:
def __init__(self, name: str):
self.name = name
class Man(Human):
pass
def __init__(self, shift: int):
self.shift = shift
self.alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
class Woman(Human):
pass
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 God():
return [Man("Adam"), Woman("Eve")]
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)