Created
February 28, 2020 09:31
-
-
Save ahmed4end/ea25872c24ace320d97052f0e1aa25ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
text = "attack postponed untill two am".replace(' ','') | |
key = 4312567 | |
sliced = [ int(k) for k in str(key) ] | |
#a special function to calculate how many cells at least it would take to store the key and text into a matrix. | |
least_cells = lambda x=1: x*len(sliced) if x*len(sliced) >= len(text)+len(sliced) else least_cells(x+1) | |
rows = least_cells() // len(sliced) | |
matrix = [] | |
step = 0 | |
for i, j in enumerate(sliced): | |
step = 0 | |
col =[j] | |
for r in range(rows-1): | |
try:col.append(text[i+step]) | |
except:pass | |
step += len(sliced) | |
matrix.append(col) | |
matrix = sorted(matrix, key=lambda x:x[0]) | |
for i in matrix: | |
for j in i: | |
if isinstance(j, str): | |
print(j, end="") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment