Results 1 to 3 of 3

Thread: encryption

  1. #1

    Thread Starter
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    860

    encryption

    Hi, I,ve been wroking on an algorythm to encrypt data I save to
    files... so far I,ve got it mixing and raising it.. I just wanted to
    know how I could put... uh.. 'junk' characters in it. I,ve tried it but
    nothing's worked so far. Here's what I've got so far...

    ---------------------------------------
    Private Sub demix(code As Variant)
    Dim code2 As String
    code = CStr(code)
    b = 1
    Do Until a = Len(code) + 3
    For a = 1 To Len(code) Step 2
    If Asc(Mid(code, a, 1)) = b Then code2 = code2 + Mid(code, a + 1, 1): b = b + 1: c = True
    If (b - 1) * 2 >= Len(code) Then GoTo 1
    Next a
    If c = False Then MsgBox "Decryption error", vbCritical, "Warning": Call raise(code): Exit Sub
    c = False
    Loop
    1
    code = code2
    Text1.Text = code
    End Sub

    Private Sub mix(code As Variant)
    Dim codeset() As Boolean
    Dim code2 As String
    Dim counter As Variant
    code = CStr(code)
    ReDim codeset(Len(code))
    Do Until a = Len(code) + 1
    a = Int(Rnd * Len(code)) + 1
    If codeset(a) = False Then codeset(a) = True: code2 = code2 + Chr$(a): code2 = code2 + Mid(code, a, 1): counter = counter + 1
    If counter = Len(code) Then a = Len(code) + 1
    Loop
    code = code2
    Text1.Text = code
    End Sub

    Private Sub raise(code As Variant)
    Dim code2 As String
    code = CStr(code)
    On Error GoTo 1
    For a = 1 To Len(code)
    code2 = code2 + Chr$(Asc(Mid(code, a, 1)) + 3)
    Next a
    code = code2
    Text1.Text = code
    Exit Sub
    1
    MsgBox "Encryption error", vbCritical, "Warning"
    End Sub

    Private Sub lower(code As Variant)
    Dim code2 As String
    code = CStr(code)
    On Error GoTo 1
    For a = 1 To Len(code)
    code2 = code2 + Chr$(Asc(Mid(code, a, 1)) - 3)
    Next a
    code = code2
    Text1.Text = code
    Exit Sub
    1
    MsgBox "Decryption error", vbCritical, "Warning"
    End Sub

    Private Sub Command1_Click()
    If Not Text1.Text = "" And Not Len(Text1.Text) > 255 Then
    Call mix(Text1.Text)
    Call raise(Text1.Text)
    End If
    End Sub
    Private Sub Command2_Click()
    If Not Text1.Text = "" And Not Len(Text1.Text) > 255 * 2 Then
    Call lower(Text1.Text)
    Call demix(Text1.Text)
    End If
    End Sub
    -------------------------------------------

    Here's "hello" after I've encrypted it 5 times:

    &$ RD;~%> ,O
    {7 

    P/+
    Q
    
    "#,+-0 L8"' @<'&B*!9J C wGK!A4(H$2.NI%?)36#1.F
    5{ tS) E(-=:* M

    any ideas?
    Don't pay attention to this signature, it's contradictory.

  2. #2
    Zaei
    Guest
    Using the Rnd() function in encryption is a big no-no. You have no idea what is going to come out of that function, which means that if you use it to encrypt (as you are), you have no way to decrypt. I would suggest that at every N characters in the source string, you insert M junk characters:
    Code:
    For i = 1 to Len(src)
      dest = dest & Mid(src, i, 1)
      If i mod N = 0 Then
        For j = 0 to M - 1
           dest = dest & chr(Int(Rnd() * 255))
        Next j
       End If
    Next i
    Z.

  3. #3

    Thread Starter
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    860

    actually

    the rnd function makes the encryption better, if u'd looked more closely at the code, you'd have noticed that it puts what came out of the rnd function in the string, then the decrypt uses that to put it back together....
    Don't pay attention to this signature, it's contradictory.

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