• Skip to primary navigation
  • Skip to main content

data Rebellion

Learning through Adventure

  • Home
  • Blog
  • Beginner Python Course
    • Preface – The Journey Ahead
    • Prologue – The Door
    • Chapter 1 – Arithmetic and Variables
    • Chapter 2 – Strings and Lists
    • Chapter 3 – Conditional Statements
    • Chapter 4 – Functions
    • Chapter 5 – Loops
    • Chapter 6 – Built-in Functions and Methods
    • Chapter 7 – Imports and Nesting
    • Chapter 8 – Opening the Door
    • Epilogue – Only the Beginning
  • About
  • Contact
You are here: Home / Demons & Dwarves / Intro to Python, Chapter 8 – Opening the Door

Intro to Python, Chapter 8 – Opening the Door

Updated March 25, 2021. Published November 8, 2017. 2 Comments

Baldric was suddenly standing in a crowd of soldiers. Not Imperial soldiers thankfully. These were more ragtag, wearing random bits of armor here and there. Some had swords and shields, though most had spears or clubs or long knives. One formidable-looking woman appeared to be wielding a frying pan. They were all hurrying away in some form of organized chaos, and once they cleared out Baldric had a look at his surroundings. He was back on the Teleportation Circle in the city, and the soldiers were all headed in the direction of the Imperial castle. It somehow loomed even larger than before and seemed to shroud the entire city in its shadow. Dark clouds circled its peak and thunder rumbled faintly. Baldric noticed a familiar voice nearby barking orders and ran over to see Cassandra.

“Baldric, thank the gods you’ve returned. There’s no time for explanations. We’re forcing our way to the castle, and we’ve got them outnumbered and on the run. And now with you here, victory is within our grasp. Imperial reinforcements from outside the city are surely on their way, so we must move with all haste. In the event our army can’t force its way into the castle, you and I will have to slip in and try to find the Door ourselves.”

Another batch of soldiers teleported onto the Circle. Cassandra gave a few directions to a nearby officer, and then led Baldric through the city streets at a run. He had to take care not to trip over all the corpses strewn about, rebels and Imperials alike.

Wheezing and cursing as he tried to match Cassandra’s pace, Baldric eventually arrived in the section of city just beyond the castle walls. Some minor skirmishes were still taking place, but it seemed the rebellion would have the area secured in short order. Rebels were taking up positions in buildings with views of the castle, fortifying positions and assembling siege weapons. Cassandra had her head together with several other rebel commanders. Baldric wanted a sandwich and a nap, but those could wait for the fall of the Empire.

Soon all grew quiet. The rebels were ready for the assault, tens of thousands of them surrounding the sprawling castle grounds. Those in the buildings and on roofs would provide cover for those who would be charging in. They had catapults and a battering ram prepared, and many ladders and grappling hooks if they still couldn’t get the gates open. Once the last of the skirmishes had subsided, it became quiet. Eerily so.

The double doors to a large fifth-story castle balcony opened, and out marched an ominous assortment of ornately armored individuals. The Board of Directors. And last out was an imposing masked figure clad in heavy red and black armor lounging on a throne that appeared to be walking on its own. A closer look revealed the throne to be composed entirely of living, breathing bodies, roped together into the likeness of a throne. Interns, Baldric suspected.

The space around this figure seemed to be leeched of its color. In fact, what little sunlight was able to break through the thickening clouds seemed to dim when he emerged. The aura he gave off was worse than death. Tedium. Obedience. There was no doubt about it, this was the Emperor.

Baldric saw the Emperor weave a quick spell, too fast for him to make out. Then he spoke in a deep commanding voice amplified many times louder than any normal one.

“Welcome my employees. I take it that you are upset with the way things have been managed. And I’ll admit that, were I in your position, I’d be upset too. You have to understand though that we simply don’t have the budget to satisfy everyone’s needs for food and sleep and meaningful social interaction. It was hoped that the free oxygen and ping pong tables would make up for these deficits, but unfortunately things have come to a head and we are in the process of implementing some new management practices.”

The voice vaguely tickled something in the back of Baldric’s mind. To everyone’s surprise, the gates to the castle grounds began slowly creaking open.

The Emperor continued. “You see, we realized that providing employees with any recompense at all, no matter how inconsequential, would mean less for us. So the question was, how do we keep all the employees of the realm doing their work without giving them anything in return? Threats and force only work so well, as evidenced by the feedback you’ve provided thus far.”

The gates were now open by a crack, and Baldric could see movement beyond. He also could have sworn he saw something around the Emperor’s neck for a moment. Almost like a black band of some sort, there just for an instant. Maybe he was seeing things.

“So today marks the beginning of a new era. An era of pure, mindless, elemental obedience. Never again shall you think for yourself. Never again shall you want for more. Never again shall you feel badly about your state of affairs, or try to better yourselves or your community. For it is my greatest pleasure to introduce to you the new paradigm in Imperial management: Plan Z.”

A massive axe materialized in the Emperor’s outstretched hand, and the blade glowed a deep crimson red.

Bodies streamed through the gates. They looked like fellow employees, aside from some missing flesh or limbs or chunks of head here and there. What they all had in common though was one or two glowing red eyes. Like water breaking through a dam they took off at a dead run toward rebel positions. Zombies, and fast ones too. Screams broke out from inside the nearby buildings, and Baldric heard sounds of battle from their rear flank.

The Emperor was still speaking as if nothing had happened. “You see, zombies are far more cost-effective than living people, requiring neither salary nor benefits, and all those savings go right back to us, the job creators, so we can create even more jobs. It’s a win-win-win. And when we demolish the non-essentials such as your homes and hospitals and so on, not to mention your offices, and remodel this city into one sprawling open office, just imagine the productivity! The free flow of ideas! Row after endless row of soulless, obedient automatons, all tirelessly executing on clerical busy work in extremely close quarters. Busyness is Progress indeed! And don’t worry, zombified employees are just as happy as living ones. Well, we haven’t received any complaints at least. So please, what do you say we all get on the same page, hmm? Simply throw down your arms and let the full glory of Plan Z carry you into the future of this great Empire!”

As the zombies were closing in a battery of spells erupted from the rebels, mangling the oncoming zombified horde with elemental destruction. But the zombies were too many and too fast, and soon the rebels were fighting in close quarters with the undead.

Baldric was stunned at the turn of events, but shook himself out of it, reminding himself that this was never going to be easy. A crowd of zombies scrambled over a nearby barricade and sprinted at him. While he was preparing a blast of flame, ice formed under the zombies’ feet, sending them tumbling over each over. As they tried to scramble back to their feet, icicles impaled each of them squarely between the eyes.

“It appears our brute force strategy is out. Time for Plan B,” said Cassandra. Shouting to the officers in earshot, she said, “Infiltration teams, execute Plan B. Everyone else, provide cover until we’re in. Then fall back to the Circle and teleport to safety if you must.”

Baldric followed Cassandra down a street to where a team of rebels were climbing down a manhole. Baldric sighed, “Looks like I’m taking the scenic route again.”

The sewers were eerily quiet after the carnage aboveground. About a hundred or so rebels were with Baldric and Cassandra, many of them exceedingly powerful Magic users. There were a few other similarly sized teams, each with one or two Logic users. Weak compared to Baldric, but the best the rebels had. These teams would be infiltrating the castle at other places and, with any luck, would catch the Imperials by surprise and have a fighting chance at opening the Door.

Cassandra addressed the group as they hurried along. “Now remember, the Emperor keenly aware of all Magical usage in the city. It’s possible that all the other activity would keep us from being noticed, but we don’t want to risk being discovered if we don’t have to.”

