Last active
November 1, 2023 11:17
-
-
Save gabemarshall/f25afd533b341e1b21bc39f8e26946b7 to your computer and use it in GitHub Desktop.
Simple Encrypt and Decrypt with Powershell
This file contains 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
# Not secure by any means, just a PoC for XOR'ing data using powershell | |
# Credit to http://stackoverflow.com/questions/3478954/code-golf-xor-encryption | |
$enc = [System.Text.Encoding]::UTF8 | |
function xor { | |
param($string, $method) | |
$xorkey = $enc.GetBytes("secretkey") | |
if ($method -eq "decrypt"){ | |
$string = $enc.GetString([System.Convert]::FromBase64String($string)) | |
} | |
$byteString = $enc.GetBytes($string) | |
$xordData = $(for ($i = 0; $i -lt $byteString.length; ) { | |
for ($j = 0; $j -lt $xorkey.length; $j++) { | |
$byteString[$i] -bxor $xorkey[$j] | |
$i++ | |
if ($i -ge $byteString.Length) { | |
$j = $xorkey.length | |
} | |
} | |
}) | |
if ($method -eq "encrypt") { | |
$xordData = [System.Convert]::ToBase64String($xordData) | |
} else { | |
$xordData = $enc.GetString($xordData) | |
} | |
return $xordData | |
} | |
$output = xor "text to encrypt" "encrypt" | |
# $output = xor "ciphertext" "decrypt" | |
Write-Host $output |
sctfic
commented
Jul 3, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment