Skip to content

Instantly share code, notes, and snippets.

@ahmed4end
Created February 28, 2020 09:31
Show Gist options
  • Save ahmed4end/ea25872c24ace320d97052f0e1aa25ff to your computer and use it in GitHub Desktop.
Save ahmed4end/ea25872c24ace320d97052f0e1aa25ff to your computer and use it in GitHub Desktop.
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