Created
January 13, 2021 12:25
-
-
Save Arnaud-Chevalier/ca9ebc8bc6d6a5f21a05a37e6506d10d to your computer and use it in GitHub Desktop.
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
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | |
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | |
$Form = New-Object System.Windows.Forms.Form | |
$Form.Size = New-Object System.Drawing.Size(600,270) | |
$Form.Text = "Caesar Cipher Decryption" | |
$Form.ShowIcon = $False | |
###Function used to decrypt the text | |
function Decrypt { | |
#Populate $i with the selected shift to apply | |
$i = $DropDownBox.SelectedItem.ToString() | |
#Populate $text with the text input | |
$text = $InputBox.Text | |
#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 | |
$OutputBox.text = $arraytostring | |
} | |
#Label1 to show explanation | |
$label1 = New-Object System.Windows.Forms.Label | |
$label1.Location = New-Object System.Drawing.Point(10,10) | |
$label1.Size = New-Object System.Drawing.Size(280,20) | |
$label1.Text = 'Enter the text to decrypt : ' | |
$form.Controls.Add($label1) | |
###Text to decrypt | |
$InputBox = New-Object System.Windows.Forms.TextBox | |
$InputBox.Location = New-Object System.Drawing.Size(10,35) | |
$InputBox.Size = New-Object System.Drawing.Size(565,40) | |
$InputBox.MultiLine = $True | |
$InputBox.ScrollBars = "Vertical" | |
$Form.Controls.Add($InputBox) | |
###Combox box to select the shift to apply to the text | |
$DropDownBox = New-Object System.Windows.Forms.ComboBox | |
$DropDownBox.Location = New-Object System.Drawing.Size(10,80) | |
$DropDownBox.Size = New-Object System.Drawing.Size(180,20) | |
$DropDownBox.text = "Select the Shift to apply" | |
$DropDownBox.DropDownHeight = 200 | |
$Form.Controls.Add($DropDownBox) | |
$Numbers=@(1,2,3,4,5,6,7,8,9) | |
foreach ($Number in $Numbers) { | |
$DropDownBox.Items.Add($Number) | |
} | |
###Button to launch the decryption | |
$Button = New-Object System.Windows.Forms.Button | |
$Button.Location = New-Object System.Drawing.Size(400,80) | |
$Button.Size = New-Object System.Drawing.Size(110,80) | |
$Button.Text = "Decrypt" | |
$Button.Add_Click({Decrypt}) | |
$Form.Controls.Add($Button) | |
#Label2 to show explanation | |
$label2 = New-Object System.Windows.Forms.Label | |
$label2.Location = New-Object System.Drawing.Point(10,150) | |
$label2.Size = New-Object System.Drawing.Size(280,20) | |
$label2.Text = 'Your text decrypted : ' | |
$form.Controls.Add($label2) | |
###Show the result of the decryption | |
$OutputBox = New-Object System.Windows.Forms.TextBox | |
$OutputBox.Location = New-Object System.Drawing.Size(10,170) | |
$OutputBox.Size = New-Object System.Drawing.Size(565,40) | |
$OutputBox.MultiLine = $True | |
$OutputBox.ScrollBars = "Vertical" | |
$Form.Controls.Add($OutputBox) | |
###Show the Gui Box | |
$Form.Add_Shown({$Form.Activate()}) | |
[void] $Form.ShowDialog() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment