Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This would help me visualize what controls to use in my form. Thanks! Develop a

ID: 3669801 • Letter: T

Question

This would help me visualize what controls to use in my form. Thanks!

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 output

   Keys 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 digit

   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.   

Example: Using a sample key of 58912, the output would be as follows:

Clear Character

N

J

I

T

V

B

N

e

T

ASCII Code

78

74

73

84

32

86

66

78

101

84

ASCII Code + Key Value

83

82

82

85

34

91

74

87

102

86

Shifted Character

S

R

R

U

[

J

W

f

V

Clear-Text: “NJIT VBNet”

Cipher-Text: “SRRU”[JWfV”

Clear Character

N

J

I

T

V

B

N

e

T

ASCII Code

78

74

73

84

32

86

66

78

101

84

ASCII Code + Key Value

83

82

82

85

34

91

74

87

102

86

Shifted Character

S

R

R

U

[

J

W

f

V

Name Property Text Labell x1 Label2 x2 Label3 x3 Label4 x4 Label5 x5 Label6 x6 Buttonl Mean Button2 Std.Deviation btnStd Button3 Variance Button4 Grade TextBox1 btnMean TextBox TextBoxi TextBox2 TextBox4 TextBox5 TextBox6" TextBox7 45 TextBox8 TextBox3 | “ TextBox10 45 btn Variance btnGrade xlTxtBox x2TxtBox x3TxtBox x4TxtBox x5TxtBox x6TxtBox meanTxtBx txtDeviation txtVariance txtGrade

Explanation / Answer

Imports System Imports System.IO Imports System.Security Imports System.Security.Cryptography Imports System.Runtime.InteropServices Imports System.Text Module Module1 ' Call this function to remove the key from memory after it is used for security. _ Public Sub ZeroMemory(ByVal addr As IntPtr, ByVal size As Integer) End Sub ' Function to generate a 64-bit key. Function GenerateKey() As String ' Create an instance of a symmetric algorithm. The key and the IV are generated automatically. Dim desCrypto As DESCryptoServiceProvider = DESCryptoServiceProvider.Create() ' Use the automatically generated key for encryption. Return ASCIIEncoding.ASCII.GetString(desCrypto.Key) End Function Sub EncryptFile(ByVal sInputFilename As String, _ ByVal sOutputFilename As String, _ ByVal sKey As String) Dim fsInput As New FileStream(sInputFilename, _ FileMode.Open, FileAccess.Read) Dim fsEncrypted As New FileStream(sOutputFilename, _ FileMode.Create, FileAccess.Write) Dim DES As New DESCryptoServiceProvider() 'Set secret key for DES algorithm. 'A 64-bit key and an IV are required for this provider. DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey) 'Set the initialization vector. DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey) 'Create the DES encryptor from this instance. Dim desencrypt As ICryptoTransform = DES.CreateEncryptor() 'Create the crypto stream that transforms the file stream by using DES encryption. Dim cryptostream As New CryptoStream(fsEncrypted, _ desencrypt, _ CryptoStreamMode.Write) 'Read the file text to the byte array. Dim bytearrayinput(fsInput.Length - 1) As Byte fsInput.Read(bytearrayinput, 0, bytearrayinput.Length) 'Write out the DES encrypted file. cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length) cryptostream.Close() End Sub Sub DecryptFile(ByVal sInputFilename As String, _ ByVal sOutputFilename As String, _ ByVal sKey As String) Dim DES As New DESCryptoServiceProvider() 'A 64-bit key and an IV are required for this provider. 'Set the secret key for the DES algorithm. DES.Key() = ASCIIEncoding.ASCII.GetBytes(sKey) 'Set the initialization vector. DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey) 'Create the file stream to read the encrypted file back. Dim fsread As New FileStream(sInputFilename, FileMode.Open, FileAccess.Read) 'Create the DES decryptor from the DES instance. Dim desdecrypt As ICryptoTransform = DES.CreateDecryptor() 'Create the crypto stream set to read and to do a DES decryption transform on incoming bytes. Dim cryptostreamDecr As New CryptoStream(fsread, desdecrypt, CryptoStreamMode.Read) 'Print out the contents of the decrypted file. Dim fsDecrypted As New StreamWriter(sOutputFilename) fsDecrypted.Write(New StreamReader(cryptostreamDecr).ReadToEnd) fsDecrypted.Flush() fsDecrypted.Close() End Sub Public Sub Main() 'Must be 64 bits, 8 bytes. Dim sSecretKey As String ' Get the key for the file to encrypt. ' You can distribute this key to the user who will decrypt the file. sSecretKey = GenerateKey() ' For additional security, pin the key. Dim gch As GCHandle = GCHandle.Alloc(sSecretKey, GCHandleType.Pinned) ' Encrypt the file. EncryptFile("%USERPROFILE%MyData.txt", _ "%USERPROFILE%Encrypted.txt", _ sSecretKey) ' Decrypt the file. DecryptFile("%USERPROFILE%Encrypted.txt", _ "%USERPROFILE%Decrypted.txt", _ sSecretKey) ' Remove the key from memory. ZeroMemory(gch.AddrOfPinnedObject(), sSecretKey.Length * 2) gch.Free() End Sub End Module
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote