-1
$\begingroup$

I am working on a way to decipher some text generated by a small piece of code (see below).

This piece of code swaps letters in the sentence at random and was wondering if there where any techniques to solve this? I have tried frequency analysis, however because it is not a simple substitution cipher this does not work.

Here is the text:

NBWHJO MIIOI CAMC JSERIXSMBO FMQ QOOWHT M QWKMZSO WHJBOMQO WH OBBEBQ WH CBMXXWJ XEB WCQ JRQCEPOBQ ZOJMRQO CAO MCCMJV FMQ MXXOJCWHT WHXBMQCBRJCRBO NBEGWIOBQ SWVO TWCARZ. "WX M JRQCEPOB'Q QWCO WQ NEWHCWHT CE M TWC CAOBO, HEF FO JMH'C BOMJA TWCARZ," AO QMWI. "CAOBO MBO IOXWHWCOSY WHXBMQCBRJCRBO NBEGWIOBQ CAMC FO JMH'C BOMJA.

Here is the code (Python)

import random

def shuffle(string):
    string = list(string)
    for i in range(0, len(string)):
        # Choose two random letters in the string
        index_one = random.randint(0, len(string)-1)
        index_two = random.randint(0, len(string)-1)

        # Swap letters        
        buffer = string[index_one]
        string[index_one] = string[index_two]
        string[index_two] = buffer
    return ''.join(string)

$\endgroup$
  • $\begingroup$ Unless you know the RNG seed, there's no way to reverse that. $\endgroup$ – SEJPM Mar 15 at 14:15
1
$\begingroup$

This is a simple transposition cipher—effectively, a very long anagram. It might be possible to exploit the nonuniform distribution on the permutation of positions—a standard Knuth shuffle works a little differently to give all permutations of positions equal probability—but probably standard anagram algorithms can enumerate possible solutions that are sequences of (e.g.) valid English words to find candidate plaintexts.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.