只是為了好玩,一個朋友和我正試圖找到一種創造性的方式來使用隱寫術向彼此發送編碼訊息。我偶然發現做了如下所示的事情,我一直在努力撰寫一個函式來自動化這個程序。
this is a secret message
can be turned into:
("{2}{1}{0}{3}"-f'ecret m','is a s','this ','essage')
拆分字串并使用重新排序似乎是要走的路。
所以字串需要在 5-10 個字符之間隨機分割。
需要保存原始位置的索引
拆分需要交換
并且新索引排序為正確地重新排序訊息
我真的一直在苦苦掙扎,感謝您的幫助
uj5u.com熱心網友回復:
只是為了好玩....????
$InputMessage = 'this is a secret message'
$SplittedString = $InputMessage -split '' | Select-Object -Skip 1 | Select-Object -SkipLast 1
[array]::Reverse($SplittedString)
foreach ($Character in $SplittedString) {
if ($Character -notin $CharacterList) {
[array]$CharacterList = $Character
}
}
foreach ($Character in ($InputMessage -split '' | Select-Object -Skip 1 | Select-Object -SkipLast 1)) {
$Index = [array]::indexof($CharacterList, $Character)
$Output = "{$Index}"
}
$Result = "'$Output' -f $(($CharacterList | ForEach-Object {"'$_'"}) -join ',')"
$Result
其輸出將是:
'{6}{10}{9}{3}{5}{9}{3}{5}{2}{5}{3}{0}{8}{7}{0}{6}{5}{4}{0}{3}{3}{2}{1}{0}' -f 'e','g','a','s','m',' ','t','r','c','i','h'
其輸出將是:
this is a secret message
現在,如果您想使用它,您可以洗掉花括號、引號、逗號和 the -f,并且只將數字和字符添加到資料中。;-)
uj5u.com熱心網友回復:
不完全是您正在尋找的東西,但這可能會給您一些幫助:
class Encode {
[string] $EncodedMessage
[int[]] $Map
Encode ([string] $Value) {
$this.Shuffle($Value)
}
[void] Shuffle([string] $Value) {
$ref = [Collections.Generic.HashSet[int]]::new()
$ran = [random]::new()
$enc = [char[]]::new($Value.Length)
$ind = 0
while($ind -lt $Value.Length) {
$i = $ran.Next(0, $Value.Length)
if($ref.Add($i)) {
$enc[$ind ] = $Value[$i]
}
}
$this.EncodedMessage = [string]::new($enc)
$this.Map = $ref
}
}
class Decode {
static [string] DecodeMessage ([Encode] $Object) {
return [Decode]::DecodeMessage($Object.EncodedMessage, $Object.Map)
}
static [string] DecodeMessage ([string] $EncodedMessage, [int[]] $Map) {
$decoded = [char[]]::new($EncodedMessage.Length)
$z = 0
foreach($i in $Map) {
$decoded[$i] = $EncodedMessage[$z ]
}
return [string]::new($decoded)
}
}
編碼訊息:
$message = 'this is a secret message, hello world 123'
$encoded = [Encode] $message
PS /> $encoded
EncodedMessage Map
-------------- ---
t li,ti as 3ossmrs waer h1leeh deg2coles {0, 16, 35, 5…}
要解碼訊息,您可以使用該型別的物件,Encode也可以給您的朋友Encoded Message 和 Map 來解碼它;)
PS /> [Decode]::DecodeMessage($encoded)
this is a secret message, hello world 123
PS /> [Decode]::DecodeMessage('t li,ti as 3ossmrs waer h1leeh deg2coles', $encoded.Map)
this is a secret message, hello world 123
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/479347.html
