Windows Powershell Reverse Caeser Cipher -- 2
Budget: $30 – $250 USD
Using Visual Studio Code, create a shell script named advscript.ps1
Save advscript.ps1 to the appropriate location on your system:
Windows: "My Documents" Folder
Mac OS X: /Users/<username>
Linux: /home/<username>
Write some code in advscript.ps1 that will read the XML file linked below into PowerShell:
advps.xml Download advps.xml
Using the values contained in the XML file, write a reversed Caesar Cipher function to decrypt and output the message contained in the XML file using the offset value contained in the XML file.
Since the algorithm to perform this decryption is a little beyond most new programmers, I will provide you with mine. This code will create a reverse Caesar Cipher hash table ($translation) based upon the offset ($offset) you provide to it. You will need to provide the code to perform the lookups in this hash table and return the results:
$translation = [ordered]@{}
$alpha = @('A','B','C','D','E','F','G','H','I','J','K','L','M',`
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z')
For ($i=0; $i -lt 26; $i++)
{
# This is an adaptation of the Atbash algorithm E(x)=(-x mod m)+1
# where m is the number of letters used (26 in this case), and x is the offset.
# In this case, the trailing +1 is not needed, as we are working with a zero
# base array index.
# Note that PowerShell's Mod operator (%) does not calculate a true Modulus -
# it actually calculates a remainder (the nuance is that it has trouble with
# negative numbers). In order to get a true Modulus, you must add the divisor
# back to the first "Modulus", then calculate another Modulus on the result.
$translation[$alpha[((((-$i + $offset) % 26) + 26) % 26)]] = $alpha[$i]
}
Hint #1: You probably won't find any examples of a reversed Caesar Cipher using Google - there are plenty of examples of standard Caesar Ciphers, but none that are reversed. If you simply copy some random Caesar Cipher code from somewhere online, you will fail this assignment.
Hint #2: The easiest way to accomplish this task is by creating a hash table (as the algorithm above does).
Hint #3: Be sure to download the XML file to your computer - do not simply copy and paste the XML code from Canvas.
Hint #4: In order to iterate over the cipher string character-by-character, you will need to convert it to a character array first. Once in a character array, you can loop through each character and look up its corresponding character in the hash table. After performing the decryption, join the character array back into a string for output.
Hint #5: After converting your cipher string to a character array, translate each character to its unencrypted form like this:
Foreach ($c in $mychararray)
{
$myoutchararray += $translation["$c"]
Hint #6: Convert your output character array back to a string.
Save advscript.ps1 to the appropriate location on your system:
Windows: "My Documents" Folder
Mac OS X: /Users/<username>
Linux: /home/<username>
Write some code in advscript.ps1 that will read the XML file linked below into PowerShell:
advps.xml Download advps.xml
Using the values contained in the XML file, write a reversed Caesar Cipher function to decrypt and output the message contained in the XML file using the offset value contained in the XML file.
Since the algorithm to perform this decryption is a little beyond most new programmers, I will provide you with mine. This code will create a reverse Caesar Cipher hash table ($translation) based upon the offset ($offset) you provide to it. You will need to provide the code to perform the lookups in this hash table and return the results:
$translation = [ordered]@{}
$alpha = @('A','B','C','D','E','F','G','H','I','J','K','L','M',`
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z')
For ($i=0; $i -lt 26; $i++)
{
# This is an adaptation of the Atbash algorithm E(x)=(-x mod m)+1
# where m is the number of letters used (26 in this case), and x is the offset.
# In this case, the trailing +1 is not needed, as we are working with a zero
# base array index.
# Note that PowerShell's Mod operator (%) does not calculate a true Modulus -
# it actually calculates a remainder (the nuance is that it has trouble with
# negative numbers). In order to get a true Modulus, you must add the divisor
# back to the first "Modulus", then calculate another Modulus on the result.
$translation[$alpha[((((-$i + $offset) % 26) + 26) % 26)]] = $alpha[$i]
}
Hint #1: You probably won't find any examples of a reversed Caesar Cipher using Google - there are plenty of examples of standard Caesar Ciphers, but none that are reversed. If you simply copy some random Caesar Cipher code from somewhere online, you will fail this assignment.
Hint #2: The easiest way to accomplish this task is by creating a hash table (as the algorithm above does).
Hint #3: Be sure to download the XML file to your computer - do not simply copy and paste the XML code from Canvas.
Hint #4: In order to iterate over the cipher string character-by-character, you will need to convert it to a character array first. Once in a character array, you can loop through each character and look up its corresponding character in the hash table. After performing the decryption, join the character array back into a string for output.
Hint #5: After converting your cipher string to a character array, translate each character to its unencrypted form like this:
Foreach ($c in $mychararray)
{
$myoutchararray += $translation["$c"]
Hint #6: Convert your output character array back to a string.