I have made a program to automatically apply an encryption I have developed. Within one particular bit of code, I keep on getting a "String Index out of range" error.
What does this code do?
The below code creates an array, d. It appends some section of a string to the array. The purpose of the code is to make a rectangle out of the text with width 5, meaning if the original text was "abcdefghijkl", then the idea is to turn this into
a b c d e
f g h i j
k l X X X
The last line of the code gives the error "string index out of range" Why? Earlier in the code, as I have forgotten to mention, I add X's to the end of the string so that it devides evenly into 5.
d = []
for x in range(1,length/5+2):
d.append(string[(x-1)*5:5*x])
d2=str(d).replace('[','').replace(']','').replace("'",'').replace(',','').replace(' ','')
lend2=len(d)
new=''
for i in range(1,lend2):
new += str([l[i-1] for l in d]).replace('[','').replace(']','').replace("'",'').replace(',','').replace(' ','')
Full error text:
new += str([l[i-1] for l in d]).replace('[','').replace(']','').replace("'",'').replace(',','').replace(' ','')
IndexError: string index out of range