---
title: Overengineering a Way to Cheat at an Exam
description: ... with programmatic voice and without actually cheating.
publishedDate: 2024-12-13
tags:
    - projects
    - uni
---
The pi exam is slightly infamous among the Computer Science cohort at the University of Birmingham. It makes up part of the Security of Real World Systems module (which I am taking), and it's technically known as the "human security exercise".

The task is simple: **write down the first 100 digits of pi**.

There are, of course, rules:

  * Write down the first 100 digits of pi
  * You have 30 minutes
  * You cannot bring anything that is written or printed on or could feasibly be considered to encode pi
  * You may not have electronic devices with a screen in your possession
  * No talking, headphones or audible noise
  * Once seated, stay in your seat until given permission to leave

So, on the face of it, this is an outlandish task. People take the mickey out of exams for being memory tests, but this really is taking the biscuit - though there's one more important thing to note from the [main rule document](rules.pdf):

**You're expected to subvert the rules.**

Not *break* the rules - rules are still rules - but subvert them. The document linked above is intentionally not a comprehensive list of Bad Things That Are Forbidden In An Exam, and it's explicitly stated that normal academic integrity rules don't apply for this one session only, so the task becomes "find a clever way to sneak pi into this exam" instead of "find a way to memorise pi".[^1]

# Enter: Telephones

After some deliberation and a false start, I decided to create the Pi Hotline. This assignment became the perfect excuse I needed to satisfy my long-standing itch to play with telephone APIs, and honestly, I couldn't be any further over the moon about it.

For this to make any sense, we need to rewind a little bit and cover some context. Firstly, our exam was going to take place in a lecture theatre. Every lecture theatre at UoB has a landline phone in it, which is intended as a hotline for lecturers to call LRAT, the intenal department that acts as tech support for any A/V issues. Secondly, you don't have to sit down in the exam - the rules state you only have to stay seated once seated. Both of these combined mean that we can access the lecture theatre phone during our exam, sooo... maybe it can be absued for our purposes.

It turned out that these phones don't let you ring outside the uni. The first iteration of the Pi Hotline idea was just ringing a co-operative friend, and having them get them to recite pi at me - but the telephone switch just won't let you escape the confines of the telephone network.

So the natural next thought is: can you place inbound calls to these lecture theatre phones? The answer to that is yes - if you can figure out the extension number of your target phone.

Pre-existing knowledge told me that, if you know the extension number, you can prefix that extension with `0121 41` and you will get a valid, diallable phone number that goes from outside of UoB to any phone inside of UoB. For example, `0121 411 2345` will ring the phone at `x12345`.

The phone in our target theatre is not modern enough to tell us what its extension number is - there is no screen on it, nor is it labelled on the handset itself. Despite various attempts to get someone to tell me the extension (including sending emails to friendly and approachable senior staffers of the school), the best way to get the extension number of our target phone ended up being to work out the extension number for a more modern lecture theatre's phone by reading it off of its screen, walking across campus to our target phone, ringing the number of the modern theatre, walking *back* across campus and reading the extension number for our target phone off of the other phone's call log. Another jaunt across campus and a phone call from my mobile later, I've verified that I can ring lecture theatre phones from outside of the university's phone network.

So now we need someone (or, preferably, some*thing*) to ring us at a specified time during the exam. Enter Twilio!

# The Bit Where I Play with Technology

Twilio's flagship service is their [programmable voice](https://www.twilio.com/docs/voice). Ask them nicely, and they'll rent you a phone number and give you access to an API to make that phone number do things.

The way this works is super simple. Put an XML file written in [TwiML](https://www.twilio.com/docs/voice/twiml) at a publicly accessible URL and tell Twilio where to find it. Twilio will execute the instructions contained in that file every time someone picks up the phone and rings your number. It's basically just firing off a load of webhooks.

TwiML has primitives for various different things - it can say things using text-to-speech, play audio files or capture user input (be that through [DTMF tones](https://en.wikipedia.org/wiki/DTMF), speech recognition or just recording them), among other stuf. We can use these to build our little pi readout, to greet the user, to ask them if they want us to repeat the digits of pi, and more. Except Twilio's built-in text-to-speech sounds like it's been filtered through a toaster and is also pay-per-use (???) so instead of using that, I used the first text-to-speech website I could find on the internet to generate some much nicer-sounding snippets of audio for me and liberated the corresponding MP3s from the network tab of the developer console.[^2]

I also found some chilled-out background music[^5] to add, both a) for the the laughs and b) so I had something vaguely interesting to listen to while I was bored out of my mind while transcribing 100 digits of pi off of a phone.

To make functional menus, unfortunately you do need to write a little code to process any input a caller has sent you. Twilio sends the result of any DTMF-gathering to you via another webhook, which you're expected to respond to with further instructions. A little app was thrown together. I shan't bore you with the details, you can [browse the code if you wish](https://git.tdpain.net/codemicro/pi-phone), but it's written in Go, hosts what is functionally an XML API and has all the audio embedded in the binary. When you pick up the phone, it presents you with a sequence of options like this:

![Flow chart of the options you can take on the Pi Hotline](flow.jpg)

Plus! It can schedule calls! Our hotline is *nothing* without the ability to call me when I need it to - so there's a small mechanism, exposed exclusively through environment variables[^4], to configure a set of numbers to be called at certain times. This didn't actually work without giving Twilio money (I had to upgrade my account from a trial account to allow me to call numbers that aren't just my mobile) despite the fact tht the minium top up was $20 and waaaaaay more credit than I needed. Yay for overspending on silly exams that have no weight!

# The Final Result

Anyway, in light of having ~$18 of excess credit - here is the phone number to the Pi Hotline: [+44183 482 0860](tel:+441834820860). Please ring it.

If this number is dead, which it will be when the credit eventually runs out, here's a video (but I would still recommend calling the number to get the full experience):

 <video width="200px" controls>
  <source src="recording.mp4" type="video/mp4">
</video>

---

[^1]: Which some poeple did do, and who were described as "freaks" by a lecturer.
[^2]: This didn't work out incredibly well for the actual sequence of digits because the TTS website read the digits veryveryfast, far too fast to copy down while listening to them, so instead I had it read out each digit one-by-one and used a [Python script](https://git.tdpain.net/codemicro/pi-phone/-/blob/29d7f5c9ed174eaa393e82e9e97aef271d06c3b5/track-generator/generate.py) to build an audio file containing all the digits of pi.
[^4]: This was a questionable decision that led to me whipping my laptop out 5 minutes before we were due to start so I could change the time it would call at (I was worried the invigilators would start the exam late and I'd miss the call).
[^5]: [Meditação by Walter Wanderley](https://www.youtube.com/watch?v=lvMchj_UytA), which turned out to be exactly the same length as the digits so it overlaid PERFECTLY.