This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import datetime | |
import nltk | |
from deap import base, creator, tools, algorithms | |
from matplotlib import pyplot as plt | |
from nltk import FreqDist | |
from nltk.corpus import brown | |
from timeit import default_timer as timer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for index, perm in enumerate(permutations([0, 1, 2, 3, 4, 5])): | |
permutation_cipher = PermutationCipher(perm) | |
if permutation_cipher.decrypt(cipher_of_cipher_data) == trimmed_cipher_data: | |
print(f"Found at epoch: {index}. Result is: {perm}") | |
break | |
index += 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import textwrap | |
class PermutationCipher: | |
def __init__(self, permutation): | |
self.permutation = permutation | |
self.permutation_transpose = [0] * len(self.permutation) | |
for index, value in enumerate(self.permutation): | |
self.permutation_transpose[value] = index |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
KWPXEZLZKMMTPDVHEBPACMPKBWABLZUMXOELPIXXATUUVMWQWZFEFTXIKJWVBWSOTFUAZDTXAMVPMJUEVOZVZBVHEPYUKWOQLAZELGZBYOXUINKKDVGVLHMNUIVEUNYITOMNUAOSLOZJAWMJYJPSGZKMVWPQGWUXRTHAVFCQLJJOCQGBYOSVKPRDSKHQZJPJEMKEOLHEYSRPOWYXSWYWJZMFLNXDTYVGCRTBPAUEOVGVQOCXEJWJWZVJRHSQMSLFTVKARJUQKACIXOOBJEEMGMVXDGGSSVTLHADFAGLWCRPLPXYOWVXWJJTJMSZDTYUTVZMUPIXPTZSNJQMNKWBFTXMXKHEPYKAOSQWBZELGZBYOVZGBPOOVGNJJWZCZZJTBUNBJRGUBYOHGAQURPAYWBJPWSNBRTYMZRJDVNWZDSQBNUKPTLKAEAPYBZZRPUMRZEZKJJZTVGVWECZBWAYJLENJQMFYWJNMNONBFMXRWCRPFXPVHRPPWWJMVOJKUXFMZVMPTSSJNPLMSTRXFNZZWDZSXCEEPYJCRTJMJCRTHYMWECUUITOMNMZZIUZUBYEHZBWAJWZKWFXDGGWKYDLUUPOLVTWPBEPUBLERSYBYXLYRWAZWQYXBYTQGYUORQXWUXCLPUPODGZQDAFJEZRNQZYIWECVSQWKEMKWCSOZLSJNPOYAAOOGBWUPCGTBYOLGLWBEUHUCLOCKVGCRTZDKAODKHMUOCGZBYOQGUMUSLXHCJZXTUABOOWSWUIMTYRJVJOPDVDPFXKAELGAITOSMGVVHEPYNARPFXARDSKYSPIEPYMVMPKUACSNTNMVXEZKJSIEVWQVSLGSNEOCKEJDJWVGVTRXTXNBRLZLAYOMFSGTHXZXTZJEZKQHXNTXSHXLYCZVDEPYQKDVYPAQXNFPYYJRVTWKDDHKWRNWQLQZJETYZRDSKVWWECZONBOJZLBKIWMMJDJEPYVRHZFYABXLYWMKKRPPIXSLLOWTECFYMCHXZXBKINZYKVLTJUIUXLGGERU |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from matplotlib import pyplot as plt | |
from tabulate import tabulate | |
from chi_squared import ChiSquared | |
from stats_collector import StatsCollector | |
tableau = { | |
0: "NOPQRSTUVWXYZABCDEFGHIJKLM", | |
1: "OPQRSTUVWXYZNMABCDEFGHIJKL", | |
2: "PQRSTUVWXYZNOLMABCDEFGHIJK", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from stats_collector import StatsCollector | |
LETTER_PROBABILITIES = {"A": 0.0856, "B": 0.0139, "C": 0.0279, "D": 0.0378, | |
"E": 0.1304, "F": 0.0289, "G": 0.0199, "H": 0.0528, | |
"I": 0.0627, "J": 0.0013, "K": 0.0042, "L": 0.0339, | |
"M": 0.0249, "N": 0.0707, "O": 0.0797, "P": 0.0199, | |
"Q": 0.0012, "R": 0.0677, "S": 0.0607, "T": 0.1045, | |
"U": 0.0249, "V": 0.0092, "W": 0.0149, "X": 0.0017, | |
"Y": 0.0199, "Z": 0.0008} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tabulate import tabulate | |
from stats_collector import StatsCollector | |
import matplotlib.pyplot as plt | |
desired_ioc_value = 0.065 | |
random_ioc_value = 0.038 | |
class IndexOfCoincidence: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
import matplotlib.pyplot as plt | |
class StatsCollector: | |
def __init__(self, data, label="input"): | |
self.data = data | |
self.label = label | |
self.freq_dict = {char: 0 for char in string.ascii_uppercase} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
class ShiftCipher: | |
def __init__(self, shift_size=3): | |
self.shift_size = shift_size % 26 | |
self.shifted = [] | |
for decrypted in string.ascii_uppercase: | |
encrypted = chr((ord(decrypted) - ord('A') + self.shift_size) % 26 + ord('A')) | |
self.shifted.append(encrypted) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public void solveSudoku(char[][] board) { | |
backtrack(board, 0, 0); | |
} | |
public boolean backtrack(char[][] board, int row, int col) { | |
//traverse from left top to bottom right | |
if (col == 9) { //checked all row elements, continue with the next one. | |
return backtrack(board, row + 1, 0); | |
} |