Advertisement
android

My sample Code

Mar 13th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 15.29 KB | None | 0 0
  1. Imports System.Security.Cryptography
  2. Imports System.IO
  3. Imports System.Text
  4.  
  5. Public Class Form1
  6.  
  7.         Dim operand1 As Double = 0
  8.         Dim operand2 As Double = 0
  9.         Dim op As String = Nothing
  10.         Dim newoperand As Boolean = True
  11.  
  12.         Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  13.                 Randomize()
  14.                 Dim a, b, c, d, f, g, h, i, j, k, l, Phrase As Integer
  15.                 Dim t As New Color
  16.                 Dim li As List(Of String) = New List(Of String)
  17.  
  18.  
  19.                 li.Add("Md5 Sum's and More!")
  20.                 li.Add("Md5 Sum's arn't they Great!")
  21.                 li.Add("It Has a Calculator!")
  22.                 li.Add("It Knows Binary!!")
  23.                 li.Add("It Does Hex")
  24.                 li.Add("It Does The Math For You ;)")
  25.                 li.Add("Are The Files The Same?? :D")
  26.                 li.Add("00110011001100000011001100110000001100110011000100110011001100010011001100000110011")
  27.  
  28.                 Me.Text = li.Item(Int(Rnd() * (li.Count - 1)))
  29.  
  30.                 t = Color.Transparent
  31.  
  32.                 a = Int(Rnd() * 255)
  33.                 b = Int(Rnd() * 255)
  34.                 c = Int(Rnd() * 255)
  35.                 d = Int(Rnd() * 255)
  36.                 f = Int(Rnd() * 255)
  37.                 g = Int(Rnd() * 255)
  38.                 h = Int(Rnd() * 255)
  39.                 i = Int(Rnd() * 255)
  40.                 j = Int(Rnd() * 255)
  41.                 k = Int(Rnd() * 255)
  42.                 l = Int(Rnd() * 255)
  43.  
  44.                 tabFile.BackColor = Color.FromArgb(a, b, c, 0)
  45.                 tabText.BackColor = Color.FromArgb(h, d, g, 0)
  46.                 tabCheck.BackColor = Color.FromArgb(j, k, h, 0)
  47.                 tabTexttoBinary.BackColor = Color.FromArgb(i, c, k, 0)
  48.                 tabTexttoHex.BackColor = Color.FromArgb(l, h, a, 0)
  49.                 tabCount.BackColor = Color.FromArgb(b, c, i, 0)
  50.                 tabCal.BackColor = Color.FromArgb(l, h, j, 0)
  51.                 tabAESDecriptText.BackColor = Color.FromArgb(i, g, h, 0)
  52.                 tabAESEncriptText.BackColor = Color.FromArgb(k, j, j, 0)
  53.  
  54.  
  55.                 MenuStrip1.BackColor = Color.FromArgb(b, k, f, 0)
  56.  
  57.                 btnFile.BackColor = Color.FromArgb(f, g, b, 0)
  58.                 btnText.BackColor = Color.FromArgb(b, l, c, 0)
  59.                 btnCheck.BackColor = Color.FromArgb(k, i, l, 0)
  60.                 btnBinary.BackColor = Color.FromArgb(g, j, b, 0)
  61.                 btnHex.BackColor = Color.FromArgb(c, a, d, 0)
  62.                 btnCount.BackColor = Color.FromArgb(a, g, k, 0)
  63.                 btnDecrypt.BackColor = Color.FromArgb(l, f, k, 0)
  64.                 btnEncrypt.BackColor = Color.FromArgb(b, d, d, 0)
  65.  
  66.                 btn0.Text = "0"
  67.                 btn1.Text = "1"
  68.                 btn2.Text = "2"
  69.                 btn3.Text = "3"
  70.                 btn4.Text = "4"
  71.                 btn5.Text = "5"
  72.                 btn6.Text = "6"
  73.                 btn7.Text = "7"
  74.                 btn8.Text = "8"
  75.                 btn9.Text = "9"
  76.                 btnDivide.Text = "/"
  77.                 btnDot.Text = "."
  78.                 btnEqual.Text = "="
  79.                 btnTimes.Text = "*"
  80.                 btnClear.Text = "Clear"
  81.                 btnPlus.Text = "+"
  82.                 btnOff.Text = "Off"
  83.                 btnMinus.Text = "-"
  84.  
  85.                 btn0.Tag = "0"
  86.                 btn1.Tag = "1"
  87.                 btn2.Tag = "2"
  88.                 btn3.Tag = "3"
  89.                 btn4.Tag = "4"
  90.                 btn5.Tag = "5"
  91.                 btn6.Tag = "6"
  92.                 btn7.Tag = "7"
  93.                 btn8.Tag = "8"
  94.                 btn9.Tag = "9"
  95.                 btnDivide.Tag = "/"
  96.                 btnDot.Tag = "."
  97.                 btnEqual.Tag = "="
  98.                 btnTimes.Tag = "*"
  99.                 btnPlus.Tag = "+"
  100.                 btnMinus.Tag = "-"
  101.  
  102.                 txtText.BackColor = Color.SteelBlue
  103.                 txtBinaryOutput.BackColor = Color.SteelBlue
  104.                 txtHexOutput.BackColor = Color.SteelBlue
  105.                 txtTextB.BackColor = Color.SteelBlue
  106.                 txtTextH.BackColor = Color.SteelBlue
  107.                 txtMd5.BackColor = Color.SteelBlue
  108.                 txtOutput.BackColor = Color.SteelBlue
  109.                 txtInput.BackColor = Color.SteelBlue
  110.                 txtDisplay.BackColor = Color.SteelBlue
  111.                 txtDecryptOutput.BackColor = Color.SteelBlue
  112.                 txtEncriptedOutput.BackColor = Color.SteelBlue
  113.                 txtToDecrypt.BackColor = Color.SteelBlue
  114.                 txtToEncrypt.BackColor = Color.SteelBlue
  115.                 txtTextC.BackColor = Color.SteelBlue
  116.  
  117.                 Label1.BackColor = t
  118.                 Label2.BackColor = t
  119.                 Label3.BackColor = t
  120.                 Label4.BackColor = t
  121.                 Label5.BackColor = t
  122.                 Label6.BackColor = t
  123.                 lblResualt.BackColor = t
  124.                 lblTotF.BackColor = t
  125.                 Label7.BackColor = t
  126.                 Label8.BackColor = t
  127.                 lblCharCount.BackColor = t
  128.                 Label11.BackColor = t
  129.                 Label10.BackColor = t
  130.                 Label9.BackColor = t
  131.  
  132.                 lblResualt.Text = Nothing
  133.                 lblTotF.Text = Nothing
  134.                 lblCharCount.Text = Nothing
  135.  
  136.                 Me.BackColor = Color.Thistle
  137.         End Sub
  138.  
  139.         Private Sub btnFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFile.Click
  140.  
  141.                 OpenFileDialog1.ShowDialog()
  142.  
  143.                 txtInput.Text = OpenFileDialog1.FileName()
  144.  
  145.                 txtOutput.Text = MD5CalcFile(OpenFileDialog1.FileName())
  146.  
  147.         End Sub
  148.  
  149.         Private Sub btnText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnText.Click
  150.  
  151.                 txtMd5Text.Text = StringToMD5(txtText.Text)
  152.  
  153.         End Sub
  154.  
  155.         Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
  156.  
  157.                 OpenFileDialog1.ShowDialog()
  158.  
  159.                 lblResualt.Text = MD5CalcFile(OpenFileDialog1.FileName())
  160.  
  161.                 If lblResualt.Text = txtMd5.Text Then
  162.  
  163.                         lblTotF.Text = "True"
  164.  
  165.                 Else
  166.  
  167.                         lblTotF.Text = "False, Md5 Not The Same"
  168.  
  169.                 End If
  170.  
  171.         End Sub
  172.  
  173.         Private Sub btnBinary_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBinary.Click
  174.  
  175.                 txtBinaryOutput.Text = ConvertToBinary(txtTextB.Text)
  176.  
  177.         End Sub
  178.  
  179.         Private Sub btnHex_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHex.Click
  180.  
  181.                 Dim str As String
  182.                 Dim byteArray() As Byte
  183.                 Dim hexNumbers As System.Text.StringBuilder = New System.Text.StringBuilder
  184.  
  185.                 str = txtTextH.Text
  186.  
  187.                 byteArray = System.Text.ASCIIEncoding.ASCII.GetBytes(str)
  188.  
  189.                 For i As Integer = 0 To byteArray.Length - 1
  190.  
  191.                         hexNumbers.Append(byteArray(i).ToString("x"))
  192.  
  193.                 Next
  194.  
  195.                 txtHexOutput.Text = hexNumbers.ToString()
  196.  
  197.         End Sub
  198.  
  199.         Private Sub btnCount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCount.Click
  200.                 Dim a As String
  201.  
  202.                 a = txtTextC.Text
  203.  
  204.                 a = a.Trim
  205.  
  206.                 a = a.Length
  207.  
  208.                 lblCharCount.Text = a
  209.  
  210.         End Sub
  211.  
  212.         Public Function ConvertToBinary(ByVal str As String) As String
  213.  
  214.                 Dim converted As New StringBuilder
  215.  
  216.                 For Each b As Byte In ASCIIEncoding.ASCII.GetBytes(str)
  217.  
  218.                         converted.Append(Convert.ToString(b, 2).PadLeft(8, "0"))
  219.  
  220.                 Next
  221.  
  222.                 Return converted.ToString()
  223.  
  224.         End Function
  225.  
  226.         Private Function StringToMD5(ByVal Content As String) As String
  227.  
  228.                 Dim M5 As New Security.Cryptography.MD5CryptoServiceProvider
  229.  
  230.                 Dim ByteString() As Byte = System.Text.Encoding.ASCII.GetBytes(Content)
  231.  
  232.                 ByteString = M5.ComputeHash(ByteString)
  233.  
  234.                 Dim FinalString As String = Nothing
  235.  
  236.                 For Each bt As Byte In ByteString
  237.  
  238.                         FinalString &= bt.ToString("x2")
  239.  
  240.                 Next
  241.  
  242.                 Return FinalString
  243.  
  244.         End Function
  245.  
  246.         Public Function MD5CalcFile(ByVal filepath As String) As String
  247.  
  248.                 Using reader As New System.IO.FileStream(filepath, IO.FileMode.Open, IO.FileAccess.Read)
  249.  
  250.                         Using md5 As New System.Security.Cryptography.MD5CryptoServiceProvider
  251.  
  252.                                 Dim hash() As Byte = md5.ComputeHash(reader)
  253.  
  254.                                 Return ByteArrayToString(hash)
  255.  
  256.                         End Using
  257.  
  258.                 End Using
  259.  
  260.         End Function
  261.  
  262.         Private Function ByteArrayToString(ByVal arrInput() As Byte) As String
  263.  
  264.                 Dim sb As New System.Text.StringBuilder(arrInput.Length * 2)
  265.  
  266.                 For i As Integer = 0 To arrInput.Length - 1
  267.                         sb.Append(arrInput(i).ToString("X2"))
  268.                 Next
  269.  
  270.                 Return sb.ToString().ToLower
  271.  
  272.         End Function
  273.  
  274.  
  275.         Private Sub btnOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOff.Click
  276.                 Application.Exit()
  277.         End Sub
  278.  
  279.         Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDot.Click, btn0.Click, btn1.Click, btn2.Click, btn3.Click, btn4.Click, btn5.Click, btn6.Click, btn7.Click, btn8.Click, btn9.Click
  280.                 Dim btnNumberClicked As Button = sender
  281.                 If newoperand Then
  282.                         txtDisplay.Text = btnNumberClicked.Tag
  283.                         newoperand = False
  284.                 Else
  285.                         txtDisplay.Text &= btnNumberClicked.Tag
  286.                 End If
  287.         End Sub
  288.  
  289.         Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
  290.                 txtDisplay.Text = "0"
  291.                 operand1 = 0
  292.                 operand2 = 0
  293.                 newoperand = True
  294.                 op = Nothing
  295.         End Sub
  296.  
  297.         Private Sub btnOperator_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivide.Click, btnPlus.Click, btnMinus.Click, btnTimes.Click, btnEqual.Click
  298.  
  299.                 Dim operatorSelected As Button = sender
  300.  
  301.                 If (operand1 = 0 And op = Nothing) Or op = "=" Then
  302.                         operand1 = Val(txtDisplay.Text)
  303.                 Else
  304.                         operand2 = Val(txtDisplay.Text)
  305.                         operand1 = Calcualte(operand1, operand2, op)
  306.                         Me.txtDisplay.Text = operand1
  307.  
  308.                 End If
  309.  
  310.                 op = operatorSelected.Tag
  311.                 newoperand = True
  312.  
  313.         End Sub
  314.  
  315.         Function Calcualte(ByVal firstOperand As Double, ByVal secondOperand As Double, ByVal op As String) As Double
  316.                 Select Case op
  317.                         Case "+"
  318.                                 Return (firstOperand + secondOperand)
  319.                         Case "-"
  320.                                 Return (firstOperand - secondOperand)
  321.                         Case "x"
  322.                                 Return (firstOperand * secondOperand)
  323.                         Case "/"
  324.                                 Return (firstOperand / secondOperand)
  325.                 End Select
  326.         End Function
  327.  
  328.         Private Sub StringsToolSripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StringsToolStripMenuItem.Click
  329.                 Form2.Show()
  330.         End Sub
  331.  
  332.         Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  333.                 Application.Exit()
  334.         End Sub
  335.  
  336.         Public Function AES_Encrypt(ByVal input As String, ByVal pass As String) As String
  337.                 Dim AES As New System.Security.Cryptography.RijndaelManaged
  338.  
  339.                 Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
  340.  
  341.                 Dim encrypted As String = ""
  342.  
  343.                 Try
  344.  
  345.                         Dim hash(31) As Byte
  346.  
  347.                         Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))
  348.  
  349.                         Array.Copy(temp, 0, hash, 0, 16)
  350.  
  351.                         Array.Copy(temp, 0, hash, 15, 16)
  352.  
  353.                         AES.Key = hash
  354.  
  355.                         AES.Mode = Security.Cryptography.CipherMode.ECB
  356.  
  357.                         Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateEncryptor
  358.  
  359.                         Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(input)
  360.  
  361.                         encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
  362.  
  363.                         Return encrypted
  364.  
  365.                 Catch ex As Exception
  366.  
  367.                 End Try
  368.  
  369.         End Function
  370.  
  371.         Public Function AES_Decrypt(ByVal input As String, ByVal pass As String) As String
  372.                 Dim AES As New System.Security.Cryptography.RijndaelManaged
  373.  
  374.                 Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
  375.  
  376.                 Dim decrypted As String = ""
  377.  
  378.                 Try
  379.  
  380.                         Dim hash(31) As Byte
  381.  
  382.                         Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))
  383.  
  384.                         Array.Copy(temp, 0, hash, 0, 16)
  385.  
  386.                         Array.Copy(temp, 0, hash, 15, 16)
  387.  
  388.                         AES.Key = hash
  389.  
  390.                         AES.Mode = Security.Cryptography.CipherMode.ECB
  391.  
  392.                         Dim DESDecrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateDecryptor
  393.  
  394.                         Dim Buffer As Byte() = Convert.FromBase64String(input)
  395.  
  396.                         decrypted = System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
  397.  
  398.                         Return decrypted
  399.  
  400.                 Catch ex As Exception
  401.  
  402.                 End Try
  403.  
  404.         End Function
  405.  
  406.         Private Sub btnEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEncrypt.Click
  407.                 Dim Pass As String
  408.  
  409.                 Pass = InputBox("Enter The PassWord To Encrypt With:")
  410.  
  411.                 If Pass = Nothing Then
  412.  
  413.                         MessageBox.Show("Y U NO ENTER A PASSWORD?")
  414.  
  415.                 Else
  416.  
  417.                         txtEncriptedOutput.Text = AES_Encrypt(txtToEncrypt.Text, Pass)
  418.  
  419.                 End If
  420.  
  421.         End Sub
  422.  
  423.         Private Sub btnDecrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecrypt.Click
  424.                 Dim Pass As String
  425.  
  426.                 Pass = InputBox("Enter The PassWord To Encrypt With:")
  427.  
  428.                 If Pass = Nothing Then
  429.  
  430.                         MessageBox.Show("Y U NO ENTER A PASSWORD?")
  431.  
  432.                 Else
  433.  
  434.                         txtDecryptOutput.Text = AES_Decrypt(txtToDecrypt.Text, Pass)
  435.  
  436.                 End If
  437.  
  438.         End Sub
  439.  
  440. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement