Add chart for IC
This commit is contained in:
parent
2e8bf0bd9e
commit
b115533bfa
13
ic.py
13
ic.py
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from functions import readFile, countLetters
|
from functions import readFile, countLetters
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
def checkArguments():
|
def checkArguments():
|
||||||
@ -32,11 +33,21 @@ def main():
|
|||||||
|
|
||||||
# We calculate the sum of all character in the text
|
# We calculate the sum of all character in the text
|
||||||
ic = 0
|
ic = 0
|
||||||
|
allIC = list()
|
||||||
for i in range(0, len(counts)):
|
for i in range(0, len(counts)):
|
||||||
sum = (counts[i] * (counts[i] - 1))
|
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}")
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user