Encrypted Private Diary App in Python
Code prompt
Local encrypted dream journal.
import json
import os
import getpass
import hashlib
import base64
from datetime import datetime
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.hazmat.backends import default_backend
from cryptography.fernet import Fernet
import colorama
from colorama import Fore, Style
colorama.init()
class DreamJournal:
def __init__(self):
self.filename = "dreams.enc"
self.salt_file = "salt.bin"
self.key = None
self.fernet = None
self.dreams = []
self.ensure_files()
def ensure_files(self):
if not os.path.exists(self.salt_file):
with open(self.salt_file, "wb") as f:
f.write(os.urandom(16))
if not os.path.exists(self.filename):
self.save_encrypted([])
def derive_key(self, password):
with open(self.salt_file, "rb") as f:
salt = f.read()
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=32,
salt=salt,
iterations=1000000,
backend=default_backend()
)
key = base64.urlsafe_b64encode(kdf.derive(password.encode()))
return key
def authenticate(self):
if self.key:
return True
print(Fore.MAGENTA + "\n=== Sensual Dream Journal ===" + Style.RESET_ALL)
print(Fore.CYAN + "All dreams stored locally and encrypted." + Style.RESET_ALL)
password = getpass.getpass(Fore.YELLOW + "Enter master password: " + Style.RESET_ALL)
try:
self.key = self.derive_key(password)
self.fernet = Fernet(self.key)
self.load_dreams()
print(Fore.GREEN + "Access granted. Welcome back to your private dream world." + Style.RESET_ALL)
return True
except Exception:
print(Fore.RED + "Invalid password." + Style.RESET_ALL)
self.key = None
return False
def load_dreams(self):
try:
with open(self.filename, "rb") as f:
encrypted = f.read()
if encrypted:
decrypted = self.fernet.decrypt(encrypted)
self.dreams = json.loads(decrypted.decode())
else:
self.dreams = []
except:
self.dreams = []
def save_encrypted(self, data):
encrypted = self.fernet.encrypt(json.dumps(data).encode())
with open(self.filename, "wb") as f:
f.write(encrypted)
def record_dream(self):
print(Fore.MAGENTA + "\nRecord a new dream..." + Style.RESET_ALL)
title = input(Fore.CYAN + "Dream title: " + Style.RESET_ALL).strip()
if not title:
title = "Untitled Dream"
print(Fore.YELLOW + "\nDescribe your dream in vivid, sensual detail." + Style.RESET_ALL)
print(Fore.YELLOW + "Focus on colors, sensations, emotions, textures..." + Style.RESET_ALL)
content_lines = []
print(Fore.CYAN + "Write your dream (type 'END' on a new line when finished):" + Style.RESET_ALL)
while True:
line = input()
if line.strip().upper() == "END":
break
content_lines.append(line)
content = "\n".join(content_lines)
sensual_colors = []
print(Fore.MAGENTA + "\nSensual colors that dominated the dream (comma separated):" + Style.RESET_ALL)
colors_input = input(Fore.CYAN + "e.g. crimson, velvet indigo, molten gold, obsidian: " + Style.RESET_ALL)
if colors_input.strip():
sensual_colors = [c.strip() for c in colors_input.split(",")]
timestamp = datetime.now().isoformat()
dream = {
"timestamp": timestamp,
"title": title,
"content": content,
"sensual_colors": sensual_colors,
"date": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
}
self.dreams.append(dream)
self.save_encrypted(self.dreams)
print(Fore.GREEN + "\nDream saved securely on your device." + Style.RESET_ALL)
def view_dreams(self):
if not self.dreams:
print(Fore.YELLOW + "No dreams recorded yet. Your subconscious awaits..." + Style.RESET_ALL)
return
print(Fore.MAGENTA + "\n=== Your Encrypted Dream Archive ===" + Style.RESET_ALL)
for i, dream in enumerate(reversed(self.dreams), 1):
print(Fore.CYAN + f"\n[{i}] {dream['date']} - {dream['title']}" + Style.RESET_ALL)
if dream.get("sensual_colors"):
colors = ", ".join([Fore.MAGENTA + c + Style.RESET_ALL for c in dream["sensual_colors"]])
print(Fore.YELLOW + f" Sensual palette: {colors}" + Style.RESET_ALL)
print(Fore.WHITE + " " + "-" * 40 + Style.RESET_ALL)
content_preview = dream["content"][:120] + "..." if len(dream["content"]) > 120 else dream["content"]
print(Fore.WHITE + f" {content_preview}" + Style.RESET_ALL)
print()
choice = input(Fore.CYAN + "Enter dream number to read full entry (or press Enter to return): " + Style.RESET_ALL)
if choice.strip().isdigit():
idx = int(choice) - 1
if 0 <= idx < len(self.dreams):
dream = list(reversed(self.dreams))[idx]
print(Fore.MAGENTA + "\n" + "="*60 + Style.RESET_ALL)
print(Fore.CYAN + f"{dream['date']} - {dream['title']}" + Style.RESET_ALL)
if dream.get("sensual_colors"):
print(Fore.YELLOW + "Sensual Colors: " + ", ".join(dream["sensual_colors"]) + Style.RESET_ALL)
print(Fore.MAGENTA + "="*60 + Style.RESET_ALL)
print(Fore.WHITE + dream["content"] + Style.RESET_ALL)
print(Fore.MAGENTA + "="*60 + Style.RESET_ALL)
else:
print(Fore.RED + "Invalid selection." + Style.RESET_ALL)
def run(self):
if not self.authenticate():
return
while True:
print(Fore.MAGENTA + "\n" + "="*50 + Style.RESET_ALL)
print(Fore.CYAN + " LOCAL ENCRYPTED DREAM JOURNAL" + Style.RESET_ALL)
print(Fore.MAGENTA + "="*50 + Style.RESET_ALL)
print(Fore.YELLOW + "1. Record new sensual dream" + Style.RESET_ALL)
print(Fore.YELLOW + "2. View dream archive" + Style.RESET_ALL)
print(Fore.YELLOW + "3. Exit" + Style.RESET_ALL)
choice = input(Fore.CYAN + "\nChoose an option: " + Style.RESET_ALL).strip()
if choice == "1":
self.record_dream()
elif choice == "2":
self.view_dreams()
elif choice == "3":
print(Fore.GREEN + "\nDreams secured. Sleep well, lover of the subconscious." + Style.RESET_ALL)
break
else:
print(Fore.RED + "Invalid choice. Try again." + Style.RESET_ALL)
if __name__ == "__main__":
journal = DreamJournal()
journal.run()Write a Python program to implement a locally encrypted dream journal. Users can record dream content with sensual colors. All data is only saved on the local device.
This prompt focuses on “Local Encrypted Dream Journal Program”: Local encrypted dream journal. It is ready to use for code generation on HackAIGC.
Open the prompt, tap Use prompt or Copy prompt, then run it with your preferred model and settings.
Follow the creative direction in “Local Encrypted Dream Journal Program”: Local encrypted dream journal. Edit the prompt to change the tone, structure, or level of detail.
Yes. Copy the prompt text, modify details, then generate again on HackAIGC.