Crypto Grid Cipher

Hard
cryptography grid diagonal-traversal encryption
Problem Description

Encrypt a message by writing it into an N×N grid row by row, then reading it diagonally from top-left to bottom-right. Handle padding and multiple diagonals.

Input Format
Two lines: message string and grid size N.
Output Format
Encrypted message read diagonally from the grid.
Constraints
• 1 ≤ message length ≤ 1000
• 1 ≤ N ≤ 50
• Pad with 'X' if message shorter than N²
• Read all diagonals from top-left to bottom-right
• Include spaces and punctuation in message
Sample Input/Output
Input:
HELLO WORLD
4
Output:
HLXEORXLWXLDX
Explanation

Fill 4×4 grid row by row with "HELLO WORLD" + padding, then read diagonally.

Solution Hints
135
Points
3000ms
Time Limit
256MB
Memory Limit
Code Editor
Register to Submit
Register to Access Code Editor

Create a free account to solve coding problems and track your progress.

Register Now
Feedback