forked from dfinke/Tiny-PowerShell-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelephone.ps1
47 lines (35 loc) · 1.15 KB
/
telephone.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<#
Author: Doug Finke
Email: [email protected]
Blog: https://dfinke.github.io/
Twitter: https://twitter.com/dfinke
GitHub: https://github.com/dfinke
YouTube: https://www.youtube.com/dougfinke
PowerShell Meetup: https://www.meetup.com/NycPowershellMeetup/
LinkedIn: https://www.linkedin.com/in/douglasfinke/
#>
param(
$text,
$mutations = .1,
$seed
)
Import-Module ..\UtilityModules\UtilityModules.psm1 -Force
if (Test-Path $text) {
$text = Get-Content -Raw $text
}
if ($seed) { $null = Get-Random -SetSeed $seed }
$alpha = (Get-AsciiLetters) + (Get-AsciiPunctuation)
$lengthText = $text.Length
$numMutations = [math]::Round($mutations * $lengthText)
$newText = $text
$positionList = Get-RandomSample (0..($lengthText - 1)) $numMutations
foreach ($position in $positionList) {
$newChar = $alpha.Replace($newText[$position], $null).ToCharArray() | Get-Random
$first = $newText.Substring(0, $position)
$rest = $newText.Substring($position + 1)
$newText = "{0}{1}{2}" -f $first, $newChar, $rest
}
@"
You said: "{0}"
I heard : "{1}"
"@ -f $text, $newText