Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Say I have a weighted range of 0 - 10. 0 being no garbled, 10 being 100% garbled.

I'm looking for an algorithm that will garble plain text based upon this weight. The garbling doesn't need to be consistent between runs, it just needs to appear more and more garbled with the higher weight.

share|improve this question
What have you tried so far? What has your research found? – FrustratedWithFormsDesigner Apr 26 '12 at 16:10
3  
Define "more garbled". Shouldn't be hard to write something that randomly changes/swaps 10-100% of the letters in the string. Anyway this is off topic. – Michael K Apr 26 '12 at 16:10
1  
do you've a sample text? – Morpheus Apr 26 '12 at 16:23
Sorry, I didn't realize this was off-topic. I though text-processing was relevant to what I'm looking for. – bcardarella Apr 26 '12 at 16:23
4  
define "garbled", show input and output examples, this, as is, this is an incomplete question; put some effort into the question, it might get answered. – Jarrod Roberson Apr 26 '12 at 16:46
show 2 more comments

closed as off topic by Michael K, gnat, World Engineer, Steve Evers, Walter Apr 26 '12 at 23:12

Questions on Programmers Stack Exchange are expected to relate to software development within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

The simplest thing to do would be to use the weighting and the length of the string to determine a number of random transpositions (swaps) to perform among letters/characters in the text. If a string has 20 characters, then a weighting of 1 would result in one transposition (thus changing two letters, 10% of the string), while a weight of 10 would result in 10 transpositions (changing 20 letters, 100% of the length of the string, though if the swaps are truly random you can't enforce that each letter is only ever transposed once). For a string with 100 characters, a weight of 1 is 5 swaps, a weight of 10 is 50 swaps.

If swaps directly proportional to the length of the string and the weighting isn't garbling the string enough at the high end, or too much at the low end, try a nonlinear conversion between weight and number of swaps. Try squaring the weight and performing swaps proportional to that percentage of the string's characters. Try squaring the number of characters, multiplying by 1/(11-weight), and performing that many swaps.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.