-1

The following code scrambles the text randomly using step size, i want to write a function to unscramble and get the original string how to do it.

def scramble(plain):
    cipher = ""
    step = 7
    for x in range(0, step):
        for y in range(x, len(plain), step):
            cipher += plain[y]
    return cipher
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
harsha
  • 17
  • 5
  • It doesn't scramble it "randomly", it scrambles it with a very noticeable pattern. Try scrambling the letters of the alphabet, starting with the first 7 letters, then adding one letter at a time, and see the resulting pattern. Look for the pattern, and try writing the unscramble function yourself. If you have specific issues with your unscrambling code, we can try to help. – Gerrat Dec 04 '16 at 05:43
  • sorry i recognized the pattern could u help me figure it out how to reverse it I'm unable get a hold of it any clue would be appriciated – harsha Dec 04 '16 at 08:48

1 Answers1

0

Just reverse the pattern:

def unscramble(cipher):
    plain = [""] * len(cipher)
    step = 7
    i = 0
    for x in range(0, step):
        for y in range(x, len(plain), step):
            plain[y] = cipher[i]
            i += 1
    return ''.join(plain)
MotKohn
  • 3,485
  • 1
  • 24
  • 41