Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Encryption
- Public Function Encrypt(Data As String, Key As String) As String
- Dim formattedKey As UInteger() = FormatKey(Key)
- If Data.Length Mod 2 <> 0 Then
- Data += ControlChars.NullChar
- End If
- ' Make sure array is even in length.
- Dim dataBytes As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
- Dim cipher As String = String.Empty
- Dim tempData As UInteger() = New UInteger(1) {}
- For i As Integer = 0 To dataBytes.Length - 1 Step 2
- tempData(0) = dataBytes(i)
- tempData(1) = dataBytes(i + 1)
- code(tempData, formattedKey)
- cipher += ConvertUIntToString(tempData(0)) + ConvertUIntToString(tempData(1))
- Next
- Return cipher
- End Function
- 'Decryption
- Public Function Decrypt(Data As String, Key As String) As String
- Dim formattedKey As UInteger() = FormatKey(Key)
- Dim x As Integer = 0
- Dim tempData As UInteger() = New UInteger(1) {}
- Dim dataBytes As Byte() = New Byte(Data.Length / 8 * 2 - 1) {}
- For i As Integer = 0 To Data.Length - 1 Step 8
- tempData(0) = ConvertStringToUInt(Data.Substring(i, 4))
- tempData(1) = ConvertStringToUInt(Data.Substring(i + 4, 4))
- decode(tempData, formattedKey)
- dataBytes(System.Math.Max(System.Threading.Interlocked.Increment(x),x - 1)) = CByte(tempData(0))
- dataBytes(System.Math.Max(System.Threading.Interlocked.Increment(x),x - 1)) = CByte(tempData(1))
- Next
- Dim decipheredString As String = System.Text.ASCIIEncoding.ASCII.GetString(dataBytes, 0, dataBytes.Length)
- ' Strip the null char if it was added.
- If decipheredString(decipheredString.Length - 1) = ControlChars.NullChar Then
- decipheredString = decipheredString.Substring(0, decipheredString.Length - 1)
- End If
- Return decipheredString
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement