Results 1 to 4 of 4

Thread: Ben's Encryption codes

Threaded View

  1. #1

    Thread Starter
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 2010
    Location
    Wales UK
    Posts
    814

    Lightbulb Ben's Encryption codes

    Hi this page will contain some of my little snippets of encryption codes this is my first try it a basic encryption using XOR and random function it also uses a function to get a hash coded from your password hope you like this first example. comments and suggestions welcome.


    Sniplet 1 XOR using random encryption for strings.

    vbnet Code:
    1. Public Class Form1
    2.  
    3.     Private Function GetHash(ByVal source As String) As Integer
    4.         Dim hash As Integer = 0
    5.         'Add some random hex codes add more if you want.
    6.         Dim Magic = {&H3FEE, &H3A9B, &H3977, &H37A4, &H3583, &H3019, &H2F86, &H2E55, &H554}
    7.         'Build hash code.
    8.         For x As Integer = 0 To source.Length - 1
    9.             hash = (hash >> 2) Xor Asc(source(x)) + Magic(x And &H8)
    10.         Next x
    11.  
    12.         Return hash
    13.  
    14.     End Function
    15.  
    16.     Private Function EncryptString(ByVal source As String, ByVal Password As String) As String
    17.         Dim Hash As Integer = 0
    18.         Dim sb As New System.Text.StringBuilder()
    19.         'Get hash of password.
    20.         Hash = GetHash(Password)
    21.  
    22.         Rnd(-3)
    23.         'Random hash
    24.         Randomize(hash)
    25.  
    26.         For x As Integer = 0 To source.Length - 1
    27.             Dim b As Byte = Asc(source(x)) Xor Int(Rnd() * Hash) Mod 256
    28.             'Append chars.
    29.             sb.Append(Chr(b))
    30.         Next x
    31.  
    32.         'Return string
    33.         Return sb.ToString
    34.     End Function
    35.  
    36.     Private Sub cmdTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTest.Click
    37.         Dim src As String = "hello,hello,hello world"
    38.  
    39.         Dim en As String = EncryptString(src, "secret")
    40.         Dim de As String = EncryptString(en, "secret")
    41.  
    42.         'Show encrypted string.
    43.         MessageBox.Show("Encrypted string: " & en, "Encrypt1", MessageBoxButtons.OK, MessageBoxIcon.Information)
    44.         'Show decrypted string.
    45.         MessageBox.Show("Decrypted string: " & de, "Encrypt1", MessageBoxButtons.OK, MessageBoxIcon.Information)
    46.     End Sub
    47.  
    48. End Class
    Last edited by BenJones; Sep 3rd, 2012 at 06:55 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width