mercredi 19 octobre 2022

how to crack a random substitution text cypher?

i was reading about caesar cipher where the characters are simply shifted by a number life this:

l=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

def shift(l,n):
    res = l[n:] +l[:n]
    return res

we can then switch the function to 2 steps for the rights for example to get:

l_c2= ['c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b']

for encrypting the message one just has to substitute each chatacter in the original text with the shifted one. This method is very easy to break, because once you know the mirror of one characted, you know all others, even if we do not, we can try 26 shiftings to find the correct shift, its a small number of tests.

so i was thinking if i randomly reorder the elements of the list with:

import random

def randomReorder(l):
    return random.sample(l,len(l))

then i will get a list that looks like this;

l_r = ['f', 'e', 'l', 'r', 'p', 't', 'k', 'v', 'u', 'c', 'd', 'o', 'a', 'x', 'm', 'g', 'b', 'z', 'q', 's', 'h', 'j', 'i', 'n', 'w', 'y']

so if i subsitute the letters in the original text with these ones, if one know the key to one character, its hard to predict the others, because they are simpley randomly reordered, so for "hello" for example it become "vpoom". Can this method of crypting data be powerful?, or there are complicated ways that crackers use to break these cypher texts?




Aucun commentaire:

Enregistrer un commentaire