Rename files
This commit is contained in:
parent
63d0dd32f1
commit
34fda59784
@ -2,45 +2,14 @@
|
||||
|
||||
from argparse import ArgumentParser
|
||||
import matplotlib.pyplot as plt
|
||||
from lorem import text as loremtext
|
||||
from functions import readFile
|
||||
|
||||
|
||||
def checkArguments():
|
||||
args = ArgumentParser(description='Cryptanalyst')
|
||||
args.add_argument('-f', '--filename', help='Text to analyze')
|
||||
args.add_argument('-s', '--stats', help='Statistics', action='store_true')
|
||||
args.add_argument('-d', '--decrypt', help='Decrypt Caesar text', action='store_true')
|
||||
return args.parse_args()
|
||||
|
||||
def stats(file=None):
|
||||
"""
|
||||
This function get a stats of all letter occurrence in a text
|
||||
"""
|
||||
if file is None:
|
||||
dataFile = loremtext()
|
||||
else:
|
||||
dataFile = file
|
||||
|
||||
lettersOccurence = []
|
||||
|
||||
# Init our tab
|
||||
for i in range (0, 26):
|
||||
lettersOccurence.append(0)
|
||||
|
||||
letterToAscii = ord('a') # Get the ASCII code
|
||||
for letter in dataFile:
|
||||
l = ord(letter) - letterToAscii
|
||||
if l >= 0 and l <= 26:
|
||||
lettersOccurence[l] += 1
|
||||
|
||||
x = [chr(letter + 65) for letter in range(0, 26)]
|
||||
y = [tmp for tmp in lettersOccurence]
|
||||
|
||||
largeur = 0.5
|
||||
plt.bar(x, y, largeur)
|
||||
plt.show()
|
||||
|
||||
def decryptCaesarText(cipherFile):
|
||||
"""
|
||||
This function breach the caesar ciphertext with all key
|
||||
@ -82,17 +51,11 @@ def getNewLetter(letterAscii, letterToAscii, key):
|
||||
res = ((letterAscii - key) % 26) + letterToAscii
|
||||
return chr(res)
|
||||
|
||||
def main():
|
||||
if __name__ == "__main__":
|
||||
args = checkArguments()
|
||||
cipherFile = None
|
||||
|
||||
if args.filename:
|
||||
cipherFile = readFile(args.filename)
|
||||
|
||||
if args.stats:
|
||||
stats(cipherFile)
|
||||
if args.decrypt:
|
||||
decryptCaesarText(cipherFile)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
decryptCaesarText(cipherFile)
|
48
stats.py
Normal file
48
stats.py
Normal file
@ -0,0 +1,48 @@
|
||||
# coding: utf-8
|
||||
|
||||
from argparse import ArgumentParser
|
||||
import matplotlib.pyplot as plt
|
||||
from lorem import text as loremtext
|
||||
from functions import readFile
|
||||
|
||||
|
||||
def checkArguments():
|
||||
args = ArgumentParser(description='Cryptanalyst')
|
||||
args.add_argument('-f', '--filename', help='Text to analyze')
|
||||
return args.parse_args()
|
||||
|
||||
def stats(file=None):
|
||||
"""
|
||||
This function get a stats of all letter occurrence in a text
|
||||
"""
|
||||
if file is None:
|
||||
dataFile = loremtext()
|
||||
else:
|
||||
dataFile = file
|
||||
|
||||
lettersOccurence = []
|
||||
|
||||
# Init our tab
|
||||
for i in range (0, 26):
|
||||
lettersOccurence.append(0)
|
||||
|
||||
letterToAscii = ord('a') # Get the ASCII code
|
||||
for letter in dataFile:
|
||||
l = ord(letter) - letterToAscii
|
||||
if l >= 0 and l <= 26:
|
||||
lettersOccurence[l] += 1
|
||||
|
||||
x = [chr(letter + 65) for letter in range(0, 26)]
|
||||
y = [tmp for tmp in lettersOccurence]
|
||||
|
||||
largeur = 0.5
|
||||
plt.bar(x, y, largeur)
|
||||
plt.show()
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = checkArguments()
|
||||
|
||||
if args.filename:
|
||||
dataFile = readFile(args.filename)
|
||||
|
||||
stats(dataFile)
|
Loading…
Reference in New Issue
Block a user