Sure, however before you get into the code please understand that this is *not* secure in any way. In fact, it is more like encoding than encrypting; it will protect the string from casual viewing, but will not be safe against anyone with a purpose (and 5 minutes to kill). If you need encryption, see the list below the code for several free and commercial offerings. If you are trying to protect passwords, credit card numbers and other information inside a database, see
Article #2536.
Basically, this code takes the ASCII value of each string, offsets it by a number you can control (don't go too high though; I'd stick in the range of -47 -> 133 to be safe, as CHR() will return errors if you reach > 255). This assumes, of course, that the original string contains ONLY alphanumeric characters. You will have to play with that range if you are using other characters, and you will also want to test this code if you are using a non-default character set.
<% str = "ZzAa019WHOLEbunch" offset = 8 for i = 1 to len(str) newStr = newStr & chr((asc(mid(str,i,1))+offset)) next response.write "New string is : " & newStr & "<p>" for i = 1 to len(newStr) oldStr = oldStr & chr((asc(mid(newStr,i,1))-offset)) next response.write "Old string was : " & oldStr & "<p>" %> |
Components Available
For MD5 encryption options, see
Article #2397.