I would like to split a string with the result being a string consisting only of every nth character of the original string. My first approach looks like this (and works):
#Divide the cipher text in the estimated number of columns
for i in range(0,keyLengthEstimator):
cipherColumns.append(cipherstring[i])
for i in range(keyLengthEstimator,len(cipherstring)):
if i % keyLengthEstimator == 0:
cipherColumns[0] += cipherstring[i]
elif i % keyLengthEstimator == 1:
cipherColumns[1] += cipherstring[i]
elif i % keyLengthEstimator == 2:
cipherColumns[2] += cipherstring[i]
elif i % keyLengthEstimator == 3:
cipherColumns[3] += cipherstring[i]
elif i % keyLengthEstimator == 4:
cipherColumns[4] += cipherstring[i]
I have the feeling, that there is a more efficient way to do it. In Matlab there would be the reshape function, is there a similar function in Python?