Snippet Library

Browse | Submit A New Snippet | Create A Package

rot13 (freeware)

HTML Manipulation

Freeware implementation of rot13 in JavaScript.
Example see

Versions Of This Snippet:

Snippet ID Download Version Date Posted Author Delete
812005-01-11 12:08Valentin Hilbig

Download a raw-text version of this code by clicking on "Download Version"


Latest Snippet Version: 1

// This script hereby is dedicated in the Public Domain // as long as nobody else claims the copyright for it. // origin: 2000-01-08 // Use at own risk. var last=""; var rot13map; // The problem is that JavaScript 1.0 // does not provide a Char to Numeric value conversion // Thus we define a map. // Because there are 64K UniCode characters, this map does not cover all characters. function rot13init() { var map = new Array(); var s = "abcdefghijklmnopqrstuvwxyz"; for (i=0; i<s.length; i++) map[s.charAt(i)] = s.charAt((i+13)%26); for (i=0; i<s.length; i++) map[s.charAt(i).toUpperCase()] = s.charAt((i+13)%26).toUpperCase(); return map; } // Usage: rot13("text") gives rotated output. // Note: rot13(rot13(a))==a function rot13(a) { if (!rot13map) rot13map=rot13init(); s = ""; for (i=0; i<a.length; i++) { var b = a.charAt(i); s += (b>='A' && b<='Z' || b>='a' && b<='z' ? rot13map[b] : b); } return s; }

Submit a new version

You can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..

Powered By FusionForge