PentaBit Cipher
The PentaBit cipher is my latest creation in my encoding hobbyist journey. I created this cipher one day while trying to come up with a cipher that doesn’t greatly expand the size of the output, like my straddling checkerboard does.
This is also my first cipher which can handle various letter casings, and can handle alphanumeric text. Both of these concepts have given me trouble in the past, so creating a cipher that’s capable of both was a proud moment for me. Also new for me is that this is my first Vigenère cipher, making use of a key word or phrase to complete the encoding.
Demo
Plain Text
Secret Key
Plain Text
Plain Text
Encoded
Secret Key
My Own Analysis
As with all of my ciphers, I do not assume that this is cryptographically secure. As always, though, I do not think it is trivially easy to crack either.
Advantages
- Uses a key to further obfuscate the message
- Uses a bespoke text encoding system to store messages
- The size of the output is equal to the size of the input
Disadvantages
- Still unable to encode any punctuation, which limits the information that can be relayed with the cipher
- It’s kind of just an arbitrary text encoding system hidden under a XOR key
- Just as susceptible to XOR brute-forcing as plaintext once the encoding method is understood
After Thoughts
As I type this out, it dawns on me that maybe this isn’t the greatest cipher in the world. Like I say in the Disadvantages section above, it’s basically just XOR’d ASCII, but instead of ASCII, it’s a custom encoding. That means, though, that it suffers from all the same flaws as plain XOR’d ASCII. Nonetheless, I am still quite proud of this cipher. It’s more capable than any of my past ciphers, and does it in less space. I’m also fond of the fact that I set it up to output as a byte array instead of a string, as this once again allows me to easily use the output as color values in an image. As far as practical uses of this feature goes, I have none. I just think it’s a neat option!
Explanation
Expand for an explanation
- Split the plaintext string into an array of individual characters.
- Do the same for the secret key.
- For each character in the plaintext.
- Use a modified A1Z26 cipher to encode the value and get some meta info about the character.
- If the character is in the range
[A-Za-z]
.- Get the character’s ordinal position in the alphabet, such that
A == 1
,B == 2
, andZ == 26
. - Convert that value into binary. This will only take 5 bits.
- Use the 6th bit to store whether that character is uppercase (
1
) or lowercase (0
). - Zero out the 7th and 8th bit.
- Get the character’s ordinal position in the alphabet, such that
- If the character is in the range
[0-9]
.- Convert the character’s decimal value to binary.
- e.g.
"9" == 9 == 0b1001
- e.g.
- Zero out the 5th and 6th bit.
- Set the 7th bit to
1
to signal that this is a numeric value. - Zero out the 8th bit.
- Convert the character’s decimal value to binary.
- For all other values
- Set the 8th bit to
1
to signal that we couldn’t encode this value.- This will be decoded as a space.
- Set the lower 5 bits to be this character’s position in the string modulo 26, and bound to the range
[1, 26]
.- So, if a
,
appears as the 53rd character in a string, it will be represented by0b10000010
.
- So, if a
- Set the 8th bit to
- If the character is in the range
- XOR that encoded byte by the corresponding character in the secret key.
- The secret key will repeated if the key length is shorter than the length of the plaintext.
- Add that byte to the output array
- Use a modified A1Z26 cipher to encode the value and get some meta info about the character.
- Return the array of encoded bytes.
The full documented encode and decode functions can be found here.