Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class NicHardwareBasedEncryption
- Dim hexKey As Integer = &HFF
- Dim input As String
- Dim strEncrypt As String
- 'This function use to encrypt string,input is require.
- 'For example : Nickson Printer:Nic1234,Serial:0001,Point:20,Date:2018-09-19 13:33:30
- Function Encryption(str As String) As String
- Dim outputString As String = ""
- Dim charArray() As Char = str.ToCharArray
- For i As Integer = 0 To charArray.Length - 1
- Dim hexStr As Integer = Convert.ToInt32(charArray(i))
- Dim encryptStr As String = hexStr Xor hexKey
- Dim outputStr As String = Hex(encryptStr)
- outputString = outputString & String.Join("", outputStr)
- Next
- Return outputString
- End Function
- 'This function use to decrypt string and return output
- 'For example output : B1969C948C9091DFAF8D96918B9A8DC5B1969CCECDCCCBD3AC9A8D969E93C5CFCFCFCED3AF9096918BC5CDCFD3BBCCF.......
- Function Decryption(qrcodeOutput As String) As String
- Dim len As Integer = qrcodeOutput.Length / 2
- Dim outputString As String = ""
- For i As Integer = 0 To len - 1
- Dim tempStr As String = qrcodeOutput.Substring(i * 2, 2)
- Dim hexStr As Integer = Convert.ToInt32(tempStr, 16) Xor hexKey
- Dim charStr As Char = Convert.ToChar(hexStr)
- outputString = outputString & String.Join("", charStr)
- Next
- Return outputString
- End Function
- 'This Function use to separate string
- Function ChopString(decryptString As String) As String()
- ChopString = decryptString.Split(",")
- For Each arr As String In ChopString
- lstBox.Items.Add("String After Split : " & arr)
- Next
- End Function
- 'When user click Encrypt
- Private Sub btnEncrypt_Click(sender As Object, e As EventArgs) Handles btnEncrypt.Click
- input = txtEncrypt.Text 'get input text
- strEncrypt = (Encryption(input)) 'encrypt and assign to variable
- txtEnOutput.Text = strEncrypt 'set output textbox = variable
- lstBox.Items.Add("Original String Input " & vbNewLine & input)
- lstBox.Items.Add("Encrypted Output" & vbNewLine & strEncrypt)
- End Sub
- 'When user click Decrypt
- Private Sub btnDecrypt_Click(sender As Object, e As EventArgs) Handles btnDecrypt.Click
- Dim strDecrypte As String = Decryption(strEncrypt) 'decrypt with encrypt input
- txtDeOutput.Text = strDecrypte 'set decrypt output to textbox
- lstBox.Items.Add("Decrypted Output" & vbNewLine & strDecrypte)
- 'separate string from output
- ChopString(strDecrypte)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement