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.
Hello!
That would be my version of Text to Dial … not really sure if the Dial to Text makes sense since we cannot decrypt back to which letter that could be or maybe there is something I don’t get 🙂 hoping to see others solutions. I was able to limit the input to a maximum 5 characters word.
https://github.com/MartinSajpel/IronScripter/blob/master/TextMe/TextMe.ps1
Regards
Martin
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.
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? 🙂
Hi guys, I have just discovered this great site on Reddit, here is my solution – https://github.com/jabberwoockey/IronScripter-TextMe
Unfortunately, I’m not so proficient in Powershell yet, so, don’t judge the quality, please. Also English isn’t my native language, sorry for possible mistakes.
Thanks for contributing. Looks good. Keep an eye on comments for other people’s work.
Thanks for your reply! By the way, I’ve managed to write the bonus function and to get actual possible words for numbers. It’s simple and a little bit tricky at the same time, so, I intentionally do not write here how exactly I did it to not spoil the fun. The link is the same: https://github.com/jabberwoockey/IronScripter-TextMe
Hello everyone!
This is my first contribution to Iron Scripter!
I use hashtable to create the dialer. I Wrote a function to turn the numeric value back to text, but it not gives the same word.
It would be nice if we convert the word considering the position on the keypad. Like “help” = 44335557 insted of 4357
Anyway, this is my contribution:
https://github.com/pustai/IronScripter/blob/master/Get-Dial.ps1
I was thinking about that as well, this one would actually allow us to code and decode the message on another system without a need of a shared dictionary, great one 🙂
Unfortunately it will not work.
If there are two letters in a row on the same key, there will be no way to decrypt.
This is my try : https://github.com/pustai/IronScripter/blob/master/Get-DialAdvanced.ps1
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
”
}
Hi, just found Iron Scripter – AWESOME!
My fisrt post, been Poshing for a few years. Tried to use techniques learned online. Many great blogs and posts across the web. My first community contrib !
https://github.com/sboggs1/IronScripter/blob/master/Text%20Me%20-%20A%20PowerShell%20Dialer%20Challenge.ps1
Here’s my addition to the solution pile. https://jdhitsolutions.com/blog/powershell/7576/answering-the-powershell-word-to-phone-challenge/
First post so I figured I’d keep it simple!
Here’s my addition:
https://github.com/Deanlw/PowerShell/blob/master/TEXT%20ME