From b115533bfa33e6726ef22b6a37f551b1e787bb4c Mon Sep 17 00:00:00 2001 From: geoffrey Date: Thu, 28 Sep 2023 21:50:14 +0200 Subject: [PATCH] Add chart for IC --- ic.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ic.py b/ic.py index 47eb72d..5001696 100644 --- a/ic.py +++ b/ic.py @@ -2,6 +2,7 @@ from argparse import ArgumentParser from functions import readFile, countLetters +import matplotlib.pyplot as plt def checkArguments(): @@ -32,11 +33,21 @@ def main(): # We calculate the sum of all character in the text ic = 0 + allIC = list() for i in range(0, len(counts)): sum = (counts[i] * (counts[i] - 1)) - ic += sum / (totalLetters * (totalLetters - 1)) + currentIC = sum / (totalLetters * (totalLetters - 1)) + allIC.append(currentIC) + ic += currentIC print(f"Index of coincidence: {ic}") + largeur = 0.5 + y = list() + for alphabet in range(0, 26): + y.append(chr(ord('a') + alphabet)) + plt.bar(y, allIC, largeur) + plt.show() + if __name__ == "__main__": main()