diff --git a/Caesar_Cipher/Vignere_README.txt b/Caesar_Cipher/Vignere_README.txt new file mode 100644 index 00000000..6b354a02 --- /dev/null +++ b/Caesar_Cipher/Vignere_README.txt @@ -0,0 +1,60 @@ + + + + +# Vigenère Cipher: Classical Text Encryption + +
+
+
+## 🛠️ Description
+
+This script implements the **Vigenère Cipher**, a classic polyalphabetic substitution encryption technique. It accepts a keyword from the user to encode and decode messages. The same keyword must be used to decrypt the output, making it a lightweight reversible encryption tool. This is a great intro project for learning about ciphers and key-based text transformations.
+
+The script demonstrates:
+1. A `VigenereCipher` class with methods to encrypt and decrypt alphabetic strings
+2. Character-level transformation based on a repeating keyword
+3. Custom `transform()` logic that handles both encryption and decryption
+
+Feel free to enhance it with non-alphabet support, file-based encryption, or use it inside a larger pipeline.
+
+## ⚙️ Languages or Frameworks Used
+
+- Python 3.x standard library only
+- No external packages required
+
+## 🌟 How to run
+
+To execute the script, run the following in your terminal:
+
+```bash
+python vigenere_cipher.py
+```
+
+When prompted:
+- Enter a **keyword** to serve as the encryption key
+- Enter the plaintext you'd like to encrypt
+- The script will output the encrypted text and decrypt it back immediately
+
+Use `CTRL + C` to exit at any point.
+
+## 📺 Demo
+
+An example prompt might look like:
+
+```
+Enter encryption keyword: lemon
+Enter text to encrypt: hello world
+Encrypted text: siprb xbpqe
+Decrypted back: hello world
+```
+
+
+
+## 🤖 Author
+
+Script by Dr. rer. nat. Nenad Balaneskovic.
+
+Nenad Balaneskovic → [GitHub Profile](https://github.com/NenadBalaneskovic)
+
+Feel free to contribute your own enhancements or port this into other encryption schemes!
\ No newline at end of file
diff --git a/Caesar_Cipher/vignere_cipher.py b/Caesar_Cipher/vignere_cipher.py
new file mode 100644
index 00000000..6d5b7b8e
--- /dev/null
+++ b/Caesar_Cipher/vignere_cipher.py
@@ -0,0 +1,38 @@
+class VigenereCipher:
+ def __init__(self, keyword: str):
+ self.keyword = keyword.lower()
+ self.alphabet = 'abcdefghijklmnopqrstuvwxyz'
+
+ def shift_char(self, c, key_c, encode=True):
+ if c not in self.alphabet:
+ return c
+ shift = self.alphabet.index(key_c)
+ if not encode:
+ shift = -shift
+ return self.alphabet[(self.alphabet.index(c) + shift) % 26]
+
+ def transform(self, text: str, encode=True):
+ text = text.lower()
+ result = []
+ key_len = len(self.keyword)
+ for i, c in enumerate(text):
+ key_c = self.keyword[i % key_len]
+ result.append(self.shift_char(c, key_c, encode))
+ return ''.join(result)
+
+ def encrypt(self, text: str) -> str:
+ return self.transform(text, True)
+
+ def decrypt(self, text: str) -> str:
+ return self.transform(text, False)
+
+if __name__ == "__main__":
+ keyword = input("Enter encryption keyword: ").strip()
+ cipher = VigenereCipher(keyword)
+
+ plaintext = input("Enter text to encrypt: ").strip()
+ encrypted = cipher.encrypt(plaintext)
+ print(f"Encrypted text: {encrypted}")
+
+ decrypted = cipher.decrypt(encrypted)
+ print(f"Decrypted back: {decrypted}")
\ No newline at end of file