Search: Go
 Transact SQL
 Other Articles
 Software Reviews

 Canon EOS 300D Samples
 Akihabara Maids!
 More Galleries...

 Overseas Teaching Blog
 2009: China
 2008: Tokyo
 2007: Tokyo
 2006: Hong Kong
 2005: New York City

 Search Engine Optimisation
 Build an ASP Search Engine
 My Tropical Fishtank
 SQL Month Name
 SQL Get Date Today
 SQL Year Month
 Other New Stuff...

 Regular Expressions
 Index Server & ASP
 JavaScript Ad Rotator

Home > Articles

ROT13 Encoding with ASP

ROT13 is a commonly used method for encoding a text string so that it cannot be easily read. This encoding process DOES NOT encrypt the text (so don't even consider using it to encode passwords or other sensitive information). Nonetheless, it is a useful method to use in certain situations.  If you want to use sophisticated encryption within ASP, then take a look at this article.

ROT13 uses a simple encoding process; the alphabet is rotated 13 characters, so that "a" becomes "n", "z" becomes "m", "N" becomes "Y" and so on... ROT13 originated on USENET, so if you have added USENET support to your ASP powered website then it is a particularly useful feature to build into the site.

Another possible use would be to encode Query Strings or non-sensitive cookie data. Although it must be stressed that ROT13 does not encrypt text, it can be effective in keeping the average user from figuring out how your site works. So if you used ROT13 in your site, instead of something like...

the Query String would become:

If you want to test ROT13 encoding, then enter some text into the box below:

Encoding and decoding of ROT13 can be easily carried out by an ASP script or a JavaScript. The script (written in VBScript, PHP, JScript and client side JavaScript) is shown below.

The VBScript function for encoding and decoding text using ROT13 is shown below:

' rot13 function - a function to encode and decode text strings using the popular ROT13 method
' note that ROT13 does not encrypt strings, so do not use it if security is an issue!

Function rot13(rot13text)
   rot13text_rotated = "" ' the function will return this string
   For i = 1 to Len(rot13text)
      j = Mid(rot13text, i, 1) ' take the next character in the string
      k = Asc(j) ' find out the character code
      if k >= 97 and k =< 109 then
         k = k + 13 ' a ... m inclusive become n ... z
      elseif k >= 110 and k =< 122 then
         k = k - 13 ' n ... z inclusive become a ... m
      elseif k >= 65 and k =< 77 then
         k = k + 13 ' A ... m inclusive become n ... z
      elseif k >= 78 and k =< 90 then
         k = k - 13 ' N ... Z inclusive become A ... M
      end if

'add the current character to the string returned by the function
   rot13text_rotated = rot13text_rotated & Chr(k)


rot13 = rot13text_rotated

End Function

The function can then be called from an ASP page by using something like:

Response.Write rot13("Hello World")



Don't forget that the same function is used to both encode and decode ROT13.

It is also possible to use ROT13 encoding with JavaScript. The function below uses JavaScript to convert strings using the ROT13 method. It has been tested and found to work in Internet Explorer 5 and Netscape 4.5.

<script LANGUAGE="JavaScript">
function JSrot13(text) {
var rot13text_rotated = "";
/* the function will return this string */;

for (i = 1 ; i < (text.length + 1); i++) {

k = text.charCodeAt(i-1);

if (k >= 97 && k <= 109) {
k = k + 13;
} else

if (k >= 110 && k <= 122) {
k = k - 13;
} else

if (k >= 65 && k <= 77) {
k = k + 13;
} else

if (k >= 78 && k <= 90) {
k = k - 13;

rot13text_rotated = rot13text_rotated + String.fromCharCode(k);


return rot13text_rotated;

Once you have added the function to the page, it can be called using something like:

<script language="JavaScript">
document.write (JSrot13("
Visit for some great original ASP articles!"));

Further Reading

  Site Map | Privacy Policy

All content is 1995 - 2018