analyse_freq_decryptage.py

Created by elodie-gamot

Created on July 05, 2022

346 Bytes

Analyse fréquentielle d’un texte. Les résultats sont donnés en pourcentages. ATTENTION, le texte entré en argument (message) doit être écrit entre guillemets pour être reconnu comme une chaîne de caractères !


alphabet = "abcdefghijklmnopqrstuvwxyz"

def analyse_freq(message):
  for letter in alphabet:
    freq=0
    freq=(message.count(letter))/(len(message)-message.count(' '))
    #La soustraction de ' ' permet de supprimer les espaces pris 
    #en compte avec la fonction len()
    print(letter,"=",round(freq*100,2))

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.