Before long they arrived at their entrance to the castle. With a quick hand motion from Cassandra one of the rebels slowly opened the hatch, which Cassandra had thought to unlock before events had gotten out of hand. The area was clear, and everyone filed up into the wine cellar, then out into a grand obsidian hall, the stained glass likenesses of leaders of old watching as they hurried along. Cassandra led them through corridor after corridor, stairwell after stairwell, climbing ever higher. After a time, a frown grew on Cassandra’s face.

“Cassandra, everything alright?”

“No, something is amiss. I’ve traversed these halls many times, and they just seem…off. Sometimes there are more doors than I remember, or fewer windows. I feel for a moment as if I’m in a part of the castle I’ve never seen, when suddenly I’ll recognize the next room, never expecting to have encountered it on our path. And I can’t get the Emperor’s voice out of my head. It was…different than it was even just a few days ago. It doesn’t matter though, we just need to focus on the mission.”

Eventually the windows disappeared entirely, substituted with sparsely-placed torches. Baldric thought the shadows from the dancing flames looked odd. They didn’t quite move how he expected them to.

Someone screamed behind Baldric. He looked back to see someone being pulled into the shadows. Black flickering arms were grabbing at the fellow, pulling him into the wall. Several others rushed to pull him back, though most of his body had already disappeared into the blackness. The rebels suddenly tumbled backwards, and found themselves holding their comrade’s severed limbs. Seeing this, everyone else began showering the walls of the corridor in flame. The shadows seemed to dance around the Magic, and arm after shadowy arm shot out grasping for the rebels. One warrior was grabbed from both sides of the hallway, and with a sickening snap an arm was pulled clean off before both halves of him were yanked into the darkness.

Baldric remembered the Magic he had seen flow through Geofram’s hammer before he slew the HR Manager, and he tried to recreate it. He wove all five elements in a complex pattern which collapsed into an orb that illuminated the area around him in a nearly blinding white, pure light. The remaining rebels scurried into the light’s shelter. The surrounding darkness seemed to be pressing in on the light, not allowing it to extend as far as Baldric would have expected. But those arms stayed away.

Cassandra nodded at Baldric. “Alright, everyone stay calm. We’re not far now. Lead on Baldric.”

The remaining party, maybe half what they started with, cautiously advanced. The further they went, the more forcefully the darkness seemed to press against Baldric’s light. It was becoming a bit of a strain to maintain it. Baldric turned a corner and saw the corridor was coated in something. It looked almost…fleshy. It was soft and warm under his feet. Cassandra examined the substance and said, “There is great evil ahead. Prepare yourselves.”

They soon came to a set of double doors throbbing with the fleshy, veiny growth. A young human rebel stepped forward and wove a compact mix of Wind and Fire. Cassandra nodded, and the weave detonated, blowing the doors wide open. Rebels streamed into an expansive room, spells readied, and stopped in horror. The room, once a meeting hall or antechamber of some sort, was completely coated in the fleshy substance, and embedded in it throughout the room’s floor, walls, and ceiling were clusters of what could only be described as large egg sacs.

Baldric carefully approached one and could make out a face through the fluid within. It was the face of a halfling. He recognized that face: it was his supervisor, Kevin! But something was different about him. His features were sharper, his jaw more pronounced. His skin seemed to be red and almost scaly. His eyelids flashed open, revealing solid black eyes. His mouth curled in a smile, baring a forest of crooked black teeth. Baldric lost his concentration on the light he’d been holding and instinctively lashed out with a beam of molten fire. It incinerated the egg sac and crashed through the wall beyond.

All at once the egg sacs began rupturing, and out crawled humanoids in varying states of demonic corruption. They all began channeling dark Magic, and in an instant the room was a maelstrom of Magical combat. Baldric was stunned when Cassandra flew through the air and kicked him with both legs straight in the chest. He flew backwards, propelled by an additional gust of wind, and found himself sliding on a path of ice, a moment later bursting through a pair of doors that had been at the far end of the room. He tumbled into an even larger, dome-ceilinged room in which he noticed two things. First, a massive throne composed of bones and gold. And second, beyond the throne, the Door he had seen in his dreams.

He ran to the Door and turned around to see the remaining twenty or so rebels including Cassandra retreat from the antechamber and weave a powerful Magical barrier across the doorway. He didn’t blame them. The room beyond was filled with monstrously disfigured Supervisors and Managers, screeching and howling as they tried to tear the barrier down.

Cassandra spoke up, her voice as cold and commanding as ever. “We are safe for the time being. Baldric, if you please, get that Door open.”

One of the other rebels spoke up, “Why don’t we just blow it down, ma’am? Let me have a shot at it.”

“Unfortunately it’s not that kind of door,” replied Cassandra. “More of a portal than a door, from what I can tell. Trust me, if there were any way in there besides solving that puzzle, I would’ve found it.”

