Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Imports System.Security.Cryptography
- Imports System.Text
- Imports System.Runtime.Serialization.Formatters.Binary
- Imports System.Text.RegularExpressions
- Public Class Form1
- Public Function ReverseString(ByRef strToReverse As String) As String
- Dim result As String = ""
- For i As Integer = 0 To strToReverse.Length - 1
- result += strToReverse(strToReverse.Length - 1 - i)
- Next
- Return result
- End Function
- Public Function SimpleCrypt( _
- ByVal Text As String) As String
- ' Encrypts/decrypts the passed string using
- ' a simple ASCII value-swapping algorithm
- Dim strTempChar As String, i As Integer
- For i = 1 To Len(Text)
- If Asc(Mid$(Text, i, 1)) < 128 Then
- strTempChar = _
- CType(Asc(Mid$(Text, i, 1)) + 128, String)
- ElseIf Asc(Mid$(Text, i, 1)) > 128 Then
- strTempChar = _
- CType(Asc(Mid$(Text, i, 1)) - 128, String)
- End If
- Mid$(Text, i, 1) = _
- Chr(CType(strTempChar, Integer))
- Next i
- Return Text
- End Function
- Public Shared Function Crypt(ByVal Data As String, ByVal key As String) As String
- Return Encoding.Default.GetString(Crypt(Encoding.Default.GetBytes(Data), Encoding.Default.GetBytes(key)))
- End Function
- Public Shared Function Crypt(ByVal Data() As Byte, ByVal key() As Byte) As Byte()
- For i = 0 To (Data.Length * 2) + key.Length
- Data(i Mod Data.Length) = CByte(CInt((Data(i Mod Data.Length)) + CInt(Data((i + 1) Mod Data.Length))) Mod 256) Xor key(i Mod key.Length)
- Next
- Return Data
- End Function
- Public Shared Function DeCrypt(ByVal Data As String, ByVal key As String) As String
- Return Encoding.Default.GetString(DeCrypt(Encoding.Default.GetBytes(Data), Encoding.Default.GetBytes(key)))
- End Function
- Public Shared Function DeCrypt(ByVal Data() As Byte, ByVal key() As Byte) As Byte()
- For i = (Data.Length * 2) + key.Length To 0 Step -1
- Data(i Mod Data.Length) = CByte((CInt(Data(i Mod Data.Length) Xor key(i Mod key.Length)) - CInt(Data((i + 1) Mod Data.Length)) + 256) Mod 256)
- Next
- Return Data
- End Function
- Public Function XOREncrypt(ByVal CodeKey As String, ByVal DataIn As String) As String
- Dim lonDataPtr As Long
- Dim strDataOut As String
- Dim temp As Integer
- Dim tempstring As String
- Dim intXOrValue1 As Integer
- Dim intXOrValue2 As Integer
- For lonDataPtr = 1 To Len(DataIn)
- intXOrValue1 = Asc(Mid$(DataIn, lonDataPtr, 1))
- 'The second value comes from the code key
- intXOrValue2 = Asc(Mid$(CodeKey, ((lonDataPtr Mod Len(CodeKey)) + 1), 1))
- temp = (intXOrValue1 Xor intXOrValue2)
- tempstring = Hex(temp)
- If Len(tempstring) = 1 Then tempstring = "0" & tempstring
- strDataOut = strDataOut + tempstring
- Next lonDataPtr
- XOREncrypt = strDataOut
- End Function
- 'XOR Decryption
- Public Function XORDecrypt(ByVal CodeKey As String, ByVal DataIn As String) As String
- Dim lonDataPtr As Long
- Dim strDataOut As String
- Dim intXOrValue1 As Integer
- Dim intXOrValue2 As Integer
- For lonDataPtr = 1 To (Len(DataIn) / 2)
- intXOrValue1 = Val("&H" & (Mid$(DataIn, (2 * lonDataPtr) - 1, 2)))
- intXOrValue2 = Asc(Mid$(CodeKey, ((lonDataPtr Mod Len(CodeKey)) + 1), 1))
- strDataOut = strDataOut + Chr(intXOrValue1 Xor intXOrValue2)
- Next lonDataPtr
- XORDecrypt = strDataOut
- End Function
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- End Sub
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- TextBox1.Text = Crypt(TextBox1.Text, 2345)
- TextBox1.Text = ReverseString(TextBox1.Text)
- TextBox1.Text = SimpleCrypt(TextBox1.Text)
- TextBox1.Text = XOREncrypt(TextBox2.Text, TextBox1.Text)
- End Sub
- Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
- End Sub
- Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
- ' TextBox1.Text = XORDecrypt(2345, TextBox1.Text)
- 'TextBox1.Text = DeCrypt(TextBox1.Text, 2345)
- 'TextBox1.Text = SimpleCrypt(TextBox1.Text)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement