Hashingup words

Some time back, some one told me a story: if you take a story and change each word in it such, that the first and last letters remain the same, you can jumble up all the letters in between and the human eye will still read the correct word. It did work for the prepared text. But will it work for any text? Let's see. We need a program to test it though. This topic is about that program: whash01.

WordHash is online!

As of now, Wordhash is available online as a CGI executable. Check it out at WordHash.html in the CGI section where you can also run it in a webform.

Whash01

Whash works as follows:

Words have a length:
  1. A single letter word will remain unchanged
  2. A two letter word will not change either
  3. A three letter word will remain the same
  4. In a four letter word, letters 2 and 3 MAY be swapped
  5. All other words are jumbled up beyond recognition
The messing up algorithm is as follows:

Whash01: the source

Below is the source code for whash01.mod. It relies on the random number generator module and on SysLib.time to seed the random number generator in order to prevent that the random numbers become predictable.

MODULE whash01;

IMPORT InOut, Random, Strings, SysLib;

VAR	src, dest	: Strings.String;
	k, l, m, rem	: CARDINAL;
	seed		: INTEGER;

BEGIN
  SysLib.time (seed); 
  Random.initSeed (CARDINAL (seed));
  LOOP
    InOut.ReadString (src);
    IF  NOT InOut.Done () THEN  EXIT  END;
    l := Strings.Length (src);
    dest := src;
    IF  l > 3  THEN
      rem := l - 2;
      Strings.Delete (src, l - 1, 1);
      Strings.Delete (src, 0, 1);
      m := 1;
      WHILE  rem > 1  DO
        k := Random.nr (rem);
	dest [m] := src [k];
	Strings.Delete (src, k, 1);
	DEC (rem);
	INC (m)
      END;
      dest [m] := src [0]
    END;
    InOut.WriteString (dest);
    InOut.Write (' ')
  END;
  InOut.WriteLn
END whash01.
   
That's it. You can download source and compiled executable here: whash01.tgz

See it run

Below are some examples of the output of whash01:

jan@oxygen ~/Modula/whash$ ./whash01 <test5
lcok lcok lock sttaion soatitn stiaton miahcne mhancie mnciahe bileor nkatcecrur aolsshe 
   
The original file 'test5' is as follows:
jan@oxygen ~/Modula/whash$ cat test5
lock lock lock station station station machine machine machine boiler nutcracker asshole 
   
For simple words I can deduce the original words. But even a word like 'boiler' is incomprehensible after a wordhash operation.

Another myth busted

WordHash is online!

As of now, Wordhash is available online as a CGI executable. Check it out at WordHash.html in the CGI section where you can also run it in a webform.

Page created Jan 14, 2016 and