Decryption Medoth Skips character at indexes of length of Key (1 Viewer)

BlueIshDan

☠
Local time
Today, 14:28
Joined
May 15, 2014
Messages
1,122
:banghead::banghead::banghead::banghead::banghead::banghead::banghead:
Hello I'm going back to try and repair my Encryption/Decryption form that I made almost a year ago now.

My form allows the user to describe a string to be encrypted and the length of the key they wish to encrypt it with.

The program generates a key and encrypts the string based on it.

The problem resides in the decryption process. Every character that resides at the index of the length of the key (incremented) + 1 is skipped.

Say if I describe this:
Value: BlueIshdan
key_length: 5

Generated Key: ÝÈÚS (there is a value not visible here)
Encrypted Value: 0.649321266968326 0.665 N 0.651376146788991 • 0.744343891402715 0.77 x 0.747706422018349 ¿ 0.764705882352941 0.7925 0.768348623853211 È 0.728506787330317 0.7525 q 0.731651376146789 ¸ 0.665158371040724 0.6825 U 0.667431192660551 œ 0.760180995475113 0.7875  0.763761467889908 Æ 0.735294117647059 0.76 t 0.738532110091743 » 0.653846153846154 0.67 P 0.655963302752294 — 0.719457013574661 0.7425 m 0.722477064220184 ´ 0.748868778280543 0.775 z 0.752293577981651 Á

After Decryption: BlueIhDan

Here is the decryption code:

Code:
Private Sub btnDecrypt_Click()
    Dim hiddenDecryption As String
    Dim decryption As String
    Dim keyAsc() As Byte
    Dim keyCount As Integer
    Dim keyLength As Integer
    Dim dec As Integer
    
    keyLength = Len(txtKey.Value)
    keyCount = 0
    
    keyAsc = StrConv(txtKey.Value, vbFromUnicode)

    For Each node In Split(txtPlainText.Value, " ")
    
        If keyCount = 0 Then: hiddenDecryption = hiddenDecryption & node & " "
        
        txtPlainText = hiddenDecryption
        DoEvents
        Pause (0.01)
        
        If keyCount + 1 <= keyLength Then
            keyCount = keyCount + 1
        Else: keyCount = 0
        End If
        
    Next

    keyCount = 0
    
    For Each node In Split(hiddenDecryption, " ")
    
        If IsNumeric(node) Then
        
            dec = InStr(1, node, ".")
            
            If dec > 0 Then
            
                If Mid(node, dec, Len(node) - dec) > 0 Then
                    decryption = decryption & Chr((node * (keyAsc(keyCount) * 2)) - keyAsc(keyCount))
                Else: decryption = decryption & Chr(Asc(node) - keyAsc(keyCount))
                End If
                
            Else: decryption = decryption & Chr(Asc(node) - keyAsc(keyCount))
            End If
            
        ElseIf Not IsNull(node) And Not node = "" Then
        
            'a = Asc(node) Was for debugging purposes.
            decryption = decryption & Chr(Asc(node) - keyAsc(keyCount))
            
        End If
        
        If keyCount + 1 < keyLength Then
            keyCount = keyCount + 1
        Else: keyCount = 0
        End If
        
        txtPlainText.Value = decryption
        DoEvents
        Pause (0.01)
        
    Next
    
    MsgBox (decryption)
    txtPlainText = decryption
    
End Sub
 

pr2-eugin

Super Moderator
Local time
Today, 18:28
Joined
Nov 30, 2011
Messages
8,494
What Encryption algorithm is this? Or is this one of your own?
 

BlueIshDan

&#9760;
Local time
Today, 14:28
Joined
May 15, 2014
Messages
1,122
This is one of my own.
I can show you what the code is is you'd like.
 

pr2-eugin

Super Moderator
Local time
Today, 18:28
Joined
Nov 30, 2011
Messages
8,494
It would be very interesting to look at your own encryption module ! ;) If you have it well commented, that would just save me pulling all my hair out.
 

vbaInet

AWF VIP
Local time
Today, 18:28
Joined
Jan 22, 2010
Messages
26,374
I can't really read your code without any comments on it so it would be nice to have some annotations.

I suppose creating your own encryption/decryption algorithm is nice but it would be easy to break... especially seeing that you've given us the code :D

In any case, here are some other suggestions:

http://www.access-programmers.co.uk/forums/showthread.php?t=200366

You can check out the Bob Larson one or the route The Doc Man uses. I would go with The Doc Man because those are proven encryption strategies with several layers of security. There are a couple of other encryption libraries you could look into as well.
 

BlueIshDan

&#9760;
Local time
Today, 14:28
Joined
May 15, 2014
Messages
1,122
I definitely do not have it well commented, I'm also kicking my ass for not doing so.
I never think to comment my side projects that I start and drop so quickly :(
 

vbaInet

AWF VIP
Local time
Today, 18:28
Joined
Jan 22, 2010
Messages
26,374
If you ever need to hand over your project you'll need to have those comments in. It's also a good reminder for you as well so you don't have to read the entire thing to understand what you wrote.

I used to have a habit of writing comments about a module or class immediately after creating it and writing comments for a property or method immediately after completing it. I also had a template of comments so it was just a matter of copying and pasting then filling in the blanks.
 

BlueIshDan

&#9760;
Local time
Today, 14:28
Joined
May 15, 2014
Messages
1,122
I usually do comment my code.
Just not in the, probably way to many, projects that I start and drop out of boredom at work.
 

nanscombe

Registered User.
Local time
Today, 18:28
Joined
Nov 12, 2011
Messages
1,082
I would probably put a breakpoint at the beginning, watches on the values of your loops and single step through the code.

Look out for any unexpected values where your loop counters reset. I suspect that there might be a line of code which resets a pointer incorrectly, 0 instead of 1 or 1 instead of 0.

Either that or it simply skips over the character at the position which matches the length of your key.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 18:28
Joined
Sep 12, 2006
Messages
15,640
Access strings use unicode chars, which have 2 bytes per character. You need to take this into acccount when manipulating strings in some ways. Is this a possibility with your encryption algorithm?
 

BlueIshDan

&#9760;
Local time
Today, 14:28
Joined
May 15, 2014
Messages
1,122
No but funny you say that. I had to find that out the hard way when I was working on a project where I had to change values in Microstation CAD files. Notepad and UltraEdit were placing extra bytes(0) between each character I put in. So wrote a byte replacement program in access which solved the problem.
 

Users who are viewing this thread

Top Bottom