28 lines
892 B
Python
28 lines
892 B
Python
# solve.py
|
|
# Brute-force all possible shifts to recover the plaintext
|
|
|
|
def rot_custom(text: str, shift: int, alphabet: str = "qwertyuiopasdfghjklzxcvbnm") -> str:
|
|
alphabet_lower = alphabet.lower()
|
|
alphabet_upper = alphabet.upper()
|
|
result = []
|
|
|
|
for char in text:
|
|
if char in alphabet_lower:
|
|
idx = (alphabet_lower.index(char) + shift) % len(alphabet_lower)
|
|
result.append(alphabet_lower[idx])
|
|
elif char in alphabet_upper:
|
|
idx = (alphabet_upper.index(char) + shift) % len(alphabet_upper)
|
|
result.append(alphabet_upper[idx])
|
|
else:
|
|
result.append(char)
|
|
|
|
return "".join(result)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
encrypted = "RDC{rgzdji_sjd_phdb_mafyjlsx_qlfjgd}"
|
|
custom_keyboard = "qwertyuiopasdfghjklzxcvbnm"
|
|
|
|
for i in range(26):
|
|
print(i, rot_custom(encrypted, i, custom_keyboard))
|