Advertisement
ZeekoSec

Projekt Uge

Apr 13th, 2015
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.49 KB | None | 0 0
  1. Imports System.IO
  2. Imports System.Security.Cryptography
  3. Imports System.Text
  4. Imports System.Runtime.Serialization.Formatters.Binary
  5. Imports System.Text.RegularExpressions
  6.  
  7. Public Class Form1
  8.     Public Function ReverseString(ByRef strToReverse As String) As String
  9.         Dim result As String = ""
  10.         For i As Integer = 0 To strToReverse.Length - 1
  11.             result += strToReverse(strToReverse.Length - 1 - i)
  12.         Next
  13.         Return result
  14.     End Function
  15.     Public Function SimpleCrypt( _
  16.        ByVal Text As String) As String
  17.         ' Encrypts/decrypts the passed string using
  18.         ' a simple ASCII value-swapping algorithm
  19.         Dim strTempChar As String, i As Integer
  20.         For i = 1 To Len(Text)
  21.             If Asc(Mid$(Text, i, 1)) < 128 Then
  22.                 strTempChar = _
  23.           CType(Asc(Mid$(Text, i, 1)) + 128, String)
  24.             ElseIf Asc(Mid$(Text, i, 1)) > 128 Then
  25.                 strTempChar = _
  26.           CType(Asc(Mid$(Text, i, 1)) - 128, String)
  27.             End If
  28.             Mid$(Text, i, 1) = _
  29.                 Chr(CType(strTempChar, Integer))
  30.         Next i
  31.         Return Text
  32.     End Function
  33.  
  34.     Public Shared Function Crypt(ByVal Data As String, ByVal key As String) As String
  35.         Return Encoding.Default.GetString(Crypt(Encoding.Default.GetBytes(Data), Encoding.Default.GetBytes(key)))
  36.     End Function
  37.     Public Shared Function Crypt(ByVal Data() As Byte, ByVal key() As Byte) As Byte()
  38.         For i = 0 To (Data.Length * 2) + key.Length
  39.             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)
  40.         Next
  41.         Return Data
  42.     End Function
  43.     Public Shared Function DeCrypt(ByVal Data As String, ByVal key As String) As String
  44.         Return Encoding.Default.GetString(DeCrypt(Encoding.Default.GetBytes(Data), Encoding.Default.GetBytes(key)))
  45.     End Function
  46.     Public Shared Function DeCrypt(ByVal Data() As Byte, ByVal key() As Byte) As Byte()
  47.         For i = (Data.Length * 2) + key.Length To 0 Step -1
  48.             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)
  49.         Next
  50.         Return Data
  51.     End Function
  52.     Public Function XOREncrypt(ByVal CodeKey As String, ByVal DataIn As String) As String
  53.         Dim lonDataPtr As Long
  54.         Dim strDataOut As String
  55.         Dim temp As Integer
  56.         Dim tempstring As String
  57.         Dim intXOrValue1 As Integer
  58.         Dim intXOrValue2 As Integer
  59.         For lonDataPtr = 1 To Len(DataIn)
  60.             intXOrValue1 = Asc(Mid$(DataIn, lonDataPtr, 1))
  61.             'The second value comes from the code key
  62.             intXOrValue2 = Asc(Mid$(CodeKey, ((lonDataPtr Mod Len(CodeKey)) + 1), 1))
  63.             temp = (intXOrValue1 Xor intXOrValue2)
  64.             tempstring = Hex(temp)
  65.             If Len(tempstring) = 1 Then tempstring = "0" & tempstring
  66.             strDataOut = strDataOut + tempstring
  67.         Next lonDataPtr
  68.         XOREncrypt = strDataOut
  69.     End Function
  70.     'XOR Decryption
  71.     Public Function XORDecrypt(ByVal CodeKey As String, ByVal DataIn As String) As String
  72.         Dim lonDataPtr As Long
  73.         Dim strDataOut As String
  74.         Dim intXOrValue1 As Integer
  75.         Dim intXOrValue2 As Integer
  76.         For lonDataPtr = 1 To (Len(DataIn) / 2)
  77.             intXOrValue1 = Val("&H" & (Mid$(DataIn, (2 * lonDataPtr) - 1, 2)))
  78.             intXOrValue2 = Asc(Mid$(CodeKey, ((lonDataPtr Mod Len(CodeKey)) + 1), 1))
  79.             strDataOut = strDataOut + Chr(intXOrValue1 Xor intXOrValue2)
  80.         Next lonDataPtr
  81.         XORDecrypt = strDataOut
  82.     End Function
  83.    
  84.  
  85.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  86.  
  87.     End Sub
  88.  
  89.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  90.         TextBox1.Text = Crypt(TextBox1.Text, 2345)
  91.         TextBox1.Text = ReverseString(TextBox1.Text)
  92.         TextBox1.Text = SimpleCrypt(TextBox1.Text)
  93.         TextBox1.Text = XOREncrypt(TextBox2.Text, TextBox1.Text)
  94.  
  95.     End Sub
  96.     Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
  97.  
  98.     End Sub
  99.  
  100.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  101.         ' TextBox1.Text = XORDecrypt(2345, TextBox1.Text)
  102.         'TextBox1.Text = DeCrypt(TextBox1.Text, 2345)
  103.         'TextBox1.Text = SimpleCrypt(TextBox1.Text)
  104.     End Sub
  105. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement