Mind Jogging Generator

by Mar 20, 2019

The human mind can read sentences even if the characters are scrambled as long as the first and last letter of each word stays intact. Here is a PowerShell function to try out for yourself. It takes a sentence and scrambles the characters except for the first and last characters:

function Convert-Text
{
    param
    (
      $Text = 'Early to bed and early to rise makes a man healthy, wealthy and wise.'
    )
    $words = $Text -split ' '

    $newWords = foreach($word in $words)
    {
        if ($word.Length -le 2)
        {
            $word
        }
        else
        {
            $firstChar = $word[0]
            $lastChar = $word[-1]
            $charLen = $word.Length -2
            $inbetween = $word[1..$charLen]
            $chars = $inbetween | Get-Random -Count $word.Length 
            $inbetweenScrambled = $chars -join ''
            "$firstChar$inbetweenScrambled$lastChar" 
        }
    }

    $newWords -join ' '
}

When you do not submit text, a sample sentence is used. Can you guess what it means?

 
PS C:\> Convert-Text
Ealry to bed and erlay to rsie maeks a man hylhtea, wlhtaey and wies.  
 

psconf.eu – PowerShell Conference EU 2019 – June 4-7, Hannover Germany – visit www.psconf.eu There aren’t too many trainings around for experienced PowerShell scripters where you really still learn something new. But there’s one place you don’t want to miss: PowerShell Conference EU – with 40 renown international speakers including PowerShell team members and MVPs, plus 350 professional and creative PowerShell scripters. Registration is open at www.psconf.eu, and the full 3-track 4-days agenda becomes available soon. Once a year it’s just a smart move to come together, update know-how, learn about security and mitigations, and bring home fresh ideas and authoritative guidance. We’d sure love to see and hear from you!

Twitter This Tip! ReTweet this Tip!