Strange — Rail Fence Cipher
XESXOR9/10/20261 min read
#crypto#custom#medium#rail_fence_decryption
Strange — Rail Fence Cipher
Platform: spbctf | Category: Crypto | Type: Challenge | Difficulty: Medium | OS: NA | Author: XESXOR | Date: 2026-03-08 | Status: Solved Techniques: rail_fence_decryption
Summary
Task: Decrypt a scrambled text file with mixed Russian/Latin characters. Solution: Rail fence cipher decryption with 4 rails reveals the flag.
Strange — Crypto Kids 2.0
Description
"Что это за набор букв?" (What is this set of letters?) with mixed Russian/Latin text file.
Analysis
Rail fence cipher — text is written in a zigzag pattern across N rails, then read row by row.
Solution
python read-only • copy allowed#!/usr/bin/env python3 def rail_fence_decrypt(ciphertext, rails): n = len(ciphertext) # Create zigzag pattern pattern = [] rail = 0 direction = 1 for i in range(n): pattern.append(rail) rail += direction if rail == 0 or rail == rails - 1: direction *= -1 # Count characters on each rail counts = [pattern.count(r) for r in range(rails)] # Distribute characters across rails rail_chars = [] idx = 0 for r in range(rails): rail_chars.append(list(ciphertext[idx:idx + counts[r]])) idx += counts[r] # Read according to pattern result = [] indices = [0] * rails for r in pattern: result.append(rail_chars[r][indices[r]]) indices[r] += 1 return ''.join(result) # Try different number of rails ciphertext = "..." # encrypted text from file for rails in range(2, 10): decrypted = rail_fence_decrypt(ciphertext, rails) if 'spbctf' in decrypted.lower() or 'flag' in decrypted.lower(): print(f"Rails={rails}: {decrypted}") # With 4 rails we get: # "SPBCTF Лучшее сообщество... flag: spbctf{REDACTED}" # vzlom = взлом (hack), relsa = рельса (rail)