50 changes: 50 additions & 0 deletions Data Structures and Algorithms/Sorting Algorithms/Cycle_Sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from typing import List

def cycle_sort(nums: List[int]) -> int:

writes = 0

for cycle_start in range(len(nums) - 1):
current = nums[cycle_start]

# Find the target position for the current item.
target_position = cycle_start
for i in range(cycle_start + 1, len(nums)):
if nums[i] < current:
target_position += 1

# Skip if the item is already in the correct position.
if target_position == cycle_start:
continue

# Handle duplicates by finding the next available position.
while current == nums[target_position]:
target_position += 1

nums[target_position], current = current, nums[target_position]
writes += 1

# Rotate the rest of the cycle.
while target_position != cycle_start:
target_position = cycle_start
for i in range(cycle_start + 1, len(nums)):
if nums[i] < current:
target_position += 1

while current == nums[target_position]:
target_position += 1

nums[target_position], current = current, nums[target_position]
writes += 1

return writes


if __name__ == "__main__":
arr = [1, 8, 3, 9, 10, 10, 2, 4]
print("Before sort:", arr)

writes = cycle_sort(arr)

print("After sort:", arr)
print(f"Number of writes: {writes}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Python program to implement Pigeonhole Sort

def pigeonhole_sort(a):
# size of range of values in the list
# (ie, number of pigeonholes we need)
my_min = min(a)
my_max = max(a)
size = my_max - my_min + 1

# our list of pigeonholes
holes = [0] * size

# Populate the pigeonholes.
for x in a:
assert type(x) is int, "integers only"
holes[x - my_min] += 1

# Put the elements back into the array in order.
i = 0
for count in range(size):
while holes[count] > 0:
holes[count] -= 1
a[i] = count + my_min
i += 1


a = [8, 1, 2, 7, 4, 5, 8]
print("Sorted order is : ", end = ' ')

pigeonhole_sort(a)

for i in range(0, len(a)):
print(a[i], end = ' ')
49 changes: 49 additions & 0 deletions Data Structures and Algorithms/Sorting Algorithms/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Cycle Sort Algorithm

## Overview
Cycle Sort is a comparison-based sorting algorithm that is efficient when minimizing memory writes is important. It is an in-place sorting algorithm that rearranges the elements by identifying cycles in the permutation of elements.

## Algorithm Explanation
The algorithm works by:
1. Identifying the correct position of each element in the array.
2. Placing the element in its correct position and replacing the element already there in the cycle.
3. Repeating the process for the remaining unsorted elements.

## Complexity
- **Time Complexity**:
- Best, Worst, and Average Case: O(n²) (due to nested cycles).
- **Space Complexity**: O(1) (in-place sorting).

## Usage Example
```python
from Cycle_Sort import cycle_sort

arr = [4, 5, 3, 2, 1]
print("Original array:", arr)
writes = cycle_sort(arr)
print("Sorted array:", arr)
print("Number of writes performed:", writes)
```
# Pigeonhole Sort Algorithm

## Overview
Pigeonhole Sort is a sorting algorithm that works well for sorting lists where the range of values (i.e., the difference between the maximum and minimum values) is not significantly larger than the number of elements in the list. It is a non-comparison-based sorting algorithm.

The algorithm works by placing each element into its corresponding "pigeonhole" (a slot or bucket) and then iterating through the pigeonholes in order to reconstruct the sorted list.

## Complexity
- **Time Complexity**:
- The time complexity of Pigeonhole Sort is O(n + range), where n is the number of elements in the list and range is the difference between the maximum and minimum values.

- This makes it efficient for lists with a small range of values.
- **Space Complexity**: The space complexity is O(range), as it requires additional space for the holes list.
- **Limitations**: Pigeonhole Sort is not suitable for lists with a large range of values, as it would require a lot of memory for the holes list.

## Usage Example
```python
from PigeonHole_Sort import pigeonhole_sort

arr = [4, 5, 3, 2, 1]
print("Original array:", arr)
writes = pigeonhole_sort(arr)
print("Sorted array:", arr)
27 changes: 27 additions & 0 deletions Data Structures and Algorithms/queues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Queue:
def __init__(self):
self.queue = []

def enqueue(self, item):
self.queue.append(item)

def dequeue(self):
if not self.is_empty():
return self.queue.pop(0)
return "Queue is empty"

def is_empty(self):
return len(self.queue) == 0

def peek(self):
return self.queue[0] if not self.is_empty() else None

def size(self):
return len(self.queue)

# Example Usage
q = Queue()
q.enqueue(10)
q.enqueue(20)
print(q.dequeue()) # Output: 10
print(q.peek()) # Output: 20
3 changes: 3 additions & 0 deletions FLASK PROJECTS/Anniversary time/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Anniversary Timing

Simple timing page implemented using flask
17 changes: 17 additions & 0 deletions FLASK PROJECTS/Anniversary time/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from flask import Flask, render_template
from datetime import datetime

app = Flask(__name__)

# 在此定义纪念日日期
anniversary_date = datetime(2024, 6, 16)

@app.route('/')
def index():
current_date = datetime.now()
delta = current_date - anniversary_date
days_passed = delta.days
return render_template('index.html', days_passed=days_passed, anniversary_date=anniversary_date.strftime("%Y-%m-%d %H:%M:%S"))

if __name__ == '__main__':
app.run(debug=False)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions FLASK PROJECTS/Anniversary time/static/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
background: url('background.jpg') no-repeat center center fixed;
background-size: cover;
color: white;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}

.container {
text-align: center;
background-color: rgba(0, 0, 0, 0.5);
padding: 20px;
border-radius: 10px;
}

h1 {
font-size: 3em;
}

.time {
font-size: 2em;
margin-top: 20px;
}

.time span {
font-weight: bold;
}
39 changes: 39 additions & 0 deletions FLASK PROJECTS/Anniversary time/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Anniversary</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<script>
function updateTimer() {
const anniversaryDate = new Date("{{ anniversary_date }}");
const currentDate = new Date();
const timeDiff = currentDate - anniversaryDate;

const days = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
const hours = Math.floor((timeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((timeDiff % (1000 * 60)) / 1000);

document.getElementById("days").innerText = days;
document.getElementById("hours").innerText = hours;
document.getElementById("minutes").innerText = minutes;
document.getElementById("seconds").innerText = seconds;
}

setInterval(updateTimer, 1000);
</script>
</head>
<body onload="updateTimer()">
<div class="container">
<h1>It has passed the xx anniversary</h1>
<div class="time">
<span id="days">0</span>
<span id="hours">0</span> 小时
<span id="minutes">0</span> 分钟
<span id="seconds">0</span>
</div>
</div>
</body>
</html>
133 changes: 133 additions & 0 deletions OTHERS/Encryption/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@

# 🔐 Simple Symmetric Encryption in Python

This project demonstrates the basics of **symmetric encryption** using Python and the [`cryptography`](https://cryptography.io/en/latest/) library. It's a great starting point for beginners interested in **cybersecurity**, **cryptography**, or contributing to **open-source security tools**.

---

## 📚 What You'll Learn

- How to generate secure keys
- How to encrypt and decrypt messages
- Basic key management (saving & loading keys)
- How `Fernet` (AES-based encryption) works under the hood

---

## 🚀 Getting Started

### 1. Clone the Repository

```bash
git clone https://github.com/your-username/simple-encryption-python.git
cd simple-encryption-python
```

### 2. Install Dependencies

Make sure you have Python 3.6+ installed.

Install required package using `pip`:

```bash
pip install cryptography
```

### 3. Run the Code

```bash
python simple_encryption.py
```

On first run, it will generate a `secret.key` file that is used for both encryption and decryption. Each time you run the script, it:
- Loads the existing key
- Encrypts a sample message
- Decrypts it back and displays the result

---

## 📂 File Structure

```
simple-encryption-python/
├── simple_encryption.py # Main script to run encryption and decryption
├── secret.key # Auto-generated AES-based symmetric key (DO NOT SHARE)
├── README.md # Documentation
```

---

## 🔒 Security Note

This example is for educational purposes only. If you’re building a production-grade application:
- Never store raw keys in plaintext
- Use environment variables or secure vaults (e.g., AWS KMS, HashiCorp Vault)
- Handle exceptions and errors securely

---

## 🧠 How It Works (In Brief)

- **Fernet** is a module in the `cryptography` package that provides:
- AES-128 in CBC mode
- HMAC-SHA256 authentication
- Random IVs for each encryption

- The encryption key is:
- Generated once and saved to `secret.key`
- Loaded on subsequent runs

- The message is:
- Encrypted using `.encrypt()`
- Decrypted using `.decrypt()`

---

## 💡 Sample Output

```
[*] Key loaded from 'secret.key'
Original Message: This is a secret message.
Encrypted Message: b'gAAAAABlZ...'
Decrypted Message: This is a secret message.
```

---

## 🤝 Contributing

Contributions are welcome! You can help by:
- Improving the CLI interface
- Adding file encryption support
- Implementing password-based key derivation
- Writing unit tests

To contribute:
1. Fork the repo
2. Create a new branch (`git checkout -b my-feature`)
3. Commit your changes
4. Push and create a Pull Request

---

## 📜 License

This project is licensed under the **MIT License**. See [LICENSE](LICENSE) for details.

---

## 👨‍💻 Author

**Afolabi Adewale**
A data and security enthusiast exploring the intersection of Python, encryption, and open-source software.
[GitHub Profile](https://github.com/your-username)

---

## 🔗 Related Resources

- [Python `cryptography` docs](https://cryptography.io/en/latest/)
- [Understanding Symmetric vs Asymmetric Encryption](https://www.cloudflare.com/learning/ssl/how-does-ssl-work/)
- [OWASP Crypto Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html)
Loading