At the end of 2012 I was doing some research on ciphers and cryptology. I wanted to see all of the different ciphers and learn a bit more on how to identify a cipher. In doing this research I began to think of how I could create my own custom cipher. Looking at all of the ciphers, I noticed that there were not any listed in a triangle format. This is most likely because it’s not the most efficient matrix for a cipher.


I then thought, well how could I make a cipher using a pyramid. That is when I came up with the pyramix (pyramid matrix). The pyramix is made up of two separate matrices; a left matrix and a right matrix. I had 6 rows and and 11 columns with the middle column (6) being able to be a part of either the left or the right matrix.

Left Side

Right Side


I needed a way to determine which side of the matrix I am referencing beyond just x and y. That is when I realized I could use a similar technique to the Trifid cipher and use a 0 to denote ‘left’ or ‘right’. This would give me a 3 digit reference for the letter in the form of XYX. Depending on which X had the 0 would indicate the side of the matrix to use. The remaining x,y or y,x coordinates would reference the letter.

I color coded this to help myself and others.

For example, let’s take the letter P.
P is in the 'right' matrix.
Therefore the 0 will be at the end of XYX. Giving us XY0.
Then we are left with X,Y.
So, the x,y of P is 3,4.
This gives us 340.

Now let’s look at the letter J. You would think it’s 034 but you’d be incorrect.
J is in the 'left' matrix.
Therefore the 0 will be at the beginning of XYX. Giving us 0YX.
We are left with Y,X (not X,Y).
The Y,X of J is 4,3.
This gives us 043.

Now the fun part is column 6. You could choose to go either direction either left or right. So if we look at M it can be 046 and it can be 640. This allows for some words with the middle column letters to encipher differently. For example, let’s take the word Pyramid.

P = 340
Y = 250
R = 053
A = 016 or 610
M = 046 or 640
I = 430
D = 520

You could then write this out as:
340 250 053 016 046 430 520 or
340 250 053 016 640 430 520 or
340 250 053 610 046 430 520 or
340 250 053 610 640 430 520.

But, even with all of this it’s still just a simple substitution cipher. Once you started to figure out the patterns, it would not be that hard to write a script to decipher this quickly.

That’s when I decided to implement some transposition and write the 3 digit code vertically. I wrote the code like this:

Then I used transposition to write the cipher in a single string writing out the entire row of the first X, then Y, then the last X like this:

As a final step to my cipher, I realized that the largest number I had was a 6. This meant I could do a simple ROT(1-3) to create another layer of randomness. I could obviously only go up to 9.
ROT 1 = 431115656625431147711
ROT 2 = 542226767736542258822
ROT 3 = 653337878847653369933

This meant that the word PYRAMID would encipher to 16 different possible strings. Now this is only true because there are 2 letters in the middle column. If you didn’t use the middle column, it would still encipher to 3 different strings.

To decipher this, you just work backward. Let’s take the ROT 3 of the PYRAMID cipher 653337878847653369933.

  1. You know you need 0’s before you can use the pyramid matrix.
  2. Find the smallest number in the cipher text.
  3. ROT(-N) where N is the smallest number. In this case it’s 3.
  4. ROT(-3) = 320004545514320036600
  5. Take the length of the string and divide by 3. Length = 21 / 3 = 7
  6. Rearrange in 3 rows of 7 characters
  7. Rewrite the code or simply read it vertically.
  8. If you rewrite it it writes out to 340 250 053 016 046 430 520
  9. If you read it vertically just remember that if the 0 is in the top X position it’s the Left matrix; whereas if the 0 is in the bottom X position it’s the Right matrix.
  10. 340 = P 250 = Y 053 = R 016 = A 046 M 430 = I 520 = D

This cipher also allows you to use a key for a custom character set. For example, let’s say you use the ‘key’ of STAND. Your new character set would start with the key ‘STAND’ and then you’d add the rest of the alphabet and numbers without duplicating any of the letters in STAND. Like this:


You’d rewrite the cipher pyramid matrix with “S” where “A” was, “T” where “B” was, “A” where “C” was, etc. Then you’d follow the same rules for enciphering and decipher the message. Using this character set, PYRAMID would then be a completely different cipher text: 020630055524433050054

This is a fun cipher for pen & paper, but I also wanted to do this quickly. Therefore I wrote a custom python script that will do the pyramix cipher for you and allow you to change the character set. It also allows you to use a space string. I found XQ to be the best. This way you could encipher a full message and not just a word.


You can get the script off of my Github. I also used this challenge for the BSides Chicago / BSides Detroit cross-city CTF event. One team was able to solve this cipher after I gave some hints. Be sure to read their write up.

I hope you enjoyed reading about this cipher as much as I enjoyed creating it!

Share →