I need help in creating code for this Visual Basic Windows Forms. Could someone
ID: 3671894 • Letter: I
Question
I need help in creating code for this Visual Basic Windows Forms. Could someone please help me with it? Thank you.
Develop a Visual Basic Windows Forms application that will ‘encrypt’ (character shift)’ the characters in a string based on a symmetric key (process known as symmetric-key cryptography). The application must also ‘decrypt’ the message based on the symmetric key used.
General Requirements
The clear-text message (that will be ‘encrypted’) is stored in a text-file. The text-file is to be selected using an OpenFileDialog Windows control object
Text-file contents are to be displayed in a Textbox control located on the Windows form (you can also use this textbox to input clear-text characters)
Keys are contained in a ComboBox control object. Users can select a particular key resulting in alternate cipher-text outputKeys are to be a minimum of 5 digits. Each key digit is used for encoding where your program will move to the next digit for every character in the clear-text message. Since there are a limited number of digits in a key, your program must ‘wrap-back’ to the first digi t The selected key must be stored in an array
The resulting cipher-text output is to be stored in a text file and displayed in a textbox control on the Windows form Using the same key for encryption, decrypt the cipher-text message and display it in a label on the Windows Form
Since only printable characters are used (see table), if the ASCII code becomes larger than 126, you will need to wrap around to the ASCII code 32 (space) Use exception handling where needed…for example, FileNotFound or DirectoryNotFound.
Form Clear Text Select Key Button 1 Cipher Text Button2Explanation / Answer
Imports System.IO Imports System.Security.Cryptography Imports System.Text Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'You should not hard code the encryption key here Dim EncryptionKey As String = "encryptionkey" Dim eStr As String = passwordEncrypt("yourpassword", EncryptionKey) MessageBox.Show(eStr) Dim dStr As String = passwordDecrypt(eStr, EncryptionKey) MessageBox.Show(dStr) End Sub 'Encrypting a string Public Shared Function passwordEncrypt(ByVal inText As String, ByVal key As String) As String Dim bytesBuff As Byte() = Encoding.Unicode.GetBytes(inText) Using aes__1 As Aes = Aes.Create() Dim crypto As New Rfc2898DeriveBytes(key, New Byte() {&H49, &H76, &H61, &H6E, &H20, &H4D, _ &H65, &H64, &H76, &H65, &H64, &H65, _ &H76}) aes__1.Key = crypto.GetBytes(32) aes__1.IV = crypto.GetBytes(16) Using mStream As New MemoryStream() Using cStream As New CryptoStream(mStream, aes__1.CreateEncryptor(), CryptoStreamMode.Write) cStream.Write(bytesBuff, 0, bytesBuff.Length) cStream.Close() End Using inText = Convert.ToBase64String(mStream.ToArray()) End Using End Using Return inText End Function 'Decrypting a string Public Shared Function passwordDecrypt(ByVal cryptTxt As String, ByVal key As String) As String cryptTxt = cryptTxt.Replace(" ", "+") Dim bytesBuff As Byte() = Convert.FromBase64String(cryptTxt) Using aes__1 As Aes = Aes.Create() Dim crypto As New Rfc2898DeriveBytes(key, New Byte() {&H49, &H76, &H61, &H6E, &H20, &H4D, _ &H65, &H64, &H76, &H65, &H64, &H65, _ &H76}) aes__1.Key = crypto.GetBytes(32) aes__1.IV = crypto.GetBytes(16) Using mStream As New MemoryStream() Using cStream As New CryptoStream(mStream, aes__1.CreateDecryptor(), CryptoStreamMode.Write) cStream.Write(bytesBuff, 0, bytesBuff.Length) cStream.Close() End Using cryptTxt = Encoding.Unicode.GetString(mStream.ToArray()) End Using End Using Return cryptTxt End Function
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.