Jumble / substitution algo - javascript - $200
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

We are in need of some coded which will help jumble the letters in a string/blob. think something like scrabble here. for example i give it 12345 and it will jumble to something like 52314. then the jumble output can be reversed with a key that is generated. so 52314 + a key will get me back to 12345 but... we need some fancy stuff handled.

-Each time we run it we want a way to salt the jumbler so the keys aren't always the same.

-While jumbling it would be cool if the key could handle character substitution. this way 12345 changes to 1b3d5 and then is jumbled to 53b1d. the key containers which characters should be substituted for what as well as the unjumble rules.

-Each time we substitute we should also have some sort of salting so the character substitution is not the same all the time a =1, b=2 etc... it should be random but able to be encoded in that key

-it would be awesome to jumble out the line returns and spaces- I think this would make it easier for the jumbled blob to not get corrupted along the way. Im guessing the way to do this is either via substitution in a thoughtful way or by storing a ton of pointers in the key which seems like it might end up really bloated and less ideal.

-the text input here is meant to be short or long. If we have an upper bound on performance like 5K characters just let us know what you think is the logical upper bound here.

Prototype for this should be in javascript. would be fine to make use of a standard RNG for handling the randomness needed but we would like to roll the rest of this in as few 3rd party dependencies as possible. Page should just have a Text area to input some text and then a button to jumble it. the output should be in a text area box below it along with another text area which has the "key" to undo everything. Another function on the page is needed to check our work. so user would put in the jumbled text and the key and it would show everything put back the way it was originally.

Please post bounty running in repl.it to make it easy to review and debug.



I have created this visualization of the steps i think are needed to make what we are asking for. https://miro.com/app/board/o9J_lad9J1c=/

this should help a lot with the concept i was trying to outline above. While doing this i added a hashing step for integrity checking. and overall i think its a bit more work so I will increate the bounty to 200$ meaning 100 from the normal bounty and 100 as a bonus.

Unicode support? Emoji support?
AjiTae over 1 year ago
good question. i would say no... just normal text
Qdev over 1 year ago
note: i have updated the bounty with a diagram with a lot more detail and some helpful links for encoding (substitution cipher ) and jumbling (transpose cipher)
Qdev over 1 year ago
awarded to ivankahl

Crowdsource coding tasks.

2 Solutions

hey thanks for this, can you tell me a bit how it works? for example is the salt just meant to be a random input (should we hook it to a RNG? to make sure things are unique). on the subsistituion side i see 1\n is changed to az... but is it possible that az naturally occurs in the content? how does it safeguard against that sort of problem. Last question, part of the task was that a signature would be needed (like a private key but not crypto based) that would be needed to be able to reverse out the jumble. I am not seeing that here, can you give some details if I am missing something?
Qdev over 1 year ago
"Salt" is used as a kind of public key. To reverse jumble, you need to have "salt" and an exact substitution array. If "az" naturally occurs in the content jumble function will just throw an error.)
AjiTae over 1 year ago
Ill add some comments to the original post to help make things a bit more clear. Essentially we need the "encoder" to handle the logic of salting and randomizing its substitution (likely with some derivative from RNG). the input should just be the text from the user, and the output is a encoded character set + key file. in that key file we know everything about what jumbled positions and what substitutions happened.
Qdev over 1 year ago


I have created a solution that should solve your issue. I believe I have implemented everything you requested in the diagram. The logic is contained in a single JS file called Jumbler.js inside the Jumbler class. You can simply include this file in any webpage where you want to use the logic. I have created a demonstration page here: https://repl.it/@ivankahl/JumbleSubstitution .

There are three methods that you can use:

  • encrypt(text, includeVerificationHashes) - Can be used to encrypt plain text (including tabs, spaces, new lines and carriage returns). Returns an object containing the encrypted text (result) as well as the key (key). You can also optionally specify if the SHA256 hashes should be included (false by default)
  • verify(jumbledText, key) - Can be used to verify that the specified jumbled text and key are valid.
  • decrypt(jumbledText, key) - Can be used to decrypt the encrypted text with the specified key. The key and encrypted text needs to be valid!

See the script.js file for how the class can be used.

The encryption process is as follows:

  1. Use a seeded random generator to generate a random integer which will be used to perform a caesar cipher (it will be shifted by n characters where n is the randomly generated integer)

  2. Use another seeded random generator (different seed from the first) to generate a ciphertext alphabet. Use this alphabet to then shuffle the rotated text from Step 1

  3. Generate the key which is in the following format (each component is divided by an alphabet character which can be determined by the first integer in the key):

  4. The SHA256 for the key is calculated and then also appended to the end of the message. This allows for us to verify that both the message and key are unchanged:

The verify process simply checks to make sure that the SHA256 in the key and encrypted text match. If either value is modified the check will fail.

The decryption process is simply the reverse of the encryption process.

Please let me know if you have any queries or improvements you'd like made.

Geez this is really nice! any chance you can easily make a toggle to exclude the sha256 stuff so we can more easily run through tests that dont need to carry the added weight of the sha hashes on our values? (maybe check box that says, "enable hash checks". ) thanks!
Qdev over 1 year ago
That's a good idea for testing! I've added a checkbox that you can use to enable or disable the sha256 stuff. Just note that if the sha256 stuff is not included on encryption then the verify method won't work.
ivankahl over 1 year ago
Just wanted to check if this solution solves your problem? Thanks!
ivankahl over 1 year ago
View Timeline