Help i'm trying to descramble a file using a permutation as a key,i know how to scramble it but i need to create a function to descramble it back to what it was using the same permutation key, here's the code:
def stringtoarray(S):
A = []
i = 0
while i<len(S):
A.append(S[i])
i += 1
return A
def arraytostring(A):
S = ""
for c in A: # "for each element/value c in array A"
S = S+c
return S
#arraytostring
def scramble(S, P): #Scramble string S with permutation P
pn = len(P) # length of permutation array
E = (len(S) + pn - (len(S)%pn)) * [' '] # array of chars, padded
i = 0
while i< len(S):
seg = i/pn # segment number
j = i % pn # segment offset
E[ seg*pn + P[j] ] = S[i]
i += 1
# while
return arraytostring(E)
# scramble
print scramble("0123456789abcdefghij",[9, 14, 11, 19, 16, 18, 12, 6,
7, 15, 0, 5, 17, 4, 3, 10, 2, 1, 8, 13])
# prints ahgedb78i0f26j194c53
I want to set it back to string "0123456789abcdefghij" again