# coding: utf-8 from collections import Counter from argparse import ArgumentParser def checkArguments(): args = ArgumentParser(description='Cryptanalyst') args.add_argument('-f', '--filename', help='Text to analyze') args.add_argument('-b', '--bigram', help='Get bigram', action="store_true") args.add_argument('-t', '--trigram', help='Get trigram', action="store_true") return args.parse_args() def readFile(filename): """ This read the file passed in argument and return the data of it """ text = str() with open(filename, 'r') as f: data = f.readlines() for entry in data: text += entry return text def getLetters(text, pos): # return Counter(text[idx : idx + pos] for idx in range(len(text) - 1)) ###### TODO # Sorted by value and to get x data from the dictionary return Counter([text[idx: idx + pos] for idx in range(len(text) - 1)]) if __name__ == "__main__": args = checkArguments() text = readFile(args.filename) if args.bigram: data = getLetters(text, 2) if args.trigram: data = getLetters(text, 3) print(data)