|
-
Nov 29th, 2000, 06:05 PM
#1
Thread Starter
New Member
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
-
Dec 1st, 2000, 02:30 PM
#2
Fanatic Member
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
-
Dec 1st, 2000, 06:29 PM
#3
Addicted Member
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
-
Dec 2nd, 2000, 02:26 AM
#4
Thread Starter
New Member
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
-
Dec 2nd, 2000, 03:07 AM
#5
Fanatic Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|