Text Me – A PowerShell Dialer Challenge

The Chairman is very fond of puzzles, ciphers and secret codes. All of which lend themselves to PowerShell. Today’s Intermediate level challenge falls into this category. Although some of the bonus elements might require a bit more skill.

When you look at a telephone keypad, you will see that there is an alphabetic layout with each digit. There may be cultural distinctions, but The Chairman is hoping not enough to prevent you from participating in this challenge. Using the alphabet layout on phone, write a PowerShell function to convert a simple word to its numeric equivalent. For example, on a US phone, ‘help’ can be converted to 4357.

The lazy and easy way, would be to do a 1-1 substitution between alphabet characters and numbers. But Iron Scripters are made of stronger metal. Since the letters are grouped by number, let that be your guide.

Bonus

  • Limit word length to 5 word characters.
  • Write a function to convert the numeric “word” back into plain text.

13 Replies to “Text Me – A PowerShell Dialer Challenge”

    • Jeffery Hicks

      I like the use of Regex. To translate back you would need a dictionary file of words. You could convert the numeric value back into all possible permutations and only keep ones that are in the dictionary. Not saying it would be perfect.

      • Martin

        Thanks, I didn’t want to go with the dictionary since I would image that we do the “coding”, sending the message to someone else and the other person can do “decoding” without the need to have a shared dictionary … but that could only be done if we do it like Gustavo proposed below and that on the other hand would not match the example of “help” being “4357”.

        Anyhow I really like the challange, is there any way to subscribe with a newsletter when new ones arrives? 🙂

  1. Scott

    Hi, i just found this site, Great idea!
    I will be back for more. Been PoShing a few years now. Have learned a LOT from so many blogs and posts.
    I don’t have a github. but here is my entry. Tried to give a more robust error error handling.

    ———–
    # technique: find letter in delimited string, count delimiters
    cls
    $a=’||abc|def|ghi|jkl|mno|pqrs|tuv|wxyz’
    While($true){
    $arr=$null
    Do{
    Try{[ValidatePattern(‘^\w{1,5}$’)][string]$str = Read-host -Prompt ‘Enter your word ‘
    $arr = $str.ToCharArray()
    }
    Catch{Write-Host ‘Invalid, 5 chars maximum, only letters and numbers’}
    }Until($arr -ne $null)
    [string]$result=”
    ForEach($ltr in $arr){
    If($ltr -match ‘\d’){$result += $ltr}
    Else{
    $b=$a.Substring(0,$a.IndexOf($ltr))
    $result += (($b.ToCharArray().Where({$_ -match ‘\|’}) | Measure-Object -Character).Characters)
    }
    }
    $result

    }

Leave a Reply

Your email address will not be published. Required fields are marked *