2024 Cyber Apocalypse: Dynasty

Challenge Information

AttributeDetails
Event2024 Cyber Apocalypse
CategoryCrypto
ChallengeDynasty
DifficultyVery Easy

Summary

Dynasty implements a custom Caesar cipher variant where each character is shifted by an amount equal to its position in the string (1-indexed). The cipher iterates through the plaintext and shifts alphabetic characters while preserving non-alphabetic characters. Decryption is trivial: reverse the process by shifting back.


Analysis

The encryption algorithm:

def encrypt(m):
c = ''
for i in range(len(m)):
ch = m[i]
if not ch.isalpha():
ech = ch
else:
chi = to_identity_map(ch) # Convert A-Z/a-z to 0-51
ech = from_identity_map(chi + i) # Shift by position i
c += ech
return c

Key points:

  1. Non-alphabetic characters pass through unchanged
  2. Each character is shifted left by its position (0-indexed)
  3. The shift wraps around using modulo 26
  4. The identity map treats uppercase and lowercase separately

Solution

Step 1: Create Decryption Function

The decryption simply reverses the shift:

def to_identity_map(a):
return ord(a) - 0x41
def from_identity_map(a):
return chr(a % 26 + 0x41)
def decrypt(enc):
flag = ''
for i in range(len(enc)):
ech = enc[i]
if not ech.isalpha():
m = ech
else:
echi = to_identity_map(ech)
m = from_identity_map(echi - i) # Reverse the shift
flag += m
return flag

Step 2: Load Encrypted Data

The challenge provides encrypted output in a file. Load and decrypt:

def load_data(filename):
with open('output.txt') as f:
f.readline() # Skip first line
enc = f.readline().strip()
return enc
encrypted = load_data('output.txt')
flag = decrypt(encrypted)
print(flag)

Example Walkthrough

For a small example with “AB”:

  • ‘A’ at position 0: shifted left by 0 = ‘A’
  • ‘B’ at position 1: shifted left by 1 = ‘A’
  • Result: “AA”

Decryption reverses this:

  • ‘A’ at position 0: shift right by 0 = ‘A’
  • ‘A’ at position 1: shift right by 1 = ‘B’
  • Result: “AB”

Key Takeaways

  • Simple substitution ciphers with small keying material are easily reversible
  • Position-dependent shifts are still deterministic and predictable
  • Non-alphabetic characters pass through unchanged, potentially providing known-plaintext attacks
  • The identity map approach with modulo wrapping is common but offers no real security