Results 1 to 5 of 5

Thread: encoder decoder

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    youngstown, oh
    Posts
    11
    what i am trying to do is take the first letter and take the ascii value for it and add one to it then put it back into the string and do the same for the rest of the characters and also beable to reverse is to get it back to normal

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Encoding:
    Code:
    Function EnCode(Data As String) As String
        Dim oneByte As String ' a swap variable
        Dim Output As String  ' the output
    
        For i = 1 To Len(Data) 'loop trough all the bytes
            oneByte = Right(Left(Data, i), 1) 'get a byte
            oneByte = Chr((Int(Asc(oneByte)) + 1)) 'encode the byte
            Output = Output & oneByte 'add it to the output
        Next
        
        EnCode = Output 'return the encoded data
    End Function
    Decoding:
    Code:
    Function DeCode(Data As String) As String
        Dim oneByte As String ' a swap variable
        Dim Output As String  ' the output
    
        For i = 1 To Len(Data) 'loop trough all the bytes
            oneByte = Right(Left(Data, i), 1) 'get a byte
            oneByte = Chr((Int(Asc(oneByte)) - 1)) 'decode the byte
            Output = Output & oneByte 'add it to the output
        Next
        
        DeCode = Output 'return the encoded data
    End Function
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  3. #3
    Addicted Member Shrog's Avatar
    Join Date
    Aug 1999
    Location
    Darkest Africa
    Posts
    186

    Mid

    Very interesting way that you use Left and Right to simulate the Mid function.

    You can also put it all in one function by calling it with a parameter of 1 or -1 to encode or decode respectively.

    Code:
    Enum eEncodeMode
      eEncode = 1
      eDecode = -1
    End Enum
    
    Function EncodeDecode(Data As String, vMode as eEncodeMode) As String
        Dim oneByte As String ' a swap variable
        Dim Output As String  ' the output
    
        For i = 1 To Len(Data) 'loop trough all the bytes
            oneByte = Mid(Data, i, 1) 'get a byte
            oneByte = Chr(Asc(oneByte) + vMode)) 'encode the byte
            Output = Output & oneByte 'add it to the output
        Next
        
        EncodeDecode = Output 'return the encoded data
    End Function
    
    strEncoded = EncodeDecode(MyString, eEncode)
    strDecoded = EncodeDecode(strEncoded, eDecode)
    Hope this helps.
    Shrog

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    youngstown, oh
    Posts
    11
    Thanks all. all i needed to do is have it so the average joe could not edit lock info in a text save file (ex: the STATS on a character) with out have knowldge of programing

    thanks for your help

  5. #5
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Raptor31, this function will make it harder to read. It encrypts and decrypts.
    Code:
    Function Crypt(Data As String) As String
        Dim oneByte As String ' a swap variable
        Dim Output As String  ' the output
    
        For i = 1 To Len(Data) 'loop trough all the bytes
            oneByte = Right(Left(Data, i), 1) ' get a byte
            oneByte = Chr((Int(Asc(oneByte)) Xor 152)) ' encrypt the byte
            Output = Output & oneByte ' add it to the output
        Next
        
        Crypt = Output ' return the encrypted or decrypted data
    End Function
    Sorry for using Right and Left to simulate Mid.
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

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