Srambler v1.0, because he wanted one!

Years ago, my brother, Q8BKman, and I were watching National Treasure 1 on TV. Everything was cool till the scene where they were hacking their way in; their method got them a set of keys that the password is made of. In the movie, they had a made up application that would let the user enter those letters and it would get you the possible words made of them. That is what my brother liked and wanted!

Here’s the exact clip I mentioned: ClickMe!


You know, when you see such an app and you know you can do it, you try to make it. Through out the past years, I’ve had several attempts to create a a similar one, but I usually end up not satisfied; usually either inaccurate or inefficient!

However, this time – 1.5 months ago, I got it right; I called it Scrambler.

When I was first coding it, the features were nothing more than giving all permutations. However, I have this habit: if I start doing one thing, I have to do it the best possible way. So with time passing by:

  • Got dictionary feature for filtering purposes
  • Got a selective raw/filtered option
  • Got UTF-8 full support – for input, output, and dictionary (UTF-8 includes Arabic; main reason ^^)
  • Got output to file feature

And so, I was ready to share! E-mailed a simple installation bash script to my brother with instructions on how to get it running and waited. I, later, received a reply saying that it wasn’t running! I figured out that it’s because of a missing package! I’ve used ‘argparse‘ python library in this script instead of the pre-installed – depreciated – ‘optparse‘!

That was no biggie. However, his feedback was something else: Yeah, it’s good. but it has a bug.

I, later, knew it’s because he was trying to get a filtered result of the letters ‘blkaeiou’. If you know math, you’d know that that word alone has 40,320 permutations. Also, don’t forget that he wanted the output filtered through the Linux dictionary – by default – which contains about 98,569 words. That means that for every permutation, the script has to check through 98,569 words to see if it matches or not; that’s a total of 3,974,302,080 operations on a dual core PC. It’s not a bug, it just requires time, … about 2 minutes – if I remember correctly! … and no, there weren’t any real words made of those letters! :P

Other than that, it works fine! :) … Though, my brother forgot why he wanted it! :(

Wanna try it out?

I’d be really glad if you try it and give me your feedback! And FYI, it’s a single file script, there is no fuss in “installation”. Just open the command line terminal and type in the following:

sudo apt-get install python-argparse
cd /usr/bin #optional, if you want it "installed" system-wide
chmod +x scrambler

Running it is simple, if you placed it under /usr/bin, then you can launch it from any location by simply typing: scrambler. If you placed it in a local directory on the other hand, then to launch it, you’ll have to be in the directory and type: ./scrambler

For more information on how to use it, just type: scrambler -h and you’d get the help message. :)


In case you want to see some examples, here you go:

Ex1: For getting all permutations of the word ‘act’:
scrambler -w act -r

Ex2: For getting filtered permutations of the word ‘cool’:
scrambler -w cool

Ex3: For getting all permutations of the arabic word ‘السلام’ and outputs it in ‘peace.txt file’:
scrambler -r -w السلام -o peace.txt
Returns: This list.
PS: If you want Arabic support for your favorite terminal, use bicon.

Ex4: For getting filtered permutations of the arabic word ‘عميد’ according to an Arabic dictionary ‘arabic-ar‘:
scrambler -d ./words-ar -w عميد

PS: If you wanted a filtered result, you’d need an Arabic .txt dictionary, you can get one here! :)

Scrambler v2.0 plans

Talking about future? Yes. So I currently have some ideas to implement, but have more important stuff to deal with! So my intentions are simple.

First is to create a letter “place-holder”. A symbol that would mean the possibility of any letter. It would kill the processor if there were like 8 of them, but it would be useful in some cases!

Second is to rewrite a huge portion of the script. I need to use classes. I will not only be able to deliver a better experience to users, but also provide the capability of being imported in other python scripts as well! That would also make it easier to build a GUI front-end to it or to be used in a different project as a module!

… GUI? I got ‘pyGTK’ book printed months ago and I still want to read it, but got no time. If any, Scrambler would be the one to test things on. So yes, a GUI might come out as well, however, it would not be written within the same file; It would import v2.0 as a module! :)


~ by AnxiousNut on February 7, 2011.

9 Responses to “Srambler v1.0, because he wanted one!”

  1. to make it go faster, try doing this
    go through the dictionary file, and take the words one by one, arrange the word alphabetically and save the real word in linked list of linked lists (2D matrix) by the key (alphabetically arranged word is the key)

    meaning it’ll be something like this

    act -> act-> atc -> cat -> cta -> tac -> tca
    cloo -> cool -> loco
    [took those words from your post, assuming they are from the dictionary]
    the first column represents the key

    searching would be done like this, take the word from the user, arrange the letters alphabetically and you got the key, search the key and output the whole linked list

    improving this would use a hashset or something :D

    • Right! Parsing dictionary text files and put classify them into dictionaries. Might be faster, and might not; the built in ‘in’ operator might have a better method of doing this.

      Will try this out the next time I get my hands int this. :)

      • am not sure about how “in” operator works [got almost 0 info about python :P] but from what I understood, am pretty sure my method can be a lot faster (I can provide a java code for you to test if you want :P)

      • Ah, no thanks, keep Java to yourself! :P

  2. Nice and very geeky idea,
    (this might not be directly related) but Can you reuse some of the code to write a script that will take a phone number as an input
    substitute every number with every possible letter corresponding to it in the phone’s keypad.

    then check the list against a dictionary or an editable list.
    giving us ###24623 -> ###Ahmad ..

    • LOL, I actually worked on the idea you just mentioned once I finished this script! I finished from text to numbers, but not the other way around; stopped half way. Though both are still not presentable atm, but I intend to finish them up and write a blog-post as well!

      The main reason why I actually wanted this is to know if my phone number actually has a meaningful word in it, and to to what numbers i should pick if I want to buy a new number! (i.e Linux: 54689)

      Now that I know that there are other that would use that script, I think I’m gonna get back to it soon once I’m done with what’s occupying my hands atm. :)

    • actually , I’ve done something similar before, my program worked on 4 numbers only and it checked with a provided dictionary if the 4 numbers could create a word that’s in there as a practice problem from a site [the problem omitted the letters Q and Z though] did that in c++ and java

  3. Impressive, but can be better.

    Firstly, you don’t need classes to be able to import your script as a module in other scripts. calling a public function directly from the script is enough.

    If you intend to do a second version, try using sqlite. it should speed things up significantly. You can continue to use text dictionaries if you generate the database on the fly. (maybe cache it in ~ for future use, ay?)

    انظر رؤية ما تخبئه يا المتوتر :)

    خاطرة: في المرة القادمة، حاول ان تخفي رابط المخطوطة بين السطور بشكل افضل لأنني لازلت استطيع العثور عليه :|

    • If you intend to do a second version, try using sqlite.

      Thought of using DB’s to speed it up, but I didn’t go for it since the initial idea was to make a simple script. However, it’s very likely to be implemented in the next version – if I had the time to make it.

      خاطرة: في المرة القادمة، حاول ان تخفي رابط المخطوطة بين السطور بشكل افضل لأنني لازلت استطيع العثور عليه :|

      LOL, actually I had two links for it in the blogpost!

      1. Under “Wanna try it out?”, first paragraph:

      … And FYI, it’s a single file script, …

      2. Under “Wanna try it out?”, 3rd line of the code



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: