Skip to content

Latest commit

 

History

History
100 lines (61 loc) · 5.56 KB

README.md

File metadata and controls

100 lines (61 loc) · 5.56 KB

Hexacrypt

Simple text-based encryption algorithm


Features of Hexacrypt

  1. Requires a "Secret Key" to encode and decode messages.

  2. All input and output is done in text characters, so there is no need to worry about hexadecimal bytes.

  3. The same input and key can produce completely different outputs of different lengths. Look at some of the outputs for the message "Hello!"

    • |P6]Cj\j'E!P-Gs
    • ZNDH36[sRjFK"x]+~
    • i2Bf`q{i "XnT\^9

Weaknesses

  1. Uses seed with insecure pseudo-random number generator to shuffle string

  2. Flaws in algorithm design make it insecure for serious data encryption.


Custom Objects Used

  • Hash8 - Implementation of Pearson Hashing that accepts a string as input
  • Rand64 - Custom Pseudo-Random number generator. Uses a Linear Congruential Generator to fill an array of 32 elements, then iterates over the array to generate numbers. Rand64 is used for all random generation in the algorithm.

The Algorithm

Step 1: Filter

This is a simple enough step. The computer removes any “illegal characters”, such as emoji’s, special letters, etc. from the message and secret key. Any of these characters would mess up the encryption process.

Step 2: Get Seed

Using the secret key provided, the computer runs the string through a simple hashing algorithm called Hash8. The algorithm returns a 64-Bit unsigned integer that is used to seed a Rand64 object.

Step 3: Shuffle Characters

This step involves a string that has all characters that can be used in the message:

  • !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

Using the random number and seed from Step 2, this string is shuffled up to resemble something like this:

  • c1(#$m8eTb"KjDpH-.'+u&;Vx6|sw*Z~!<LrkS4tEoQ=fz[iGM`>vN/O\3lhA]WXCFa0BP9Y{2J,d:)7@ _UIR%n5}^qy?g

To shuffle the string, the computer picks a random character from the original string and adds it to the front of new string. This character is removed from the original string, and the process continues until there are no characters left.


Step 4: Pseudo Xor

In this step, characters in the secret message are replaced using characters in the shuffled up string. The first character is replaced with the last character, the second character is replaced with the second to last character, and so on. While this method works for easy encryption and decryption, the downside is that no letter will ever be replaced by itself. This step is called “Pseudo Xor” because it mimics the binary xor operator where binary digits flipped, just as the letters are flipped across the string. When decrypting the message, Pseudo Xor will return the starting letter, making it ideal for this algorithm.


Step 5: Really Mix Things Up

To make the algorithm more secure, Steps 3 - 4 are repeated for every single character in the secret message. That means that the string in Step 3 is being reshuffled over and over into different strings for every character in the secret message before being passed to the Pseudo Xor. As a result, the same character can be mapped to many different characters while encrypting the secret message, similar to the Nazi Enigma Machine.


Step 6: Reverse String

To make the encryption algorithm more secure, the string is reversed before going on to the next step.

This is to keep step 7 from accidentally undoing the Pseudo-XOR from the above steps.


Step 7: Add Some Garbage

After the entire string has been mixed up, 1 to 10 random “garbage” characters are added onto the front and back of the string. Since these characters can be anything and not mess up the algorithm, they are different every time the message is encrypted, meaning that the same message can be encrypted many different ways.

After the “garbage” is added on to the string, two more characters are placed on the back of the string to indicate how much “garbage” to remove when decrypting the message. This is done using the shuffled up string from Step 3, which is generated by resetting the pseudo-random number generator to the original seed from Step 2. The index of the letter in the string indicates the number of "garbage" characters to add on.

This step is responsible for the same message and key producing completely different outputs.


Step 8: Checksum

Hexacrypt uses a checksum to help with decoding the string, making it easier to trap errors with invalid keys. The string from the previous step is fed into the Hash8 algorithm, and an 8-Bit checksum is generated. The checksum becomes the character index of the unshuffled string of all characters (from step 3), looping around if the checksum is larger than the length of the string. This single character is then appended on to the front of the string from the previous step.


Step 9: The Final Shuffle

Once the checksum and garbage are added to the encrypted message, it it time to do one final shuffle. The seed for the pseudo-random number generator is reset once again to the value from Step 2. (This is so the algorithm can be reversed and the message decrypted.) Steps 3 - 4 are repeated to encrypt the checksum + garbage string from the previous step.



The message is now fully encrypted! No one will be able to read it unless they have the secret key.
(or they are a cryptographer).