Question Simple Encoding / Decoding Problem

lilwiccaseba

New member
Joined
Feb 6, 2009
Messages
2
Programming Experience
Beginner
Hey ,

I'm using some functions which can be compared to encoding/decoding, but it's a really simple and basic application, not really an encoding function.

The problem is, the decoding function doesn't seem to work. For some reason, it doesn't work correctly, and I'm a bit stressed, so even after searching for a while, I can't seem to find it.

Would be cool if any of you could help me out. Thx.

Function Syntax used:
( 'Encrypted' word is sebastien )

VB.NET:
MsgBox(TwiDec("115101987971151167105101110", 3, "332233333"))

Decoding Function:
VB.NET:
Public Function TwiDec(ByVal phrase As String, ByVal numRem As Integer, ByVal encLength As String)
        Dim decoded As String = ""
        Dim curNum As Integer = 0
        Dim curChar As String = ""
        Dim intChar As Integer = 0

        For i As Integer = 0 To phrase.Length - 1
            While curChar.Length.ToString <> encLength(intChar)
                If curNum <> numRem Then
                    curChar = curChar & phrase(i)
                    i = i + 1
                Else
                    curNum = 0
                    i = i + 1
                End If
            End While

            curNum = curNum + 1
            intChar = intChar + 1
            decoded = decoded & Chr(curChar)
            'Chr(curChar)
            curChar = ""

        Next i

        Return decoded
End Function

And the encoding function:
VB.NET:
Public Function TwiEnc(ByVal phrase As String, ByVal numRem As Integer)
        Dim encoded As String = ""
        Dim encLength As String = ""
        Dim curNum As Integer = 0

        For i As Integer = 0 To phrase.Length - 1
            If curNum <> numRem Then
                encoded = encoded & Asc(phrase(i))
                encLength = encLength & Asc(phrase(i)).ToString.Length
            Else
                encoded = encoded & RandomNumber(10, 0) & Asc(phrase(i))
                encLength = encLength & Asc(phrase(i)).ToString.Length
                curNum = 0
            End If

            curNum = curNum + 1 ' Increasing current number (for rem func)
        Next i

        Return encoded & "|" & encLength
End Function

I know it's REALLY basic, and I'm sure it's just a stupid mistake. But I'm a bit tired to be honest.. Having a hard time the last couple of days, so ^^

Thx to anyone trying to help me
 
How would you describe the encoding algorithm in words? What does it do?
 
I've already fixed it .. =]

By adding "i = i - 1" before the "Next i".
Next i added +1 to i, which was 1 too much (instead of 3 numbers, it added 4)

What it does?

You shouldn't really call it an encoding function .. It's just a VERY simple way to hide some basic information...

It just converts every letter to it's Asc() value. Then outputs the complete string, together with a string " | " & encLength in which each value represents the ASC length of one letter.

For example

323639|222
^ This would mean that each letter has a value of 2.
> 32 36 39
32 is letter 1, 36 being letter 2, and 39 is the last letter.

( These aren't real letter values .. I just made them up to show an example. )


It also adds a random number in a specified place. For example if you put "3", it will add a useless number after every 3 letters
 
Back
Top