335 lines
14 KiB
HTML
335 lines
14 KiB
HTML
{% extends "base.html" %}
|
|
|
|
{% block title %}Decode Message - Stegasoo{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="row justify-content-center">
|
|
<div class="col-lg-8">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h5 class="mb-0"><i class="bi bi-unlock-fill me-2"></i>Decode Secret Message or File</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
{% if decoded_message %}
|
|
<!-- Text Message Result -->
|
|
<div class="alert alert-success">
|
|
<h6><i class="bi bi-check-circle me-2"></i>Message Decrypted Successfully!</h6>
|
|
</div>
|
|
|
|
<label class="form-label text-muted">Decoded Message:</label>
|
|
<div class="position-relative">
|
|
<div class="alert-message p-3 rounded bg-dark border border-secondary" id="decodedContent" style="white-space: pre-wrap;">{{ decoded_message }}</div>
|
|
<button class="btn btn-sm btn-outline-light position-absolute top-0 end-0 m-2" onclick="navigator.clipboard.writeText(document.getElementById('decodedContent').innerText).then(() => this.innerHTML = '<i class=\'bi bi-check\'></i>').catch(() => alert('Failed to copy'))">
|
|
<i class="bi bi-clipboard"></i> Copy
|
|
</button>
|
|
</div>
|
|
|
|
<a href="/decode" class="btn btn-outline-light w-100 mt-3">
|
|
<i class="bi bi-arrow-repeat me-2"></i>Decode Another
|
|
</a>
|
|
|
|
{% elif decoded_file %}
|
|
<!-- File Result -->
|
|
<div class="alert alert-success">
|
|
<h6><i class="bi bi-check-circle me-2"></i>File Decrypted Successfully!</h6>
|
|
</div>
|
|
|
|
<div class="text-center mb-4">
|
|
<i class="bi bi-file-earmark-check text-success" style="font-size: 4rem;"></i>
|
|
<h5 class="mt-3">{{ filename }}</h5>
|
|
<p class="text-muted mb-1">{{ file_size }}</p>
|
|
{% if mime_type %}
|
|
<small class="text-muted">Type: {{ mime_type }}</small>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<a href="{{ url_for('decode_download', file_id=file_id) }}" class="btn btn-primary btn-lg w-100 mb-3">
|
|
<i class="bi bi-download me-2"></i>Download File
|
|
</a>
|
|
|
|
<div class="alert alert-warning small">
|
|
<i class="bi bi-clock me-1"></i>
|
|
<strong>File expires in 5 minutes.</strong> Download now.
|
|
</div>
|
|
|
|
<a href="/decode" class="btn btn-outline-light w-100">
|
|
<i class="bi bi-arrow-repeat me-2"></i>Decode Another
|
|
</a>
|
|
|
|
{% else %}
|
|
<!-- Decode Form -->
|
|
<form method="POST" enctype="multipart/form-data" id="decodeForm">
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label">
|
|
<i class="bi bi-image me-1"></i> Reference Photo
|
|
</label>
|
|
<div class="drop-zone">
|
|
<input type="file" name="reference_photo" accept="image/*" required>
|
|
<div class="drop-zone-label">
|
|
<i class="bi bi-cloud-arrow-up fs-3 d-block mb-2 text-muted"></i>
|
|
<span class="text-muted">Drop image or click to browse</span>
|
|
</div>
|
|
<img class="drop-zone-preview d-none">
|
|
</div>
|
|
<div class="form-text">
|
|
The same reference photo used for encoding
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label">
|
|
<i class="bi bi-file-earmark-image me-1"></i> Stego Image
|
|
</label>
|
|
<div class="drop-zone" id="stegoDropZone">
|
|
<input type="file" name="stego_image" accept="image/*" required>
|
|
<div class="drop-zone-label">
|
|
<i class="bi bi-cloud-arrow-up fs-3 d-block mb-2 text-muted"></i>
|
|
<span class="text-muted">Drop image or click to browse</span>
|
|
</div>
|
|
<img class="drop-zone-preview d-none">
|
|
</div>
|
|
<div class="form-text">
|
|
The image containing the hidden message/file
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label" id="dayPhraseLabel">
|
|
<i class="bi bi-chat-quote me-1"></i> Day Phrase
|
|
</label>
|
|
<input type="text" name="day_phrase" class="form-control"
|
|
placeholder="e.g., correct horse battery" required>
|
|
<div class="form-text">
|
|
The phrase for the day the message was encoded
|
|
</div>
|
|
</div>
|
|
|
|
<hr class="my-4">
|
|
|
|
<h6 class="text-muted mb-3">
|
|
SECURITY FACTORS
|
|
<span class="text-warning small">(provide same factors used during encoding)</span>
|
|
</h6>
|
|
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
|
|
<label class="form-label"><i class="bi bi-123 me-1"></i> PIN</label>
|
|
<div class="input-group">
|
|
<input type="password" name="pin" class="form-control" id="pinInput" placeholder="6-9 digits" maxlength="9">
|
|
<button class="btn btn-outline-secondary" type="button" id="togglePin">
|
|
<i class="bi bi-eye"></i>
|
|
</button>
|
|
</div>
|
|
<div class="form-text">
|
|
If PIN was used during encoding
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label">
|
|
<i class="bi bi-file-earmark-lock me-1"></i> RSA Key
|
|
</label>
|
|
<input type="file" name="rsa_key" class="form-control" id="rsaKeyInput"
|
|
accept=".pem,.key">
|
|
<div class="form-text">
|
|
If RSA key was used during encoding
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- RSA Key Password (shown when key selected) -->
|
|
<div class="mb-3 d-none" id="rsaPasswordGroup">
|
|
<label class="form-label">
|
|
<i class="bi bi-key me-1"></i> RSA Key Password
|
|
</label>
|
|
<input type="password" name="rsa_password" class="form-control"
|
|
placeholder="Password for the .pem file (if encrypted)">
|
|
<div class="form-text">
|
|
Leave blank if your key file is not password-protected
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary btn-lg w-100" id="decodeBtn">
|
|
<i class="bi bi-unlock me-2"></i>Decode
|
|
</button>
|
|
</form>
|
|
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
|
|
{% if not decoded_message and not decoded_file %}
|
|
<div class="card mt-4">
|
|
<div class="card-body">
|
|
<h6 class="text-muted mb-3"><i class="bi bi-question-circle me-2"></i>Troubleshooting</h6>
|
|
<ul class="list-unstyled text-muted small mb-0">
|
|
<li class="mb-2">
|
|
<i class="bi bi-dot"></i>
|
|
Make sure you're using the <strong>exact same reference photo</strong> file
|
|
</li>
|
|
<li class="mb-2">
|
|
<i class="bi bi-dot"></i>
|
|
Use the phrase for the <strong>day the message was encoded</strong>, not today
|
|
</li>
|
|
<li class="mb-2">
|
|
<i class="bi bi-dot"></i>
|
|
Provide the <strong>same security factors</strong> (PIN and/or RSA key) used during encoding
|
|
</li>
|
|
<li class="mb-2">
|
|
<i class="bi bi-dot"></i>
|
|
Ensure the stego image hasn't been <strong>resized or recompressed</strong>
|
|
</li>
|
|
<li class="mb-0">
|
|
<i class="bi bi-dot"></i>
|
|
If using an RSA key, make sure the <strong>password is correct</strong>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block scripts %}
|
|
<script>
|
|
// Form submit loading state
|
|
document.getElementById('decodeForm')?.addEventListener('submit', function() {
|
|
const btn = document.getElementById('decodeBtn');
|
|
btn.innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>Decoding...';
|
|
btn.disabled = true;
|
|
});
|
|
|
|
// Show RSA password field when key is selected
|
|
const rsaKeyInput = document.getElementById('rsaKeyInput');
|
|
const rsaPasswordGroup = document.getElementById('rsaPasswordGroup');
|
|
|
|
rsaKeyInput?.addEventListener('change', function() {
|
|
rsaPasswordGroup.classList.toggle('d-none', !this.files.length);
|
|
});
|
|
|
|
// Day names for date detection
|
|
const dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
|
|
// Detect day from filename
|
|
function detectDayFromFilename(filename) {
|
|
const dateMatch = filename.match(/_(\d{4})[-]?(\d{2})[-]?(\d{2})/);
|
|
|
|
if (dateMatch) {
|
|
const [, year, month, day] = dateMatch;
|
|
const date = new Date(year, month - 1, day);
|
|
return dayNames[date.getDay()];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// Update day phrase label
|
|
function updateDayLabel(dayName) {
|
|
const label = document.getElementById('dayPhraseLabel');
|
|
if (label && dayName) {
|
|
label.innerHTML = `<i class="bi bi-chat-quote me-1"></i> ${dayName}'s Phrase`;
|
|
}
|
|
}
|
|
|
|
// PIN Toggle
|
|
document.getElementById('togglePin')?.addEventListener('click', function() {
|
|
const input = document.getElementById('pinInput');
|
|
const icon = this.querySelector('i');
|
|
if (input.type === 'password') {
|
|
input.type = 'text';
|
|
icon.classList.replace('bi-eye', 'bi-eye-slash');
|
|
} else {
|
|
input.type = 'password';
|
|
icon.classList.replace('bi-eye-slash', 'bi-eye');
|
|
}
|
|
});
|
|
|
|
// Paste from Clipboard
|
|
document.addEventListener('paste', function(e) {
|
|
if (!document.getElementById('decodeForm')) return;
|
|
|
|
const items = e.clipboardData.items;
|
|
for (let i = 0; i < items.length; i++) {
|
|
if (items[i].type.indexOf("image") !== -1) {
|
|
const blob = items[i].getAsFile();
|
|
|
|
const stegoInput = document.querySelector('input[name="stego_image"]');
|
|
const refInput = document.querySelector('input[name="reference_photo"]');
|
|
|
|
const targetInput = (!stegoInput.files.length) ? stegoInput : refInput;
|
|
|
|
const container = new DataTransfer();
|
|
container.items.add(blob);
|
|
targetInput.files = container.files;
|
|
|
|
targetInput.dispatchEvent(new Event('change'));
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
|
|
// Drag & drop with preview
|
|
document.querySelectorAll('.drop-zone').forEach(zone => {
|
|
const input = zone.querySelector('input[type="file"]');
|
|
const label = zone.querySelector('.drop-zone-label');
|
|
const preview = zone.querySelector('.drop-zone-preview');
|
|
const isStegoZone = zone.id === 'stegoDropZone';
|
|
|
|
['dragenter', 'dragover'].forEach(evt => {
|
|
zone.addEventListener(evt, e => {
|
|
e.preventDefault();
|
|
zone.classList.add('drag-over');
|
|
});
|
|
});
|
|
|
|
['dragleave', 'drop'].forEach(evt => {
|
|
zone.addEventListener(evt, e => {
|
|
e.preventDefault();
|
|
zone.classList.remove('drag-over');
|
|
});
|
|
});
|
|
|
|
zone.addEventListener('drop', e => {
|
|
if (e.dataTransfer.files.length) {
|
|
input.files = e.dataTransfer.files;
|
|
const file = e.dataTransfer.files[0];
|
|
showPreview(file);
|
|
|
|
if (isStegoZone) {
|
|
const dayName = detectDayFromFilename(file.name);
|
|
updateDayLabel(dayName);
|
|
}
|
|
}
|
|
});
|
|
|
|
input.addEventListener('change', function() {
|
|
if (this.files && this.files[0]) {
|
|
const file = this.files[0];
|
|
showPreview(file);
|
|
|
|
if (isStegoZone) {
|
|
const dayName = detectDayFromFilename(file.name);
|
|
updateDayLabel(dayName);
|
|
}
|
|
}
|
|
});
|
|
|
|
function showPreview(file) {
|
|
if (!file.type.startsWith('image/')) return;
|
|
|
|
const reader = new FileReader();
|
|
reader.onload = e => {
|
|
preview.src = e.target.result;
|
|
preview.classList.remove('d-none');
|
|
label.innerHTML = '<i class="bi bi-check-circle text-success me-1"></i>' + file.name;
|
|
};
|
|
reader.readAsDataURL(file);
|
|
}
|
|
});
|
|
</script>
|
|
{% endblock %}
|