Skip to content

Instantly share code, notes, and snippets.

@Arnaud-Chevalier
Last active January 12, 2021 18:31
Show Gist options
  • Save Arnaud-Chevalier/eb3ed7b4e3a4a25f4a1eba279a408827 to your computer and use it in GitHub Desktop.
Save Arnaud-Chevalier/eb3ed7b4e3a4a25f4a1eba279a408827 to your computer and use it in GitHub Desktop.
###################
#Encrypt
###################
#Message to encrypt
$text = "titi a cru voir un grosminet"
#Shift number
$i = 3
#Transform the text to an array of ascii
$asciis = [int[]][char[]]"$text"
#Add the shift specified to every ascii character
$encrypt = foreach ($ascii in $asciis) {
$ascii + $i
}
#Transform back the ascii to text
$asciitotext = [char[]]$encrypt
#Transform the array to a string to read it easily
$arraytostring = -join $asciitotext
$arraytostring
###################
#Decrypt
###################
$text = "wlwl#d#fux#yrlu#xq#jurvplqhw"
#Shift number
$i = 3
#Transform the text to an array of ascii
$asciis = [int[]][char[]]"$text"
#Add the shift specified to every ascii character
$decrypt = foreach ($ascii in $asciis) {
$ascii - $i
}
#Transform back the ascii to text
$asciitotext = [char[]]$decrypt
#Transform the array to a string to read it easily
$arraytostring = -join $asciitotext
$arraytostring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment