Rename files
This commit is contained in:
parent
63d0dd32f1
commit
34fda59784
@ -2,45 +2,14 @@
|
|||||||
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from lorem import text as loremtext
|
|
||||||
from functions import readFile
|
from functions import readFile
|
||||||
|
|
||||||
|
|
||||||
def checkArguments():
|
def checkArguments():
|
||||||
args = ArgumentParser(description='Cryptanalyst')
|
args = ArgumentParser(description='Cryptanalyst')
|
||||||
args.add_argument('-f', '--filename', help='Text to analyze')
|
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()
|
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):
|
def decryptCaesarText(cipherFile):
|
||||||
"""
|
"""
|
||||||
This function breach the caesar ciphertext with all key
|
This function breach the caesar ciphertext with all key
|
||||||
@ -82,17 +51,11 @@ def getNewLetter(letterAscii, letterToAscii, key):
|
|||||||
res = ((letterAscii - key) % 26) + letterToAscii
|
res = ((letterAscii - key) % 26) + letterToAscii
|
||||||
return chr(res)
|
return chr(res)
|
||||||
|
|
||||||
def main():
|
if __name__ == "__main__":
|
||||||
args = checkArguments()
|
args = checkArguments()
|
||||||
cipherFile = None
|
cipherFile = None
|
||||||
|
|
||||||
if args.filename:
|
if args.filename:
|
||||||
cipherFile = readFile(args.filename)
|
cipherFile = readFile(args.filename)
|
||||||
|
|
||||||
if args.stats:
|
decryptCaesarText(cipherFile)
|
||||||
stats(cipherFile)
|
|
||||||
if args.decrypt:
|
|
||||||
decryptCaesarText(cipherFile)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
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