Visual Basic Programming Code Examples
Visual Basic > Applications VBA Code Examples
(De)Coding Ascii
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(De)Coding Ascii
BTW, here's a little doo-dad that I threw together that moves the ascii value of each
character up (encode) or down (decode), with a default change of 40.
So, for example, chr(233) might become chr(21), or chr(74) might become chr(114).
Anyone who knows what they're doing could easily decode it, but at least it's not legible
if you open the file in Notepad, etc. Try it!
Syntax is: encode(mytext, [range]) and decode(mytext, [range]).
Public Function Encode(Data as String, Optional Depth as Integer) as String
Dim TempChar as String
Dim TempAsc as Integer
Dim NewData as String
Dim vChar as Integer
For vChar = 1 To Len(Data)
TempChar = Mid$(Data, vChar, 1)
TempAsc = Asc(TempChar)
If Depth = 0 Then Depth = 40 'DEFAULT DEPTH
If Depth > 254 Then Depth = 254
TempAsc = TempAsc + Depth
If TempAsc > 255 Then TempAsc = TempAsc - 255
TempChar = Chr(TempAsc)
NewData = NewData & TempChar
Next vChar
Encode = NewData
End Function
Public Function Decode(Data as String, Optional Depth as Integer) as String
Dim TempChar as String
Dim TempAsc as Integer
Dim NewData as String
Dim vChar as Integer
For vChar = 1 To Len(Data)
TempChar = Mid$(Data, vChar, 1)
TempAsc = Asc(TempChar)
If Depth = 0 Then Depth = 40 'DEFAULT DEPTH
If Depth > 254 Then Depth = 254
TempAsc = TempAsc - Depth
If TempAsc < 0 Then TempAsc = TempAsc + 255
TempChar = Chr(TempAsc)
NewData = NewData & TempChar
Next vChar
Decode = NewData
End Function
Return