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
Printable View
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
Encoding:
Decoding: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
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
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.
Hope this helps.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)
Shrog
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
Raptor31, this function will make it harder to read. It encrypts and decrypts.
Sorry for using Right and Left to simulate Mid.:rolleyes: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