Skip to content

Commit 76059e6

Browse files
committed
adding file to repo
1 parent b02d2a6 commit 76059e6

File tree

2 files changed

+144
-0
lines changed

2 files changed

+144
-0
lines changed

caesar_cipher/README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# 🛡️ Caesar Cipher Tool
2+
3+
A command-line utility to **encrypt** and **decrypt** messages using the Caesar Cipher algorithm. Great for learning basic cryptography, creating puzzles, or encoding secret messages within a local or collaborative environment.
4+
5+
---
6+
7+
## 🔐 What is Caesar Cipher?
8+
9+
Caesar Cipher is a substitution cipher where each letter in the plaintext is shifted by a fixed number (shift key) of positions down the alphabet.
10+
11+
### Example (Shift = 3):
12+
- A → D
13+
- B → E
14+
- X → A
15+
- Z → C
16+
17+
> **Encryption**: Shift letters forward
18+
> **Decryption**: Shift letters backward
19+
20+
---
21+
22+
## 📦 Features
23+
24+
- Encrypt or decrypt any string using a simple shift
25+
- Supports both uppercase and lowercase
26+
- Leaves spaces, numbers, and punctuation unchanged
27+
- Command-line interface for real-time usage
28+
29+
---
30+
31+
## ⚙️ Usage
32+
33+
### 🔧 Requirements
34+
- Python 3.x installed
35+
36+
### 🏃 Run via Command Line
37+
38+
```bash
39+
python caesar_cipher_tool.py <mode> <shift> "<text>"
40+
````
41+
42+
* `<mode>`: `e` for encrypt, `d` for decrypt
43+
* `<shift>`: Number of positions to shift
44+
* `<text>`: The message to process (wrap in quotes)
45+
46+
---
47+
48+
## 🧪 Examples
49+
50+
### Encrypt:
51+
52+
```bash
53+
python caesar_cipher_tool.py e 4 "meet at library at 5pm"
54+
```
55+
56+
Output:
57+
58+
```
59+
Result: qiix ex plevvex ex 5ts
60+
```
61+
62+
### Decrypt:
63+
64+
```bash
65+
python caesar_cipher_tool.py d 4 "qiix ex plevvex ex 5ts"
66+
```
67+
68+
Output:
69+
70+
```
71+
Result: meet at library at 5pm
72+
```
73+
74+
---
75+
76+
## 💡 Real-world Scenario
77+
78+
You and a friend agree on a shift value (e.g., 4). You encrypt a secret note and send it. Your friend uses the same script and shift value to decrypt it.
79+
80+
---
81+
82+
## 🛠️ How It Works
83+
84+
The script:
85+
86+
1. Loops through each character in the message.
87+
2. Applies a shift based on encryption or decryption mode.
88+
3. Converts characters using ASCII math and wraps alphabetically using `% 26`.
89+
4. Non-alphabet characters are preserved.
90+
91+
```python
92+
chr((ord(char) - base + shift) % 26 + base)
93+
```
94+
95+
* `ord(char)` – ASCII of char
96+
* `base``ord('a')` or `ord('A')`
97+
* `shift` – Provided shift value
98+
99+
---
100+
101+
## 🧑‍🎓 Author
102+
103+
Built by Aakash — focused on cybersecurity, scripting, and real-world learning through hands-on tools.
104+
105+
---
106+
107+

caesar_cipher/encryp decryp.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Caesar Cipher Encryption/Decryption
2+
3+
def encrypt(text, shift):
4+
result = ''
5+
for char in text:
6+
if char.isalpha():
7+
base = ord('A') if char.isupper() else ord('a')
8+
result += chr((ord(char) - base + shift) % 26 + base)
9+
else:
10+
result += char # Keep spaces/symbols as is
11+
return result
12+
13+
def decrypt(text, shift):
14+
return encrypt(text, -shift)
15+
16+
def main():
17+
choice = input("Type 'encrypt' or 'decrypt': ").strip().lower()
18+
19+
if choice not in ['encrypt', 'decrypt']:
20+
print("Invalid choice. Please type 'encrypt' or 'decrypt'.")
21+
return
22+
23+
message = input("Enter your message: ")
24+
25+
try:
26+
shift = int(input("Enter shift value (0-25): ")) % 26
27+
except ValueError:
28+
print("Shift must be a number.")
29+
return
30+
31+
if choice == 'encrypt':
32+
print("Encrypted message:", encrypt(message, shift))
33+
else:
34+
print("Decrypted message:", decrypt(message, shift))
35+
36+
if __name__ == '__main__':
37+
main()

0 commit comments

Comments
 (0)