Advertisement
nicksonthc

NicHardwareBasedEncryption

Sep 18th, 2018
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.66 KB | None | 0 0
  1. Public Class NicHardwareBasedEncryption
  2.     Dim hexKey As Integer = &HFF
  3.     Dim input As String
  4.     Dim strEncrypt As String
  5.  
  6. 'This function use to encrypt string,input is require.
  7. 'For example : Nickson Printer:Nic1234,Serial:0001,Point:20,Date:2018-09-19 13:33:30
  8.   Function Encryption(str As String) As String
  9.         Dim outputString As String = ""
  10.         Dim charArray() As Char = str.ToCharArray
  11.  
  12.         For i As Integer = 0 To charArray.Length - 1
  13.  
  14.             Dim hexStr As Integer = Convert.ToInt32(charArray(i))
  15.             Dim encryptStr As String = hexStr Xor hexKey
  16.             Dim outputStr As String = Hex(encryptStr)
  17.  
  18.             outputString = outputString & String.Join("", outputStr)
  19.         Next
  20.         Return outputString
  21.     End Function
  22.  
  23.  
  24. 'This function use to decrypt string and return output
  25. 'For example output : B1969C948C9091DFAF8D96918B9A8DC5B1969CCECDCCCBD3AC9A8D969E93C5CFCFCFCED3AF9096918BC5CDCFD3BBCCF.......
  26.     Function Decryption(qrcodeOutput As String) As String
  27.         Dim len As Integer = qrcodeOutput.Length / 2
  28.         Dim outputString As String = ""
  29.  
  30.         For i As Integer = 0 To len - 1
  31.             Dim tempStr As String = qrcodeOutput.Substring(i * 2, 2)
  32.  
  33.             Dim hexStr As Integer = Convert.ToInt32(tempStr, 16) Xor hexKey
  34.             Dim charStr As Char = Convert.ToChar(hexStr)
  35.  
  36.             outputString = outputString & String.Join("", charStr)
  37.         Next
  38.  
  39.         Return outputString
  40.     End Function
  41.  
  42.  
  43. 'This Function use to separate string
  44.     Function ChopString(decryptString As String) As String()
  45.         ChopString = decryptString.Split(",")
  46.         For Each arr As String In ChopString
  47.             lstBox.Items.Add("String After Split  : " & arr)
  48.         Next
  49.     End Function
  50.  
  51. 'When user click Encrypt
  52.     Private Sub btnEncrypt_Click(sender As Object, e As EventArgs) Handles btnEncrypt.Click
  53.         input = txtEncrypt.Text   'get input text
  54.         strEncrypt = (Encryption(input)) 'encrypt and assign to variable
  55.         txtEnOutput.Text = strEncrypt 'set output textbox = variable
  56.  
  57.         lstBox.Items.Add("Original String Input " & vbNewLine & input)
  58.         lstBox.Items.Add("Encrypted Output" & vbNewLine & strEncrypt)
  59.     End Sub
  60.  
  61. 'When user click Decrypt
  62.     Private Sub btnDecrypt_Click(sender As Object, e As EventArgs) Handles btnDecrypt.Click
  63.         Dim strDecrypte As String = Decryption(strEncrypt) 'decrypt with encrypt input
  64.         txtDeOutput.Text = strDecrypte  'set decrypt output to textbox
  65.  
  66.         lstBox.Items.Add("Decrypted Output" & vbNewLine & strDecrypte)
  67.         'separate string from output
  68.         ChopString(strDecrypte)
  69.     End Sub
  70.  
  71. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement