CFLib.org – Common Function Library Project

Rot13(string)

Last updated August 23, 2001

Version: 1 | Requires: ColdFusion 5 | Library: SecurityLib

 
Rated 1 time(s). Average Rating: 5.0

Description:
Stands for "rotate alphabet 13 places". Caesar-cypher encryption that replaces each English letter with the one 13 places forward or back along the alphabet. The same function is used to both encrypt and decrypt a string.

Return Values:
Returns a string.

Example:

view plain print about
<CFSET String="Welcome to the Common Function Library Project.">
<CFSET Encrypted = Rot13(String)>
<CFSET Decrypted = Rot13(Encrypted)>

<CFOUTPUT>
<B>Original:</B><BR>
#String#
<P>
<B>Encrypted:</B><BR>
#Encrypted#
<P>
<B>Dencrypted:</B><BR>
#Decrypted#
</CFOUTPUT>

Parameters:

Name Description Required
string String you wish to rot13 encrypt. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Caesar-cypher encryption that replaces each English letter with the one 13 places forward or back along the alphabet.
 * 
 * @param string      String you wish to rot13 encrypt. 
 * @return Returns a string. 
 * @author Rob Brooks-Bilson (rbils@amkor.com) 
 * @version 1.0, August 23, 2001 
 */

function rot13(string)
{
  var i=0;
  var j=0;
  var k=0;
  var out="";
  for (i=1; i LTE Len(String); i=i+1){
    j=Asc(Mid(string, i, 1));
    if(j GTE 65 AND j LTE 90){
      j=((J-52) MOD 26)+65;
    }
    else if(j GTE 97 AND j LTE 122){
      j=((j-84) MOD 26)+97;
    }
    out=out&Chr(j);
  }
  return out;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
4 day(s) ago

Will Belden Will Belden added
longTime
9 day(s) ago

James Sleeman James Sleeman added
quickSort
19 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
22 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson