Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

easy frequency analysis python

import collections

ALPHABET = "abcdefghijklmnopqrstuvwxyz"
ETAOIN = 'etaoinshrdlcumwfgypbvkjxqz'

def generate_caesar_key(offset):
    dictionary = {}
    index = 0
    for letter in ALPHABET:
        if index+offset >= 26:
            index -= 26
        dictionary.update({letter:ALPHABET[index+offset]})
        index += 1
    return dictionary

def switch_encode(string, key):
    encoded = ""
    for letter in string.lower():
        if letter in key.keys():
            encoded += key[letter]
        else:
            encoded += letter
    return encoded

def switch_decode(string, key):
    key = dict(zip(key.values(),key.keys()))
    decoded = ""
    for letter in string.lower():
        if letter in key.keys():
            decoded += key[letter]
        else:
            decoded += letter
    return decoded

def switch_crack(string):
    key = {}
    frequent_letters = collections.Counter(string).most_common()
    index = 0
    for letter in frequent_letters:
        if letter[0] in ALPHABET:
            key[ETAOIN[index]] = letter[0]
            index += 1
    return key
Comment

PREVIOUS NEXT
Code Example
Python :: tensor.numpy() pytorch gpu 
Python :: how to concatenate dataframe in python 
Python :: looping through nested dictionary to nth 
Python :: python dataclass 
Python :: how to make a discord bot in python 
Python :: how to use input in python 
Python :: python tqdm 
Python :: find max in a dataframe 
Python :: use django taggit in template 
Python :: How to Use Python all() Function to Check for Letters in a String using all function 
Python :: strip in python 
Python :: django createssuperuser 
Python :: python pd.Timestamp add days 
Python :: planet 
Python :: making gifs via python 
Python :: pandas head sort by colun name 
Python :: python strptime() 
Python :: # find out indexes of element in the list 
Python :: python pandas in list 
Python :: python async function 
Python :: how to enter a int in python 
Python :: python run batch file 
Python :: python red table from pdf 
Python :: python extract values that have different values in a column 
Python :: python join dict 
Python :: how to create a loading in pyqt5 
Python :: matplotlib twinx legend 
Python :: print for loop in same line python 
Python :: how to sort the dataframe in python by axis 
Python :: __str__ method python 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =