Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ def categorize_letters():
|
|
| 8 |
consonants = "".join([c for c in string.ascii_letters if c not in vowels])
|
| 9 |
return vowels, consonants
|
| 10 |
|
| 11 |
-
def
|
| 12 |
vowels, consonants = categorize_letters()
|
| 13 |
symbol_pool = string.ascii_letters + string.digits + string.punctuation
|
| 14 |
cipher_map = {}
|
|
@@ -22,46 +22,57 @@ def generate_ciphertext(plaintext):
|
|
| 22 |
else:
|
| 23 |
cipher_map[letter] = letter # keep spaces and non-alphabetic characters as is
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
# Create the encrypted text using the cipher map
|
| 26 |
-
|
| 27 |
-
return ciphertext, cipher_map
|
| 28 |
|
| 29 |
-
# Helper words list with
|
| 30 |
helper_words = {
|
| 31 |
-
'A': ["
|
| 32 |
-
'B': ["
|
| 33 |
-
'C': ["
|
| 34 |
-
'D': ["
|
| 35 |
-
'E': ["
|
| 36 |
-
'F': ["
|
| 37 |
-
'G': ["
|
| 38 |
-
'H': ["
|
| 39 |
-
'I': ["
|
| 40 |
-
'J': ["
|
| 41 |
-
'K': ["
|
| 42 |
-
'L': ["
|
| 43 |
-
'M': ["
|
| 44 |
-
'N': ["
|
| 45 |
-
'O': ["
|
| 46 |
-
'P': ["
|
| 47 |
-
'Q': ["
|
| 48 |
-
'R': ["
|
| 49 |
-
'S': ["
|
| 50 |
-
'T': ["
|
| 51 |
-
'U': ["
|
| 52 |
-
'V': ["
|
| 53 |
-
'W': ["
|
| 54 |
-
'X': ["
|
| 55 |
-
'Y': ["
|
| 56 |
-
'Z': ["
|
| 57 |
}
|
| 58 |
|
| 59 |
-
def generate_helper_phrase(ciphertext):
|
| 60 |
# Generate a helper phrase using the helper words list
|
| 61 |
helper_phrase = []
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
return " ".join(helper_phrase)
|
| 66 |
|
| 67 |
# Streamlit App
|
|
@@ -72,8 +83,9 @@ st.write("Ce système remplace chaque lettre d'un texte par un caractère aléat
|
|
| 72 |
plaintext = st.text_input("Entrez le texte à chiffrer:", "Exemple de texte")
|
| 73 |
|
| 74 |
if st.button("Chiffrer"):
|
| 75 |
-
|
| 76 |
-
|
|
|
|
| 77 |
|
| 78 |
# Display the encrypted text and helper phrase
|
| 79 |
st.write("Texte chiffré:")
|
|
|
|
| 8 |
consonants = "".join([c for c in string.ascii_letters if c not in vowels])
|
| 9 |
return vowels, consonants
|
| 10 |
|
| 11 |
+
def generate_cipher_map(plaintext):
|
| 12 |
vowels, consonants = categorize_letters()
|
| 13 |
symbol_pool = string.ascii_letters + string.digits + string.punctuation
|
| 14 |
cipher_map = {}
|
|
|
|
| 22 |
else:
|
| 23 |
cipher_map[letter] = letter # keep spaces and non-alphabetic characters as is
|
| 24 |
|
| 25 |
+
return cipher_map
|
| 26 |
+
|
| 27 |
+
def generate_ciphertext(plaintext, cipher_map):
|
| 28 |
# Create the encrypted text using the cipher map
|
| 29 |
+
return "".join([cipher_map.get(char, char) for char in plaintext])
|
|
|
|
| 30 |
|
| 31 |
+
# Helper words list with common French words for each alphabet letter
|
| 32 |
helper_words = {
|
| 33 |
+
'A': ["salade", "banane", "flamme", "chaise", "carafe"],
|
| 34 |
+
'B': ["bison", "cabine", "blouse", "abri", "bonbon"],
|
| 35 |
+
'C': ["cerise", "cactus", "canard", "chaud", "cirque"],
|
| 36 |
+
'D': ["dinde", "décor", "donner", "douleur", "début"],
|
| 37 |
+
'E': ["pêche", "mercredi", "effet", "plage", "épice"],
|
| 38 |
+
'F': ["fête", "fleur", "framboise", "frère", "façade"],
|
| 39 |
+
'G': ["groupe", "gagne", "galerie", "grille", "guerre"],
|
| 40 |
+
'H': ["histoire", "hasard", "hiver", "homme", "horizon"],
|
| 41 |
+
'I': ["étudier", "milieu", "jardin", "écrire", "grill"],
|
| 42 |
+
'J': ["jaune", "jupe", "joli", "jambe", "jouet"],
|
| 43 |
+
'K': ["kilo", "kiwi", "kangourou", "kermesse", "kayak"],
|
| 44 |
+
'L': ["lumière", "lien", "lire", "loup", "lait"],
|
| 45 |
+
'M': ["mère", "mignon", "monde", "musique", "moulin"],
|
| 46 |
+
'N': ["nuage", "nuit", "nommer", "neige", "nourrir"],
|
| 47 |
+
'O': ["orange", "origine", "opéra", "objet", "ombrelle"],
|
| 48 |
+
'P': ["poire", "piano", "pluie", "parc", "porte"],
|
| 49 |
+
'Q': ["quatre", "qualité", "quitte", "queue", "quart"],
|
| 50 |
+
'R': ["rose", "rire", "réveil", "route", "réponse"],
|
| 51 |
+
'S': ["soleil", "salle", "sourire", "sombre", "salut"],
|
| 52 |
+
'T': ["table", "téléphone", "tigre", "tarte", "triste"],
|
| 53 |
+
'U': ["univers", "unité", "unique", "urgent", "utile"],
|
| 54 |
+
'V': ["vache", "valise", "visage", "vitrine", "vendre"],
|
| 55 |
+
'W': ["wagon", "weekend", "whisky", "web", "watt"],
|
| 56 |
+
'X': ["xénon", "exemple", "toxique", "fox", "lux"],
|
| 57 |
+
'Y': ["yeux", "yo-yo", "yacht", "yeti", "yogourt"],
|
| 58 |
+
'Z': ["zèbre", "zone", "zinc", "zodiac", "zigzag"]
|
| 59 |
}
|
| 60 |
|
| 61 |
+
def generate_helper_phrase(ciphertext, cipher_map):
|
| 62 |
# Generate a helper phrase using the helper words list
|
| 63 |
helper_phrase = []
|
| 64 |
+
desired_length = 3 * len(ciphertext) # Desired length for the helper phrase
|
| 65 |
+
|
| 66 |
+
while len(" ".join(helper_phrase)) < desired_length:
|
| 67 |
+
for letter in set(ciphertext):
|
| 68 |
+
if letter.isalpha() and letter.upper() in helper_words:
|
| 69 |
+
word = random.choice(helper_words[letter.upper()])
|
| 70 |
+
# Encrypt the helper word using the same cipher map
|
| 71 |
+
encrypted_word = generate_ciphertext(word, cipher_map)
|
| 72 |
+
helper_phrase.append(encrypted_word)
|
| 73 |
+
if len(" ".join(helper_phrase)) >= desired_length:
|
| 74 |
+
break
|
| 75 |
+
|
| 76 |
return " ".join(helper_phrase)
|
| 77 |
|
| 78 |
# Streamlit App
|
|
|
|
| 83 |
plaintext = st.text_input("Entrez le texte à chiffrer:", "Exemple de texte")
|
| 84 |
|
| 85 |
if st.button("Chiffrer"):
|
| 86 |
+
cipher_map = generate_cipher_map(plaintext)
|
| 87 |
+
ciphertext = generate_ciphertext(plaintext, cipher_map)
|
| 88 |
+
helper_phrase = generate_helper_phrase(ciphertext, cipher_map)
|
| 89 |
|
| 90 |
# Display the encrypted text and helper phrase
|
| 91 |
st.write("Texte chiffré:")
|