Block Cipher

Demonstrates block cipher encryption using substitution and permutation operations. Text is divided into fixed-size blocks (4 characters) and each block is encrypted independently.

Input

Cleaned: BLOCKCIPHEREXAMPLEXX

Blocks: 5 (Block size: 4)

5
S-Box (Shift-based, Key: 5)
A-EF-JK-O
A→FJ→OS→X
B→GK→PT→Y
C→HL→QU→Z
D→IM→RV→A
E→JN→SW→B
P-TU-YZ
F→K
G→L
H→M
I→N
J→O
K→P
L→Q
M→R
N→S
O→T
P→U
Q→V
R→W
S→X
T→Y
U→Z
V→A
W→B
X→C
Y→D
Z→E
Permutation Pattern Reference

The permutation pattern [3,0,1,2] defines how characters are rearranged:

Output PositionTakes from Input PositionMapping
03Output[0] = Input[3]
10Output[1] = Input[0]
21Output[2] = Input[1]
32Output[3] = Input[2]
Encryption: Uses pattern [3,0,1,2] (shown above)
Decryption: Uses inverse pattern [1,2,3,0]
Position Movement Simulation

Understanding how each position moves in the permutation pattern [3,0,1,2]:

Position 0 Movementmoves 3 steps forward (to the end)
Original
Pos 0
→
0 → 3
After Permutation
Pos 3
Position 1 Movementrotates to the first position
Original
Pos 1
→
1 → 0
After Permutation
Pos 0
Position 2 Movementshifts one position left
Original
Pos 2
→
2 → 1
After Permutation
Pos 1
Position 3 Movementcompletes the cycle
Original
Pos 3
→
3 → 2
After Permutation
Pos 2

Complete Pattern Transformation: [3,0,1,2]

Input Positions:
0
1
2
3
↓
Pattern [3,0,1,2] Applied:
Takes
[3]
Takes
[0]
Takes
[1]
Takes
[2]
↓
Output Positions:
0
1
2
3
Example: If input is "ABCD", output becomes "DABC" (A from pos 0→pos 3, B from pos 1→pos 0, C from pos 2→pos 1, D from pos 3→pos 2)

Why Pattern [3,0,1,2]?

  • Non-Identity: Actually changes the position (unlike [0,1,2,3])
  • Maximum Diffusion: Every position moves to a different location
  • Reversible: Can be inverted to [1,2,3,0] for decryption
  • Educational: Shows diffusion/mixing principle in block ciphers like DES
Process Visualization
Block 1
Input:BLOC
Step 1:GQTH (Substitution)
Step 2:HGQT (Permutation)
Block 2
Input:KCIP
Step 1:PHNU (Substitution)
Step 2:UPHN (Permutation)
Block 3
Input:HERE
Step 1:MJWJ (Substitution)
Step 2:JMJW (Permutation)
Block 4
Input:XAMP
Step 1:CFRU (Substitution)
Step 2:UCFR (Permutation)
Block 5
Input:LEXX
Step 1:QJCC (Substitution)
Step 2:CQJC (Permutation)
Output
HGQTUPHNJMJWUCFRCQJC

Total Blocks

5

Block Size

4 characters

How It Works

Block Division

The plaintext is divided into fixed-size blocks of 4 characters. If the last block is shorter, it is padded with 'X' characters to ensure all blocks are of equal size.

Encryption Process

Step 1 - Substitution: Each character in the block is replaced using an S-box (substitution box) derived from the key. The S-box performs a shift-based substitution.

Step 2 - Permutation: The positions of characters are rearranged using a fixed permutation pattern [3,0,1,2], which means: position 0 gets character from position 3, position 1 from position 0, etc.

Decryption Process

Decryption reverses the encryption: Inverse Permutation → Inverse Substitution

Key

The key (1-25) controls the S-box generation. Different keys produce different substitution and permutation results, making the encryption secure.