COSC312
Hwb: Turing machine project
April 16th 2026
Alexandre Renato Bueno dos Santos Filho
Mega Man 5 Password Decoder
The intent of this Turing Machine is to get a set of coordinates and the color of dots in a 6
x 6 grid from the game Mega Man 5 and return what state of the game that password represents.
In order to do that, I used the tables from the website “Strategy Wiki”
( https://strategywiki.org/wiki/Mega_Man_5/Password_Mechanics), on their article about Mega
Man 5 (it is important to not that I only used it as inspiration, I made some slight changes that I
think made it easier to make the Turing Machine, and the grid simulator in that page is very
faulty, so ignore it). The way that we interpret the coordinate system from Mega Man 5, is by
dividing the grid in 3 sections, one section is from columns 1 to 2, the second section are
columns 3 and 4, and the third are 5 and 6.
The way that the password works is that there are going to be blue and red dots in certain
coordinates in the grid, and for every of those sections that I just described, there is going to be
one red dot and one blue dot.
The red dots handle which Robot Masters were defeated, and each blue dot represents
which letters you collected through the stages, if you collect all of them, the word
“MEGAMANV” is formed, and you unlock a robot companion that attacks enemies.
TABLES:
Depending on where the red and blue dots are inserted, (either in the 1 st, 2nd or 3rd
sections), they will have different meanings, and sometimes there might be conflicts between the
blue dots and red dots, where the red dot is assigned to a specific coordinate in the grid, but a
blue dot would have to be assigned to that same coordinate, but may have to go to another one.
That is why I had to use the tables to see every coordinate each dot can be positioned and make
the Machine from that.
Red Dots
Section1:
Section 2:
Section 3:
Blue Dots
Section 1:
Section 2:
Section 3:
THE TURING MACHINE:
The first part of the Turing Machine is responsible for identifying the section that each
dot is in, and then go to the end of the input string and write “=01234567-01234567”, which is
going to be important for decoding afterwards:
This first section checks the first letter (either “r” for red or “b” for blue), switches it for
another letter (“e” for red, “l” for blue), goes forward to check the column of the dot, then search
back for a “#” and write the section that it is in. If we find a blank space, it means that the
Machine reached the end of the password, so it sets up the “=01234567-01234567”. Then it goes
back to the beginning of the string to start decoding the password:
The red region is responsible for interpreting the red dot that we have:
It reads the “e,” which means it is a red dot, then reads either “1,” “2” or “3”, which
indicates the region of the dot, and then reads the coordinate of the dot (while erasing the dot on
the process). Then it is going to interpret the case, move right until we find “=,” and then write it
into the “=01234567-01234567” string.
Each robot master is represented by a single letter, and since some of them have names
that start with the same letter, I had to be creative with some:
-
Gravity Man
Gyro Man
Crystal Man
Napalm Man
Stone Man
Charge Man
Wave Man
Star Man
=
=
=
=
=
=
=
=
G (because in physics we use “g” for gravity)
Y
C
N
S
Q (because in physics we use “q” for charge)
W
Z (because “star” in Russian is “звезда/zvezda”)
The way that I set it up is by the sequence that I consider to be the most efficient to finish
the game, which is by starting from the easiest stage, and going forward according to each Robot
Master’s weakness.
If the Machine identifies a 0, it will write G, if it reads 1, it will write Y and so on. So,
near the end of the Machine process, in a case where all Robot Masters were defeated, but no
letters collected:
-
=01234567-01234567
Should turn into:
-
=GYCNSQWZ-012346567
The blue region interprets each blue dot that it finds:
The way that it generally functions is like how we handle the red dot. It reads “l” for blue
dot, reads “1,” “2” or “3” for the region, and the coordinate. Then it goes right until it finds “-”
and writes what it just interpreted. It just has some extra complexity for when we have some
position conflict between the blue and red dot, on such case, in the red section, the machine goes
right until it finds “=” and sees which bosses were defeated or not and then writes up the case. If
nothing is found, then the Machine checks which red dot is taking the original spot where the
blue dot was supposed to be. The blue dots represent which letters you collected, so in a case
where you have collected all letters, but no robot masters were defeated:
-
=01234567-01234567
Turns into:
-
=01234567-MEGAMANV
After every dot has been read, the Machine goes through the final string and erases every
instance of a “#” and the “=” symbol, and finishes.
HOW TO WRITE THE INPUT:
As I described before, each dot is either red or blue, is in a certain region of the grid, and
has a coordinate, when writing the password, what you need to do is:
1. Write the color for the dot (r or b), followed by a “#”
2. Write the coordinate (letter first, number second)
Ex:
-
r#B1 (color: red, coordinate: B1)
Then you write the next dot right next to it, without any separation between them,
following the same rules
Ex:
Here we have:
-
A red dot in B1
A blue dot in B3
A red dot in D3
A blue dot in E5
A blue dot in F1
A red dot in F5
Final password
=
=
=
=
=
=
=
r#B1
b#B3
r#D3
b#E5
b#F1
r#F5
r#B1b#B3r#D3b#E5b#F1r#F5
How the dot sequence works:
Essentially, the dots can appear in any order you want, you can write in the sequence you
see in each section, sequence of what you see, red dots on one side and blue dots on the other
side, etc. In the example I just gave:
The password for this case is r#B1b#B3r#D3b#E5b#F1r#F5, but these other passwords are
essentially the same thing:
-
r#B1r#D3r#F5b#F1b#B3b#E5
b#F1b#B3b#E5r#B1r#D3r#F5
r#B1b#F1r#D3b#B3r#F5b#E5
r#B1r#D3r#F5b#F1b#B3b#E5
r#B1r#D3b#F1b#B3r#F5b#E5
PASSWORDS USED FOR ERROR TESTING:
To get the passwords and compare the results with the expected output, I used this link:
https://www.mmhp.net/Passwords/MM5/. This site allows you to select the items that you want
collected, the weapons and the letters, and returns the grid that will result in the desired state of
the game. I looked at those grids, and inserted them in the Machine, and compared the result with
what I selected. You can also use that website to get your own passwords and compare the
results. The website uses different names than I did, so here is what each letter represents in this
case:
-
G
Y
C
N
S
Q
W
Z
=
=
=
=
=
=
=
=
Gravity Hold
Gyro Attack + Rush Jet
Crystal Eye
Napalm Bomb
Power Stone
Charge Kick
Water Wave
Star Crash + Super Arrow
The example passwords followed by the expected results (“_” represents blank squares):
1. r#B1b#B3r#D3b#E5b#F1r#F5
=
________-________
2. b#B4r#C1r#D4b#D6b#F1r#F6
=
GYCNSQWZ-MEGAMANV
3. b#A2b#B3r#D3r#E2b#E5r#F5
=
___N____-______N_
4. r#B1b#C4b#E5b#F1r#F4r#F5
=
_______Z-____M___
5. r#B1b#B3r#B6r#D3b#E6b#F1
=
______W_-_E______
6. b#A2r#A6b#B3b#D6r#E2r#E3
=
GY_NS__Z-M_GAM_N__
These passwords were selected because they cover the complete case (everything
collected), the empty case (beginning of the game), and every possibility where there might be a
conflict between red and blue dots positioning, or cases where there are no conflicts.