rail_fence
"/home/yossef/notes/personal/hashing/rail_fence.md"
path: personal/hashing/rail_fence.md
- **fileName**: rail_fence
- **Created on**: 2025-03-21 04:09:37
rail fence ;)
import numpy as np
# encrption rail fence
def encryption(plain_text: str, dim: int) -> str:
encryption_text = ""
# Calculate number of columns based on the text length and rows (dim)
column_matrix = len(plain_text) // dim + (len(plain_text) % dim != 0)
# Create an empty matrix with dimensions (dim x columns)
matrix = np.full((dim, column_matrix), '', dtype='<U1')
# Fill the matrix row by row
row, col = 0, 0
for char in plain_text:
matrix[row][col] = char
row += 1
# Move to the next column when we hit the last row
if row == dim:
row = 0
col += 1
# Read the matrix row by row to get the encrypted text
encryption_text = ''.join(''.join(matrix[row, :]) for row in range(dim))
return encryption_text
def main():
plain_text = "yossef"
"""
y s
o e
s f
-> ysoesf
"""
dim = 3
print("encryption:",encryption(plain_text, dim))
# encryption: ysoesf
if __name__ == "__main__":
main()
continue:[[]]
before:./vigenere_cipher2.md