File size: 1,054 Bytes
cd13322
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# app.py

import gradio as gr
import string

def caesar_brute_force(ciphertext: str):
    ciphertext = ciphertext.strip()
    if not ciphertext:
        return "Please enter some ciphertext."

    alphabet = string.ascii_lowercase
    results = []

    for shift in range(1, 26):  # 25 possible Caesar shifts
        decrypted = ''
        for char in ciphertext:
            if char.lower() in alphabet:
                idx = (alphabet.index(char.lower()) - shift) % 26
                new_char = alphabet[idx]
                decrypted += new_char.upper() if char.isupper() else new_char
            else:
                decrypted += char
        results.append(f"Shift {shift}: {decrypted}")

    return "\n\n".join(results)

iface = gr.Interface(
    fn=caesar_brute_force,
    inputs=gr.Textbox(lines=4, label="Enter Caesar Cipher Text"),
    outputs="text",
    title="🔓 Caesar Cipher Brute-Force Analyzer",
    description="Try all 25 Caesar cipher shifts to decrypt a message. Look for the correct one based on the result."
)

iface.launch()