Enoder commited on
Commit
14caaa7
·
verified ·
1 Parent(s): 2a64a28

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -36
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 generate_ciphertext(plaintext):
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
- ciphertext = "".join([cipher_map.get(char, char) for char in plaintext])
27
- return ciphertext, cipher_map
28
 
29
- # Helper words list with repeated letters for each alphabet letter
30
  helper_words = {
31
- 'A': ["maman", "canal", "salade", "avalanche", "savane"],
32
- 'B': ["bobo", "babil", "babine", "bibine", "abbaye"],
33
- 'C': ["accroc", "accueil", "accuse", "cacao", "cocotte"],
34
- 'D': ["dada", "dedans", "dodo", "dédale", "doudou"],
35
- 'E': ["terre", "cerise", "serre", "essence", "berce"],
36
- 'F': ["fifre", "fouffe", "souffre", "coiffe", "affreux"],
37
- 'G': ["gaga", "gigogne", "gogo", "grignote", "goguette"],
38
- 'H': ["hahaha", "hache", "haha", "hérissé", "hocher"],
39
- 'I': ["ironie", "criique", "illisible", "risible", "immobile"],
40
- 'J': ["joujou", "jardinier", "jonjonaire", "jujube", "juxtapose"],
41
- 'K': ["kakapo", "kaki", "kéké", "kitoko", "kiwi"],
42
- 'L': ["loulou", "bouillon", "lila", "ballon", "molle"],
43
- 'M': ["maman", "mimique", "mamie", "moment", "murmure"],
44
- 'N': ["nanan", "manana", "ronron", "néné", "nananère"],
45
- 'O': ["oligo", "mollo", "bourgeois", "bouton", "tonton"],
46
- 'P': ["papa", "popote", "poupon", "pipeau", "appétit"],
47
- 'Q': ["croque", "quadruple", "aquatique", "qualité", "quinte"],
48
- 'R': ["rare", "terre", "arbre", "brouillard", "rire"],
49
- 'S': ["sissi", "assise", "saison", "ressasser", "cuisse"],
50
- 'T': ["tata", "totem", "tatouage", "tarte", "montant"],
51
- 'U': ["tutu", "futul", "perdu", "moule", "lutulage"],
52
- 'V': ["vavavoom", "vivant", "sauvage", "veau", "velours"],
53
- 'W': ["woow", "watt", "wowow", "wargame", "wawa"],
54
- 'X': ["axel", "axiome", "relaxe", "excitation", "sexe"],
55
- 'Y': ["yaya", "yayou", "yonis", "yeux", "joyeux"],
56
- 'Z': ["zigzag", "zizi", "zazou", "blizzard", "zaza"]
57
  }
58
 
59
- def generate_helper_phrase(ciphertext):
60
  # Generate a helper phrase using the helper words list
61
  helper_phrase = []
62
- for letter in set(ciphertext):
63
- if letter.isalpha() and letter.upper() in helper_words:
64
- helper_phrase.append(random.choice(helper_words[letter.upper()]))
 
 
 
 
 
 
 
 
 
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
- ciphertext, cipher_map = generate_ciphertext(plaintext)
76
- helper_phrase = generate_helper_phrase(ciphertext)
 
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é:")