Enoder commited on
Commit
bb51d3c
·
verified ·
1 Parent(s): 1ae392f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -48,15 +48,16 @@ helper_words = {
48
  'Z': ["zèbre", "zone", "zinc", "zodiac", "zigzag"]
49
  }
50
 
51
- def generate_helper_phrase(ciphertext, mapping):
 
52
  helper_phrase = []
53
 
54
- # Generate three words for each letter in the ciphertext
55
- for letter in set(ciphertext):
56
- if letter.isalpha() and letter.upper() in helper_words:
57
- for _ in range(3): # Add three words for each letter
58
- word = random.choice(helper_words[letter.upper()])
59
- helper_phrase.append(word)
60
 
61
  # Join the helper phrase into a single string
62
  helper_phrase_str = " ".join(helper_phrase)
@@ -76,7 +77,7 @@ plaintext = st.text_input("Entrez le texte à chiffrer:", "Exemple de texte")
76
  if st.button("Chiffrer"):
77
  mapping = generate_variable_mapping()
78
  ciphertext = encrypt_text(plaintext, mapping)
79
- helper_phrase = generate_helper_phrase(ciphertext, mapping)
80
 
81
  # Display the encrypted text and helper phrase
82
  st.write("Texte chiffré:")
 
48
  'Z': ["zèbre", "zone", "zinc", "zodiac", "zigzag"]
49
  }
50
 
51
+ def generate_helper_phrase(plaintext, mapping):
52
+ unique_letters = set(char for char in plaintext if char.isalpha()) # Get unique letters from plaintext
53
  helper_phrase = []
54
 
55
+ # Generate five words for each unique letter in the plaintext
56
+ for letter in unique_letters:
57
+ letter_upper = letter.upper()
58
+ if letter_upper in helper_words:
59
+ selected_words = random.sample(helper_words[letter_upper], 5) # Select 5 random words
60
+ helper_phrase.extend(selected_words)
61
 
62
  # Join the helper phrase into a single string
63
  helper_phrase_str = " ".join(helper_phrase)
 
77
  if st.button("Chiffrer"):
78
  mapping = generate_variable_mapping()
79
  ciphertext = encrypt_text(plaintext, mapping)
80
+ helper_phrase = generate_helper_phrase(plaintext, mapping)
81
 
82
  # Display the encrypted text and helper phrase
83
  st.write("Texte chiffré:")