-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathscrambler.ps1
41 lines (30 loc) · 959 Bytes
/
scrambler.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
<#
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,
$seed
)
function Invoke-Scramble {
param($word)
if ($word.Length -gt 3 -and [regex]::match($word, "\w+")) {
$middle = $word.Substring(1, $word.Length - 2)
$random = $middle.ToCharArray() | Sort-Object { Get-Random }
$word[0] + (-join $random) + $word[-1]
}
else {
$word
}
}
if ($seed) { $null = Get-Random -SetSeed $seed }
$pattern = "([a-zA-Z](?:[a-zA-Z']*[a-zA-Z])?)"
-join $(foreach ($word in [regex]::Split($text, $pattern)) {
Invoke-Scramble $word
})