Baldric turned back to the Door and studied it. It was just as it had been in his dreams.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
(dmsp rm rfc dmsprf nmucp) kglsq (rfpcc rgkcq lglcrccl)
((rcl rm rfc rfgpb nmucp) njsq mlc fslbpcb qgvrw mlc) bgtgbcb zw ruclrw qctcl
(rum rgkcq rfpcc rgkcq rfpcc rgkcq ruclrw rfpcc rgkcq rfpcc rgkcq rum fslbpcb rfgprw rfpcc rgkcq dmprw rfpcc) kglsq dgtc
rfc ufmjc lskzcp md rfc npmbsar md rfc yzmtc rfpcc gq rfc icw
"""
 
 
[
"----|---------------------------------------------------------------------0---",
" \_/ ",
" / | \ 0 0 0 ",
" \_|_/ ",
" | | ",
"-|-/|--|-----------------------------------------------------------0----------",
"----|-\-----------------------------------------------------------------------",
"----|/-----------0------0-----------------------------------------------------",
"---/|----------------------------------------0------0-------------------------",
" | 0 ",
" |\ ",
]
 
 
"""
ro ncdm oyy mn, ahz ro dueho qax xem
ymnudrn pm ddbigwj, amc yiq'pe zoplkycghna oscbdsm
ncaqqahcc ar hmjhgec, cewenhdq lcgc tgd snwpt
sgeh wlsvdr ndc rhcdfa, ync aamg gn xnul wpt
"""
 
 
"""
8813191238677333954665809213349646122194
3015595667663245206677258662604239718836
4431428926159036858913586646934493387784
2415423905479477475303429332505714485112
4090836065842116455582237940320444861841
8887593350492294228220622241460000717294
4955847547957801429318355097534895447954
7342296922244600793814495300151499126757
3076802599544010948629349194265749217345
4001893903317176122546504003906815939962
8428796996691959920597351056958454461881
4732394077366853306860112237237386161021
7871126702127244170489561553519315838470
2693690437372649049215349703278652470600
3015221909596231574709960176130567639024
0092004721669881955529429225102279034207
1330193718198499866240480029222396978969
9281228432921674821577765850343057221329
2779929871766974307119561522080156771664
7095071241828310135078223629923028803912
5453455582923797217620833928427273736063
7822533797916494440084693015546738131130
2640275104782204063786790634519992766829
2989314882818234607337721281487409823167
5734588734584493380447926820353540224813
5824663370552369365250850730508000154790
81377112162403735240993
"""
 
 
"""
pv-shwsub-hbbs-wbwuvffgs-uh-sosb-vdph-or
-huibtc-sw--wwucjhhss--hhousvjhgsapc-b-i
ooas-fgr-b-gvhohqwsarsa-wsfhus-hsuogsjsv
ibc--chg-rwab-qigro-zhwszrt-vsjohwfuo--w
vsgsh-h-csgbrr-ow-baccg-wigbqqsgp-gggbcz
asc-uhjrwossc-shhvg--q-fawouko-orb-oh-zz
vg-bsrckfs-n-froctwkmfchbto-iwfhbcrvsk-t
hmodvoh--fswzrvrzh--ssfhgo--susjudfhwb-s
"""

He quickly became lost in thought, trying to piece together everything he had learned and figuring out where to start. One of the rebels spoke up. “Look, they’re retreating!” It appeared the demons were scurrying away, having been unable to break through the barrier. “Wait a second, I see someone. Who is…” The explosion took out most of the wall along with the Magical barrier. The rebels were knocked off their feet, and the air was clouded with debris.

After a moment the dust began to settle, and Baldric could see a towering figure casually strolling into the room, the clink of its armor audible over the coughs and curses of the rebels. It was the Emperor, clad from head to toe in his demonically-fashioned armor, with his giant axe in hand glowing with a thirst for blood. Firebolts, ice shards, lightning, boulders, and more were all sent at the Emperor, a storm of Magical death streaming from the rebels. Many attacks he simply swatted away with inhuman speed, while others seemed to dart away from him and miss at the last instant. Baldric glimpsed it again, for sure this time, some kind of dark Magical collar around the Emperor’s neck, with a connecting leash that seemed to be coming from beyond the Door.

“This is hardly conduct befitting of Imperial employees. No, its performance reviews for all of you I’m afraid.” (cue battle music)

The Emperor channeled Magic Baldric had never seen, and the floor opened up beneath one employee, shadowy hands pulling him in. Distracted by the hellish spectacle, Baldric lost sight of the Emperor. He suddenly appeared beside another rebel and cleaved him clean in two. A storm of spells descended on his position, but he appeared to meld with the shadows, moving around the room like a bat in the night, slaying rebels wherever he appeared. His axe vanished, but with one hand he picked up a half-orc by the throat while also summoning a swirling shadowy vortex around him with the other. The vortex absorbed every spell the rebels sent at him, and they watched in horror as their friend flailed and gurgled in the Emperor’s grasp until he went limp. The same spells the rebels had cast then suddenly discharged out of the vortex back at their casters, mutilating all of the remaining rebels at once apart from Baldric.

The Emperor walked over to the corpse of Cassandra, a large, jagged icicle sticking out of her chest. “Hehehe, oh my dearest Moryggan. I take it you’re finished playing rebel now?”

A puddle of water grew and formed into Cassandra, and the corpse detonated in a burst of icy shrapnel. While the Emperor was off balance from the blast the floor and ceiling became coated in solid ice, and a furious stream of icicles descended on the Emperor from above, chasing him around the room. He just barely slipped on the ice, but it was enough for Cassandra’s attack to catch up to its mark. The Emperor raised his hand and wove a barrier to deflect the raging torrent of icy needles while the ice from the ground rose to encrust his feet and legs, working its way up to his torso. The ice was cracking with the Emperor’s attempt to break out, but it gave enough time for Cassandra’s final weave to complete, and a massive spike of ice shot diagonally from the floor straight into the Emperor’s chest and out his back. He stood still there for a moment in stunned silence.

“…Your performance review has concluded, Cassandra Winterheart. You are to be…Fired!” A flaming meteor burst through the castle wall and roared toward Cassandra. She erected an immensely thick barrier of ice in an instant, but the explosive force blew it apart and sent her flying across the room and slamming into the opposite wall. She didn’t get up.

The spike of ice melted, and the hole in the Emperor’s chest vanished as if it had never been. His armor clinked as he casually approached Baldric. The dwarf was frantically putting all his mental energies towards blocking out the chaos behind him and focusing on the Door. The Emperor spoke up behind him.

“And now we turn to you, Baldric Hightower, Aspiring Wizard. A lowly clerk who bought into the lies of an Imperial traitor, became an accomplice in the murder of the HR Manager, emptied the HR complex, and helped lead the assault on this castle. I almost want to turn you into a demon like the rest of the Magic users, as I suspect you’d be quite useful. But no, that will not be your fate. Far more fitting for you to be zombified and returned to your original station in life, wouldn’t you say?”

Baldric thought with every cell of his brain, trying to put all the pieces together, racking his mind for any flash of insight that could open this accursed Door, but with everything going on he couldn’t think straight.

“The process is quite painless, really. Just as you sometimes import Logic, your own consciousness will be imported to the Nethermind, where it will be digested and used to further its power. Your brain will be left with just enough faculty to continue performing clerical work, while your body will putrefy into a long-lasting, low-maintenance form. Consider it a promotion.”

It was too late. He could sense the Emperor’s Magic and felt the life force draining from his body. His cells were dying, putrefying into the perfect Imperial employee, while his mind was being ripped from his body. “At least I tried,” he thought.

His vision was going dark when out of the corner of his eye Baldric saw something fly though the air before impacting the wall in a cloud of dust. His vitality returned to him and he inhaled life back in his lungs. Baldric looked over to see the Emperor picking himself up out of a crater in the wall. A whirling figure flew across the room and with a spinning kick too fast for Baldric’s eyes to follow sent the Emperor flying once again. It was Doomboom! The half-orc ran across the room and tackled the Emperor, pinning him against the wall.

“Quick Baldric, the Door!”

With grim determination and utter focus, Baldric turned to the Door once more.

“Ah, I’ve seen this Magic before. You must be a monk from the Songwood. Quite a powerful one, too. The Nethermind will certainly enjoy consuming you,” said the Emperor calmly as he grabbed Doomboom’s hands and slowly began pushing the half-orc back.

It was starting to come together now for Baldric. The first part just required all the letters to be shifted twice, and the resulting instructions gave the number he’d gotten from performing Cassandra’s request what seemed like a lifetime ago.

Doomboom was drawing on more and more Magic now, channeling it into himself. His muscles were bulging grotesquely large, blood vessels audibly popping. With a shove he sent the Emperor back several feet into the stone wall. The Emperor continued on pushing back as calmly as ever. “And why, may I ask, are you so enthralled with this Door? Do you even know what lies behind it? Are you sure you want to know?”

The second part of the puzzle needed to be rearranged according to the numerical key obtained from the first part. This rearrangement resulted in a musical staff bearing a melody of sorts: ADDCABBAGE.

Despite an overwhelming effort from Doomboom that could have toppled most buildings, the Emperor was steadily forcing him back. Doomboom suddenly shifted his weight and with a roar threw the Emperor over his back and into the ground, which he followed with a blur of punches that after a few seconds put the Emperor through the floor entirely. Doomboom ducked just in time to avoid the slash meant to take his head from the Emperor who had somehow materialized behind him. The two darted around the room with Doomboom on the defensive now, desperately dodging an onslaught of lethal axe swings.

“When I convert both the word “cabbage” and the third part of the puzzle to numbers and add “cabbage” sequentially to every seven letters…I get a message!”

Doomboom ducked under a swing and with a low spinning kick swept the Emperor’s legs out from under him. He continued with his spin and brought his heel back around to connect with the Emperor’s head, knocking his helmet clean off.

“So now in this fourth part of the puzzle I’ll convert all the even numbers to 1 and the odds to 0, creating one large binary number. Then I convert this number to a new decimal number. And so now…aha, there’s a repeating pattern here! Every 10 characters is composed of the numbers 0 through 9, but not in order. Rearranging the fifth part of the puzzle accordingly, and deciphering by shifting the letters by some amount like the first part…”

Before the Emperor hit the ground he had reappeared floating high up in the center of the room. He threw back his head and cackled maniacally while black flames emanated from him. “You are powerful indeed, master monk. I thoroughly enjoyed our battle, it reminded me of my past life. But unfortunately your time is at an end.” The Emperor roared and a train of black flames in the likeness of a dragon came barreling through the wall at one end of the room, caught Doomboom in its jaws before he had a chance to react, and busted through the opposite wall. No trace of the half-orc remained. Throwing his head back once again, the Emperor lost himself in a fit of crazed laughter.

That laugh was somehow vaguely familiar. Baldric pushed the thought away. Finishing up the following Logic, he saw that the Door’s code was finally cracking under the computational weight of his weavings.

Click here to see the solution by Demons and Dwarves Champion Ken Mosher, a.k.a. /u/Specter_Terrasbane
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
from string import ascii_lowercase
from itertools import cycle, zip_longest
import re
 
inscription_1 = """
(dmsp rm rfc dmsprf nmucp) kglsq (rfpcc rgkcq lglcrccl)
((rcl rm rfc rfgpb nmucp) njsq mlc fslbpcb qgvrw mlc) bgtgbcb zw ruclrw qctcl
(rum rgkcq rfpcc rgkcq rfpcc rgkcq ruclrw rfpcc rgkcq rfpcc rgkcq rum fslbpcb rfgprw rfpcc rgkcq dmprw rfpcc) kglsq dgtc
rfc ufmjc lskzcp md rfc npmbsar md rfc yzmtc rfpcc gq rfc icw
"""
 
_CAESAR_CIPHERS = [str.maketrans(ascii_lowercase, ascii_lowercase[i:] + ascii_lowercase[:i])
for i in range(26)]
"""Translation mappings for each Caesar Cipher shift from 0 through 25"""
 
def rot_n(text, shift):
"""Perform a Caesar Cipher encryption with the given shift"""
return text.translate(_CAESAR_CIPHERS[shift % 26])
 
# Experimentation discovered that the correct shift was 2:
print(rot_n(inscription_1, 2))
 
## (four to the fourth power) minus (three times nineteen)
## ((ten to the third power) plus one hundred sixty one) divided by twenty seven
## (two times three times three times twenty three times three times two hundred thirty three times forty three) minus five
## the whole number of the product of the above three is the key
 
the_key_value = ((4**4) - (3 * 19)) * (((10**3) + 161) / 27) * ((2 * 3 * 3 * 23 * 3 * 233 * 43) - 5)
"""Integer value of the mathematical riddle above"""
 
print(the_key_value)
 
# 106479825301
 
# All numbers from zero to ten inclusive are present, so as a list, it becomes:
the_key = [10, 6, 4, 7, 9, 8, 2, 5, 3, 0, 1]
 
print(the_key, '\n')
 
inscription_2 = [
r"----|---------------------------------------------------------------------0---",
r" \_/ ",
r" / | \ 0 0 0 ",
r" \_|_/ ",
r" | | ",
r"-|-/|--|-----------------------------------------------------------0----------",
r"----|-\-----------------------------------------------------------------------",
r"----|/-----------0------0-----------------------------------------------------",
r"---/|----------------------------------------0------0-------------------------",
r" | 0 ",
r" |\ ",
]
 
def reorder_lines(lines, key):
"""Reorder lines according to the order given in key"""
return [lines[i] for i in key]
 
staff = reorder_lines(inscription_2, the_key)
 
print('\n'.join(staff))
 
## |\
## ----|-\-----------------------------------------------------------------------
## | |
## ----|/-----------0------0-----------------------------------------------------
## | 0
## ---/|----------------------------------------0------0-------------------------
## / | \ 0 0 0
## -|-/|--|-----------------------------------------------------------0----------
## \_|_/
## ----|---------------------------------------------------------------------0---
## \_/
 
def get_notes(lines):
"""Given an ASCII-art staff (list of 11 lines representing blanks and lines on
the treble clef staff), extract which notes (0's) are present.
Constraints / assumptions:
- scale runs only from D4 through G5
- no sharps or flats
"""
return ''.join('GFEDCBA'[note.index('0') % 7] for note in zip(*lines) if '0' in note)
 
print(get_notes(staff))
 
# ADDCABBAGE == "add cabbage"
 
inscription_3 = """
ro ncdm oyy mn, ahz ro dueho qax xem
ymnudrn pm ddbigwj, amc yiq'pe zoplkycghna oscbdsm
ncaqqahcc ar hmjhgec, cewenhdq lcgc tgd snwpt
sgeh wlsvdr ndc rhcdfa, ync aamg gn xnul wpt
"""
 
def add_keyword(text, keyword):
"""Decrypt text by adding the value (a=0, b=1, c=2, etc.) of the characters in keyword
to only the alphabetic characters in the given text, i.e.:
 
add_keyword('abcdef-ghijk=lmno', 'cabbage') ==>
a b c d e f - g h i j k = l m n o
+ c a b b a g e c a b b a g e c
------------------------------------
c b d e e l - k j i k l = l s r q
"""
key_characters = cycle(ascii_lowercase.index(c) for c in keyword)
return ''.join(c if not c.isalpha() else rot_n(c, next(key_characters)) for c in text)
 
print(add_keyword(inscription_3, 'cabbage'))
 
## to odds say no, and to evens say yes
## convert to decimal, and you're approaching success
## rearrange as implied, decipher like the start
## then answer the riddle, and bask in your art
 
inscription_4 = """
8813191238677333954665809213349646122194
3015595667663245206677258662604239718836
4431428926159036858913586646934493387784
2415423905479477475303429332505714485112
4090836065842116455582237940320444861841
8887593350492294228220622241460000717294
4955847547957801429318355097534895447954
7342296922244600793814495300151499126757
3076802599544010948629349194265749217345
4001893903317176122546504003906815939962
8428796996691959920597351056958454461881
4732394077366853306860112237237386161021
7871126702127244170489561553519315838470
2693690437372649049215349703278652470600
3015221909596231574709960176130567639024
0092004721669881955529429225102279034207
1330193718198499866240480029222396978969
9281228432921674821577765850343057221329
2779929871766974307119561522080156771664
7095071241828310135078223629923028803912
5453455582923797217620833928427273736063
7822533797916494440084693015546738131130
2640275104782204063786790634519992766829
2989314882818234607337721281487409823167
5734588734584493380447926820353540224813
5824663370552369365250850730508000154790
81377112162403735240993
"""
 
def even_odd_binary(n):
"""Return a text representation of a binary number, with as many bits
as there are digits in n. For each digit in n, if the digit
is even, the corresponding bit in the result is set.
"""
return ''.join('0' if digit in '13579' else '1' for digit in str(n))
 
def chunk(text, n):
"""Return a list of equal-sized (n characters) 'chunks' of text.
If the length of text is not evenly divisible by n, the smallest chunk will be the last.
"""
return [''.join(part) for part in zip_longest(*[iter(text)]*n, fillvalue='')]
 
def decode_4(s):
"""Decodes a string representation of an integer:
- join all lines into one large integer string
- convert it to an even_odd_binary string
- convert the resulting binary value to decimal
- split the string representation of this decimal into 10 digit chunks
"""
joined = ''.join(s.splitlines())
 
# to odds say no, and to evens say yes
binary = even_odd_binary(joined)
 
# convert to decimal, and you're approaching success
dec = int(binary, 2)
 
# Noticed that every set of 10 digits in the result was the
# digits 0 through 9 in some order:
chunked = chunk(str(dec), 10)
return [[int(digit) for digit in part] for part in chunked]
 
# Lists of the digits from 0 thru 9
rearrange_keys = decode_4(inscription_4)
 
print('\n'.join(map(str, rearrange_keys)), '\n')
 
inscription_5 = """
pv-shwsub-hbbs-wbwuvffgs-uh-sosb-vdph-or
-huibtc-sw--wwucjhhss--hhousvjhgsapc-b-i
ooas-fgr-b-gvhohqwsarsa-wsfhus-hsuogsjsv
ibc--chg-rwab-qigro-zhwszrt-vsjohwfuo--w
vsgsh-h-csgbrr-ow-baccg-wigbqqsgp-gggbcz
asc-uhjrwossc-shhvg--q-fawouko-orb-oh-zz
vg-bsrckfs-n-froctwkmfchbto-iwfhbcrvsk-t
hmodvoh--fswzrvrzh--ssfhgo--susjudfhwb-s
"""
 
# Noted that the sum of the lengths of the lists in rearrange_keys
# equals the number of characters in inscription five ...
assert sum(len(key) for key in rearrange_keys) == len(''.join(inscription_5.splitlines()))
 
def rearrange(text, keys):
"""Rearranges the characters in text according to the given keys orderings.
Each ten character substring of text, in sequence, is reordered by the corresponding
list in the list of lists of integers 'keys', by examining where the digits from
0 through 9 appear in the key (i.e. if 0 appears at position 8 in the key, then the
first - zeroth - character in the result should be the 8th character of the substring).
 
i.e. rearrange('abcdefghijklmnopqrst', [[9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]])
- 'abcdefghij' [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] ==> 'jihgfedcba'
- 'klmnopqrst' [0, 2, 4, 6, 8, 1, 3, 5, 7, 9] ==> 'kplqmrnsot'
- result: 'jihgfedcba' + 'kplqmrnsot' = 'jihgfedcbakplqmrnsot'
 
"""
# Constraints:
assert len(text) % 10 == 0 and sum(len(key) for key in keys) == len(text) and set(len(key) for key in keys) == {10}
return ''.join(part[key.index(i)]
for part, key in zip(chunk(text, 10), keys)
for i, __ in enumerate(key))
 
def decode_5(text, keys):
"""Decodes text by performing a rearrange(...) then a Caesar Cipher shift of 12"""
text = ''.join(text.splitlines())
# rearrange as implied,
rearranged = rearrange(text, keys)
 
# decipher like the start (experimented to discover needs shift of 12)
return rot_n(rearranged, 12)
 
riddle = decode_5(inscription_5, rearrange_keys)
 
print(riddle, '\n')
 
## in-the-beginning-the-great-serpent-had-but-one-gift-to-giveit-gave-these-to-numbers-and-mathematics-emergedit-gave-these-to-sound-and-music-filled-the-airit-gave-these-to-minds-and-consciousness-blossomedit-gave-these-to-raw-magic-and-all-the-wonders-of-wizardry-fountained-forthwhat-pray-tell-did-the-great-serpent-give
 
 
# Formatting the riddle (replace dashes with spaces, and add newlines in the appropriate places) for readability:
print(re.sub(r'(it|what)', r'\n\1', riddle).replace('-', ' '))
 
## in the beginning the great serpent had but one gift to give
## it gave these to numbers and mathematics emerged
## it gave these to sound and music filled the air
## it gave these to minds and consciousness blossomed
## it gave these to raw magic and all the wonders of wizardry fountained forth
## what pray tell did the great serpent give
 
## then answer the riddle, and bask in your art
## ... ?????
Click here to see an alternate solution by Honorable Mention awardee Dan Simon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# Initial imports.
import re
 
# I like Python 3 and it looks like you do too, but I always end up
# accidentally using Python 2 unless I check. So let's check our version.
from sys import version_info
 
if version_info[0] < 3:
raise Exception('Use Python 3!')
 
# We have five parts, let's put them in variables.
 
part1 = """
(dmsp rm rfc dmsprf nmucp) kglsq (rfpcc rgkcq lglcrccl)
((rcl rm rfc rfgpb nmucp) njsq mlc fslbpcb qgvrw mlc) bgtgbcb zw ruclrw qctcl
(rum rgkcq rfpcc rgkcq rfpcc rgkcq ruclrw rfpcc rgkcq rfpcc rgkcq rum fslbpcb rfgprw rfpcc rgkcq dmprw rfpcc) kglsq dgtc
rfc ufmjc lskzcp md rfc npmbsar md rfc yzmtc rfpcc gq rfc icw
"""
 
 
part2 = [
"----|---------------------------------------------------------------------0---",
" \_/ ",
" / | \ 0 0 0 ",
" \_|_/ ",
" | | ",
"-|-/|--|-----------------------------------------------------------0----------",
"----|-\-----------------------------------------------------------------------",
"----|/-----------0------0-----------------------------------------------------",
"---/|----------------------------------------0------0-------------------------",
" | 0 ",
" |\ ",
]
 
 
part3 = """
ro ncdm oyy mn, ahz ro dueho qax xem
ymnudrn pm ddbigwj, amc yiq'pe zoplkycghna oscbdsm
ncaqqahcc ar hmjhgec, cewenhdq lcgc tgd snwpt
sgeh wlsvdr ndc rhcdfa, ync aamg gn xnul wpt
"""
 
 
part4 = """
8813191238677333954665809213349646122194
3015595667663245206677258662604239718836
4431428926159036858913586646934493387784
2415423905479477475303429332505714485112
4090836065842116455582237940320444861841
8887593350492294228220622241460000717294
4955847547957801429318355097534895447954
7342296922244600793814495300151499126757
3076802599544010948629349194265749217345
4001893903317176122546504003906815939962
8428796996691959920597351056958454461881
4732394077366853306860112237237386161021
7871126702127244170489561553519315838470
2693690437372649049215349703278652470600
3015221909596231574709960176130567639024
0092004721669881955529429225102279034207
1330193718198499866240480029222396978969
9281228432921674821577765850343057221329
2779929871766974307119561522080156771664
7095071241828310135078223629923028803912
5453455582923797217620833928427273736063
7822533797916494440084693015546738131130
2640275104782204063786790634519992766829
2989314882818234607337721281487409823167
5734588734584493380447926820353540224813
5824663370552369365250850730508000154790
81377112162403735240993
"""
 
 
part5 = """
pv-shwsub-hbbs-wbwuvffgs-uh-sosb-vdph-or
-huibtc-sw--wwucjhhss--hhousvjhgsapc-b-i
ooas-fgr-b-gvhohqwsarsa-wsfhus-hsuogsjsv
ibc--chg-rwab-qigro-zhwszrt-vsjohwfuo--w
vsgsh-h-csgbrr-ow-baccg-wigbqqsgp-gggbcz
asc-uhjrwossc-shhvg--q-fawouko-orb-oh-zz
vg-bsrckfs-n-froctwkmfchbto-iwfhbcrvsk-t
hmodvoh--fswzrvrzh--ssfhgo--susjudfhwb-s
"""
 
# Part 1:
 
# OK, this part is probably rather simple. Let's assume it's a Caesar cipher.
# [Of course with the benefit of hindsight we know it is and I actually
# tried decoding it as an arbitrary substitution cipher at first, but
# assuming Caesar cipher seems reasonable.]
# We don't know which one it is, but we can hope that everything in it is a
# word, so if we take the shift with the most words we can hope that's correct.
 
# First, how do we shift?
def shift_letter(letter, n):
return chr(ord('a') + (ord(letter) - ord('a') + n) % 26)
 
# Now, how do we shift text?
def shift_text(text, n):
return ''.join(
shift_letter(letter, n) if 'a' <= letter <= 'z' else letter
for letter in text
)
 
# Now, how do we count the number of words in text?
def count_words(text, set_words):
return len([i for i in re.findall(r'\w+', text) if i in set_words])
 
# Turn to false if you don't have /usr/share/dict/words or
# don't want my code accessing your files. It turns out not to matter.
has_words_file = True
 
def caesar_decrypt(text):
if has_words_file:
with open('/usr/share/dict/words') as f:
set_words = {i.strip().lower() for i in f.readlines()}
else:
# Just try some common words (from Wikipedia's list) and hope
# for the best.
set_words = {
'the', 'be', 'to', 'for', 'of', 'and', 'a', 'in',
'that', 'have', 'i', 'it', 'for', 'not', 'on', 'with',
'he', 'as', 'you', 'do', 'at', 'this', 'but', 'his', 'by', 'from'
}
best_shift = max(range(26), key=lambda n:
count_words(shift_text(text, n), set_words))
return shift_text(text, best_shift)
 
shifted_part1 = caesar_decrypt(part1)
 
# To confirm that everything's still working.
print(shifted_part1)
 
# Ok, the first three lines of shifted_part1 look like arithmetic expressions
# and the last looks like an instruction to take the product and use int.
# So let's evaluate the first three. We could write code to evaluate
# expressions that use names of numbers and operations, but that's clearly
# much harder than just writing everything out.
 
term1 = (4 ** 4) - (3 * 19)
term2 = ((10 ** 3) + 161) / 27
term3 = (2 * 3 * 3 * 23 * 3 * 233 * 43) - 5
 
key_part1 = int(term1 * term2 * term3)
 
# To confirm that everything's still working. Note that this key is mentioned
# in Chapter 1 and Chapter 2.
print(key_part1)
 
# Part 2 looks weird. It looks sort of like a fighter at the front, but that's
# probably an illusion. How many lines does it have?
print(len(part2))
 
# Aha, 11! And key_part1 has the first 11 integers in it.
int_list_key_part1 = [int(i) for i in re.findall(r'10|\d', str(key_part1))]
 
# Let's rearrange the lines of part2 by int_list_key_part1.
rearranged_part2 = [part2[i] for i in int_list_key_part1]
 
# Let's print rearranged_part2 joined by newlines.
print('\n'.join(rearranged_part2))
# Ah, that's better. Now we see that we're dealing with music.
 
# The top line (line 0) is G, so line n is n notes below G,
# which we can write as chr(ord('G') - n % 7).
def note_line_to_letter(n):
return chr(ord('G') - n % 7)
 
# It looks like each 0 represents a note. Let's find where the notes are.
note_locations = [
(i, j) for i in range(len(rearranged_part2))
for j in range(len(rearranged_part2[i])) if rearranged_part2[i][j] == '0']
 
# Sort by second item, index in row (when the note is played).
sorted_note_locations = sorted(note_locations, key=lambda x: x[1])
 
# Get and join notes. First item is lines number.
notes = ''.join(note_line_to_letter(i[0]) for i in sorted_note_locations)
 
# Let's see what the notes are.
print(notes)
# Aha, ADD CABBAGE! This might tell us what to do with part 3.
# (It is also directly related to the mention of "adding cabbages"
# in Chapter 3.) It seems to clue a vigenere cipher with key "cabbage",
# so let's try that.
 
# First we need to implement a vigenre cipher.
def add_letters(l1, l2):
return chr(ord('a') + (ord(l1) + ord(l2) - 2 * ord('a')) % 26)
 
# We don't want to accidently consider spaces letters, so let's take care.
def chars_with_letter_index(text):
result = []
letter_index = 0
for i in text:
result.append((i, letter_index))
if 'a' <= i <= 'z':
letter_index += 1
return result
 
def vigenre(text, key):
return ''.join(
add_letters(i, key[index % len(key)]) if 'a' <= i <= 'z' else i
for (i, index) in chars_with_letter_index(text))
 
deciphered_part3 = vigenre(part3, 'cabbage')
 
# Did our deciphering work?
print(deciphered_part3)
 
# OK, so we apparently must say no to odd numbers and yes to evens,
# whatever that means, but we presumably do it to part4 since
# that part has the most numbers, then convert the result to decimal.
# Let's do those steps and then see what happens.
 
# From Adam's comment I realized that saying no to odd numbers
# and yes to evens meant replacing odd and even digits by 0 and 1,
# respectively.
def replace_digit(d):
if d in '13579':
return '0'
elif d in '24680':
return '1'
else:
raise Exception('Huh?')
 
no_yes_part4 = ''.join(replace_digit(i) for i in part4 if i != '\n')
 
decimal_part4 = int(no_yes_part4, 2)
 
# OK, what do we have now?
print(decimal_part4)
 
# How long is it? That is, how many digits does it have?
str_decimal_part4 = str(decimal_part4)
print(len(str_decimal_part4))
 
# Are some digits more common than others?
print([str_decimal_part4.count(i) for i in sorted(set(str_decimal_part4))])
 
# They are all exactly equally common. In fact, by inspection it seems that
# dividing str_decimal_part4 into pieces of 10 digits gives pieces with each
# digit exactly once. Let's try dividing str_decimal_part4 into pieces of
# 10 digits, and convert each digit to an int too.
list_of_lists_part4 = [
[int(j) for j in str_decimal_part4[i:10 + i]]
for i in range(0, len(str_decimal_part4), 10)]
 
# What do we have now?
print(list_of_lists_part4)
 
# Does each item have each digit exactly once?
assert all(sorted(i) == list(range(10)) for i in list_of_lists_part4)
 
# Now it seems that we need to rearrange something, decipher like the start
# (perhaps another Caesar cipher), and solve a riddle which should come out.
# Maybe part5 becomes relevant here?
 
# Let's first assume the new lines in part5 are irrelevant.
stripped_part5 = part5.replace('\n', '')
 
# Now, what's the length of part5?
print(len(stripped_part5))
 
# The same as that of part4! Maybe we can divide part5 into pieces
# of length 10, rearrange each piece using the corresponding indices
# in the corresponding piece of part4, and then join everything!
parts_of_part5 = [
stripped_part5[i:10 + i] for i in range(0, len(stripped_part5), 10)]
 
rearranged_part5 = ''.join(
''.join(i[1] for i in sorted(
zip(part4_piece, part5_piece), key=lambda i: i[0]))
for part4_piece, part5_piece in zip(list_of_lists_part4, parts_of_part5)
)
 
# Let's see what we have.
print(rearranged_part5)
 
# Now the Caesar cipher. [Initially I decoded this
# by frequency analysis rather than looking for common words.]
deciphered_part5 = caesar_decrypt(rearranged_part5)
 
# What do we get?
print(deciphered_part5)
# Aha, a riddle. The answer would have to be the answer to that riddle.
Click here to see a solution using solely the concepts introduced in Demons and Dwarves
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
###############################################################################
# Part 1
 
p1_ciphertext = """
(dmsp rm rfc dmsprf nmucp) kglsq (rfpcc rgkcq lglcrccl)
((rcl rm rfc rfgpb nmucp) njsq mlc fslbpcb qgvrw mlc) bgtgbcb zw ruclrw qctcl
(rum rgkcq rfpcc rgkcq rfpcc rgkcq ruclrw rfpcc rgkcq rfpcc rgkcq rum fslbpcb rfgprw rfpcc rgkcq dmprw rfpcc) kglsq dgtc
rfc ufmjc lskzcp md rfc npmbsar md rfc yzmtc rfpcc gq rfc icw
"""
 
import string
alphabet = string.ascii_lowercase
 
# test out shifting all letters by all possible amounts (caesar cipher)
for shift in range(1, len(alphabet)):
p1_plaintext = ""
for char in p1_ciphertext:
if char in alphabet:
shifted_index = (alphabet.index(char) + shift) % 26
p1_plaintext += alphabet[shifted_index]
else:
p1_plaintext += char
print(p1_plaintext)
 
# shift of two letters up the alphabet results in following instructions
 
"""
(four to the fourth power) minus (three times nineteen)
((ten to the third power) plus one hundred sixty one) divided by twenty seven
(two times three times three times twenty three times three times two hundred thirty three times forty three) minus five
the whole number of the product of the above three is the key
"""
 
n1 = 4**4 - 3*19
n2 = (10**3 + 161) / 27
n3 = (2 * 3 * 3 * 23 * 3 * 233 * 43) - 5
n_final = n1 * n2 * n3
n_final_whole = round(n_final)
print(n_final_whole)
 
# 106479825301
 
###############################################################################
# Part 2
 
p2_list = [
"----|---------------------------------------------------------------------0---",
" \_/ ",
" / | \ 0 0 0 ",
" \_|_/ ",
" | | ",
"-|-/|--|-----------------------------------------------------------0----------",
"----|-\-----------------------------------------------------------------------",
"----|/-----------0------0-----------------------------------------------------",
"---/|----------------------------------------0------0-------------------------",
" | 0 ",
" |\ ",
]
 
# use Part 1's answer as key for rearranging list
key = [10, 6, 4, 7, 9, 8, 2, 5, 3, 0, 1]
for i in range(len(p2_list)):
print(p2_list[key[i]])
 
"""
" |\ "
"----|-\-----------------------------------------------------------------------"
" | | "
"----|/-----------0------0-----------------------------------------------------"
" | 0 "
"---/|----------------------------------------0------0-------------------------"
" / | \ 0 0 0 "
"-|-/|--|-----------------------------------------------------------0----------"
" \_|_/ "
"----|---------------------------------------------------------------------0---"
" \_/ "
"""
# this musical passage notated in treble clef contains the following melody:
# addcabbage
 
###############################################################################
# Part 3
 
p3_ciphertext = """
ro ncdm oyy mn, ahz ro dueho qax xem
ymnudrn pm ddbigwj, amc yiq'pe zoplkycghna oscbdsm
ncaqqahcc ar hmjhgec, cewenhdq lcgc tgd snwpt
sgeh wlsvdr ndc rhcdfa, ync aamg gn xnul wpt
"""
 
key = "cabbage"
p3_plaintext = ""
 
key_index = 0
for char in p3_ciphertext:
if char in alphabet:
# get current ciphertext and key character alphabetical indices
cipher_char_alpha_index = alphabet.index(char)
key_char_alpha_index = alphabet.index(key[key_index])
# advance ciphertext char's alpha index by key char's alpha index
new_char_index = (cipher_char_alpha_index + key_char_alpha_index) % 26
# attach character at new alphabetical index to plaintext
p3_plaintext += alphabet[new_char_index]
# advance to next key character index
key_index = (key_index + 1) % 7
else:
p3_plaintext += char
 
print(p3_plaintext)
 
"""
to odds say no, and to evens say yes
convert to decimal, and you're approaching success
rearrange as implied, decipher like the start
then answer the riddle, and bask in your art
"""
 
###############################################################################
# Part 4
 
p4_string = """
8813191238677333954665809213349646122194
3015595667663245206677258662604239718836
4431428926159036858913586646934493387784
2415423905479477475303429332505714485112
4090836065842116455582237940320444861841
8887593350492294228220622241460000717294
4955847547957801429318355097534895447954
7342296922244600793814495300151499126757
3076802599544010948629349194265749217345
4001893903317176122546504003906815939962
8428796996691959920597351056958454461881
4732394077366853306860112237237386161021
7871126702127244170489561553519315838470
2693690437372649049215349703278652470600
3015221909596231574709960176130567639024
0092004721669881955529429225102279034207
1330193718198499866240480029222396978969
9281228432921674821577765850343057221329
2779929871766974307119561522080156771664
7095071241828310135078223629923028803912
5453455582923797217620833928427273736063
7822533797916494440084693015546738131130
2640275104782204063786790634519992766829
2989314882818234607337721281487409823167
5734588734584493380447926820353540224813
5824663370552369365250850730508000154790
81377112162403735240993
"""
 
p4_string = p4_string.replace("\n", "")
binary_string = ""
 
# convert p4 number to binary as line 1 of Part 3 answer specifies
for char in p4_string:
if int(char) % 2 == 0:
binary_string += "1"
else:
binary_string += "0"
 
# convert binary number back to decimal as line 2 of Part 3 answer specifies
p4_answer = int(binary_string, 2)
 
print(p4_answer)
 
"""
7465308912724963105892736150841285093467217049365841695370289160732584301894562
7498071263598104576236219753840457018329667509214387419856203271435068998523716
0436542781905849072631279068435112548390761206759348649702835149015827360532419
8670925764381063897125410476382596705281934976401283505249618734936851702986104
7352
"""
 
# notice how every 10 digits contains every digit 0 through 9 inclusive
 
###############################################################################
# Part 5
 
p5_ciphertext = """
pv-shwsub-hbbs-wbwuvffgs-uh-sosb-vdph-or
-huibtc-sw--wwucjhhss--hhousvjhgsapc-b-i
ooas-fgr-b-gvhohqwsarsa-wsfhus-hsuogsjsv
ibc--chg-rwab-qigro-zhwszrt-vsjohwfuo--w
vsgsh-h-csgbrr-ow-baccg-wigbqqsgp-gggbcz
asc-uhjrwossc-shhvg--q-fawouko-orb-oh-zz
vg-bsrckfs-n-froctwkmfchbto-iwfhbcrvsk-t
hmodvoh--fswzrvrzh--ssfhgo--susjudfhwb-s
"""
 
p4_answer = str(p4_answer) # easier to work with as a string
p5_ciphertext = p5_ciphertext.replace("\n", "")
p5_orderedtext = ""
 
# using Part 4 answer's structure, reorder Part 5 ciphertext accordingly
 
# for every group of 10 characters, each containing digits 0-9
for i in range(int(len(p5_ciphertext) / 10)):
# create list of 10 empty strings
new_slice = [""] * 10
# get 10-character slice from ciphertext
cipher_slice = p5_ciphertext[i*10: i*10 + 10]
# get 10-character slice from Part 4's answer
order_slice = p4_answer[i*10: i*10 + 10]
# for each of the 10 numbers in ordered slice
for j in range(len(order_slice)):
# assign new slice, at given ordered index, the given ciphertext number
new_slice[int(order_slice[j])] = cipher_slice[j]
p5_orderedtext += "".join(new_slice)
 
# decipher reordered text like text from Part 1 (caeser cipher)
for shift in range(1, len(alphabet)):
p5_plaintext = ""
for char in p5_orderedtext:
if char in alphabet:
shifted_index = (alphabet.index(char) + shift) % 26
p5_plaintext += alphabet[shifted_index]
else:
p5_plaintext += char
print(p5_plaintext + "\n")
 
# a shift of twelve letters up the alphabet results in following riddle
 
"""
in-the-beginning-the-great-serpent-had-but-one-gift-to-give
it-gave-these-to-numbers-and-mathematics-emerged
it-gave-these-to-sound-and-music-filled-the-air
it-gave-these-to-minds-and-consciousness-blossomed
it-gave-these-to-raw-magic-and-all-the-wonders-of-wizardry-fountained-forth
what-pray-tell-did-the-great-serpent-give
"""

The final part of the puzzle resulted in a riddle:

In the beginning, the Great Serpent had but one gift to give.
It gave these to numbers, and mathematics emerged.
It gave these to sound, and music filled the air.
It gave these to minds, and consciousness blossomed.
It gave these to raw magic, and all the wonders of wizardy fountained forth.
What, pray tell, did the Great Serpent give?

A bolt of inspiration struck Baldric, and he shouted at the top of his lungs: “PATTERNS!”

The Door’s green inscriptions glowed bright and the heavy stone Door swung silently aside, revealing a pitch black entryway. Baldric rushed on through without looking back. Once beyond the doorway, he froze in awe at the sight before him.

He had entered another…place. Another world. He seemed to have solid footing but the surrounding environment was endless darkness in all directions. Two things, however, floated in the void. The first was a large crystal, humming and pulsing with a malevolent crimson energy. The second was a massive man of some sort. Not a human, but some sort of towering humanoid, several stories tall at least. His face was aged, wizened, and his eyes were closed. He appeared to be muttering to himself feverishly, as if in the midst of a nightmare. Suspending him in the air by his wrists were crimson chains, and more chains bound his feet. A black Magical leash around his neck led to the crystal. Something about him, the being’s aura perhaps, reminded Baldric of the presence he had felt in the place the Teleportation Circle had taken him.

The Emperor spoke up behind Baldric. He suddenly recognized that voice.

“Bahaha, congratulations on getting through the Door master dwarf. You haven’t failed to surprise me yet.”

“And you’ll be surprised again when I take you and this whole wretched Empire down…Geofram.”

Baldric turned around and saw what he dreaded he would. The Emperor’s helmet was gone, revealing an older yet still vigorous white-haired human with a pale, bloodless face framing glowing crimson eyes. The black leash connecting him to the crystal was clearly visible now. Despite the change in appearance, there was no mistaking him. The Emperor was Geofram Hammerfell, a.k.a. the Hammer of the Light.

“I see you’re upset, but don’t be so judgmental Baldric. If you had been offered such a lucrative position, be honest now, you would’ve taken it too. Nine-figure salary, stock options, sizable signing bonus, an office with a view…not to mention being allowed to work from home on Thursdays. The Nethermind is generous indeed. I was even given the pleasure of disposing of my predecessor. Which brings me to my next point: it’s finally time to dispose of you, my friend. Goodbye, Baldric Hightower.”

This time Baldric saw the zombification weaves coming at him, and he was preparing a counterattack when he saw Geofram’s weaves suddenly vanish. They seemed to have been cut apart and subsequently disintegrated.

Geofram, stunned, turned to stare at the crystal. He appeared to be talking to it. “But Great One, why!? Please allow me to do this, I wish only to serve! Allow me to import his mind to…” He shut up, horror written across his face.

Baldric’s head was suddenly filled with a voice that sounded like armageddon, a jarring force, overwhelming to the point of ecstasy, that made Baldric forget anything existed besides the voice itself.

“BALDRIC HIGHTOWER, MASTER WIZARD. YOUR POTENTIAL KNOWS NO BOUNDS. SERVE ME, AND WE SHALL REMAKE ALL OF CREATION IN OUR IMAGE.”

“Whatever you wish of me, my mast…” Baldric shook himself, remembering what was going on. “No, I’ll NEVER serve you, whatever it is you are, creature of the dark!”

“THINK OF THE MANAGEMENT EXPERIENCE, BALDRIC. MANAGING BOUNDLESS UNDEAD HORDES WOULD BE INVALUABLE TO HAVE ON YOUR RESUME.”

The voice both caressed him and shook him to his core. Listening to it was like freefalling into a warm, endless abyss.

“…You know what? I never thought of it like that before. I do really need to start thinking about my professional development. Alright. Yes, you have a…NOOO, get out of my head, monster! No, wait, don’t go! I…I can’t decide.”

Baldric grabbed his head, closed his eyes, and tried to sort his thoughts out. Something was seriously wrong here…

“BUT THAT WOULD ONLY BE THE BEGINNING. ONCE WE HAVE ENSLAVED THIS WORLD, WE SHALL SLAY THE GREAT SERPENT AND TAKE THE POWER TO WEAVE THE THREADS OF REALITY FOR OURSELVES. IMAGINE THE POSSIBILITIES. WITH SUCH POWER, YOU COULD DO WHATEVER YOU LIKE, EVEN MANUFACTURE ENDLESS MULTIVERSES OF NOTHING BUT PURE, ELEMENTAL ENSLAVEMENT, BUREAUCRACY, AND INCOMPETENCE. IMAGINE YOUR OFFICE, BUT MAGNIFIED BY THE INFINITY OF EXISTENCE.”

The pressure from the voice increased, and Baldric felt as if he was drowning in a raging river of fire, being carried down to the planet’s core.

“You’re right, how could I pass up an offer like that!? How STUPID of me! But wait…AHHH, my head! Alright, alright! Let’s…let’s just let fate decide! Heads I take your deal, tails I don’t!”

1
2
3
4
5
6
7
import random
 
coin = random.randint(0,1)
if coin == 0:
print("Heads")
elif coin == 1:
print("Tails")
1
Heads

The torrent of fire in his head ceased. All was silent. Still. He felt odd, dissociated, as if he was watching himself from afar.

“Heads. Huh. I guess…I guess I accept,” Baldric said to the voice in his head.

Immediately the leash around Geofram’s neck disappeared, and Baldric felt one form around his own. His body became awash in an ecstatic flow of malevolent energy that paled even in comparison to the blissful oblivion the voice had induced. He was connected now to hundreds of thousands of enslaved minds, all of them imprisoned within the Nethermind. And he could sense the sea of undead in the city, and the demons too. Every single one of them. They were all his to command.

Across from Baldric, Geofram looked confused. His eyes were no longer glowing red, and some color was returning to his face.

“Hey, Geofram.” Geofram looked over at Baldric, still obviously struggling to put together where he was and what was happening. “Import this.”

From Baldric’s outstretched hand shot a beam of darkness, somehow far darker than even the void. Upon impact Geofram dissolved, not only his body but the Logic underpinning his existence. Geofram wasn’t just destroyed. His past was destroyed as well, as if he simply hadn’t existed for some time.

Baldric, eyes radiating crimson, turned toward the Nethermind and bowed his head.

“Direct me, Great One.”

THE END

Python can help break the loop of boring office work

“ouro7” by Rex Housour, used under CC BY-SA 2.0, cropped original

<<< Chapter 7 – Imports and NestingEpilogue – Only the Beginning >>>

Python Automation Project Ideas Ebook Front Page

Free Ebook: 88 Python Project Ideas for Automating Your Life

The best way to learn programming is by working on real-world projects, so why not work on projects that also save you time and sanity? In this free, curated collection, you'll find project ideas for automating:

  • Common office tasks
  • Birthday gifts and wishes
  • Grocery and meal planning
  • Relationships (just the tedious parts!)
  • And quite a bit more

Subscribe to Data Rebellion and get this Ebook delivered straight to your inbox, as well as other exclusive content from time to time on efficiently learning to code useful things, vanquishing soul-crushing work, and having fun along the way.

Reader Interactions

Comments

  1. Mez says

    November 21, 2017 at 9:48 am

    Oh, no, balefire! 🙂

    Reply
    • Grayson Stanton says

      November 21, 2017 at 6:05 pm

      Ha, balefire indeed! Not enough to unravel the Pattern thankfully. The fact that someone got this made my day, thanks.

      Reply

Leave a comment Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Copyright © 2023

Terms and Conditions - Privacy Policy