Created
September 12, 2019 15:28
-
-
Save AdrianVollmer/501b8319da46fe9f3e39d9632a81cefc to your computer and use it in GitHub Desktop.
test powershell rc4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function RC4 { | |
param([Byte[]]$buffer) | |
$key = ([system.Text.Encoding]::UTF8).GetBytes("abcdefghjikjlmnopqrstuvwxyz") | |
$s = New-Object Byte[] 256; | |
$k = New-Object Byte[] 256; | |
for ($i = 0; $i -lt 256; $i++) | |
{ | |
$s[$i] = [Byte]$i; | |
$k[$i] = $key[$i % $key.Length]; | |
} | |
$j = 0; | |
for ($i = 0; $i -lt 256; $i++) | |
{ | |
$j = ($j + $s[$i] + $k[$i]) % 256; | |
$temp = $s[$i]; | |
$s[$i] = $s[$j]; | |
$s[$j] = $temp; | |
} | |
$i = $j = 0; | |
for ($x = 0; $x -lt $buffer.Length; $x++) | |
{ | |
$i = ($i + 1) % 256; | |
$j = ($j + $s[$i]) % 256; | |
$temp = $s[$i]; | |
$s[$i] = $s[$j]; | |
$s[$j] = $temp; | |
[int]$t = ($s[$i] + $s[$j]) % 256; | |
$buffer[$x] = $buffer[$x] -bxor $s[$t]; | |
} | |
$buffer | |
} | |
RC4(@(1..10)) | |
$cleartext = @() | |
$x = 123 | |
1 .. 10000 | % { $x = (43*$x + 23) % 256; $cleartext += $x } | |
Get-FileHash -InputStream ([System.IO.MemoryStream]::New($cleartext)) | |
$ciphertext = RC4($cleartext) | |
Get-FileHash -InputStream ([System.IO.MemoryStream]::New(($ciphertext))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment