Enoder commited on
Commit
2a64a28
·
verified ·
1 Parent(s): 50e8391

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -8
app.py CHANGED
@@ -26,14 +26,43 @@ def generate_ciphertext(plaintext):
26
  ciphertext = "".join([cipher_map.get(char, char) for char in plaintext])
27
  return ciphertext, cipher_map
28
 
29
- def generate_helper_phrase(ciphertext, cipher_map):
30
- # Generate a helper phrase that repeats letters from ciphertext
31
- helper_words = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  for letter in set(ciphertext):
33
- if letter.isalpha():
34
- word = letter * random.randint(2, 5) # repeat the letter to give hints
35
- helper_words.append(word)
36
- return " ".join(helper_words)
37
 
38
  # Streamlit App
39
  st.title("Chiffrement par Substitution")
@@ -44,7 +73,7 @@ plaintext = st.text_input("Entrez le texte à chiffrer:", "Exemple de texte")
44
 
45
  if st.button("Chiffrer"):
46
  ciphertext, cipher_map = generate_ciphertext(plaintext)
47
- helper_phrase = generate_helper_phrase(ciphertext, cipher_map)
48
 
49
  # Display the encrypted text and helper phrase
50
  st.write("Texte chiffré:")
 
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
68
  st.title("Chiffrement par Substitution")
 
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é:")