Encrypt / Decrypt
A binary to char encryptor/decryptor made with JS
How it works
// Encrypting
- First we grab the word and the key from form input in HTML
- Function getWord() accepts this 2 values
- Than it shuffles the original bits matrix based on the key using the sortTableSeedBased function which accepts a copy of the original matrix and the encrypt key
- After sorting the matrix using the key we create a matrix of bits we found from the matching chars.
- We convert the matrix to an array
- We join the array using .join() and then show it using showText.
// Decrypting
- First we grab the binary coded value and the key from form input in HTML
- Function turnBack() accepts this 2 values and then shuffles a duplicate of original matrix array using the key.
- We create an array of chars using BitsToChars function
- BitsToChars loops every 8 bits, so captures the first one, than the eighth one and so on. After capturing the first one it checks the bits from 0 to 7 and searches for matches in the Binary Matrix array using EightBitsToChar, so if exist any match from the Binary table it returns the char that belongs to that key.
- Then we join the array and show it using showText.
-- addRow - shows the table -- showText - shows text in the id that accepts as parameter.
Background image author/link
Photo by Markus Spiske temporausch.com from Pexels
License
MIT - Use the code as you want!