EmEditor (text editor) Forum Index
   Macro Samples
     Macro: ROT13 - simple letter substitution caesar cipher
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
Stefan
Posted on: 7/21/2012 7:25 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 265
Macro: ROT13 - simple letter substitution caesar cipher
The other day i wanted to know what is written in the registry under 'UserAssist'.
I know i can decrypt them by using an additional entry 'NoEncrypt'
but it was not my pc and i just wanted to know something quickly.

So i remembered i did this coding already twice in other languages and now i wanted to see
if i am skilled enough to do this in JavaScript again... and it worked.

Examples:
FROM:
{0139Q44R-6NSR-49S2-8690-3QNSPNR6SSO8}\Zvpebfbsg Bssvpr\Zvpebfbsg Rkpry 2010.yax=""
TO:
{0139D44E-6AFE-49F2-8690-3DAFCAE6FFB8}\Microsoft Office\Microsoft Excel 2010.lnk=""

FROM:
clipboardData.setData( sDataFormat, sData, iPos );
EmEditor ROT13 macro
TO:
pyvcobneqQngn.frgQngn( fQngnSbezng, fQngn, vCbf );
RzRqvgbe EBG13 znpeb


ROT13 is an very simple letter substitution cipher know too as caesar cipher.
http://en.wikipedia.org/wiki/ROT13

Here is my code:


// INPUT =================================
//Sel = clipboardData.getData("Text"); 
Sel = document.selection.Text;
if(Sel.length == 0)  quit();
//Sel = Sel.replace(/(^\s*)|(\s*$)/g, ""); //LTrim/RTrim
//if(Sel.length > 20000) Sel = Sel.substr(0, 20000); //not to many please ;-)
out ="";

// CODE =================================
for(Pos=0,strLen=Sel.length;Pos<strLen;Pos++){
	nASC = Sel.charCodeAt(Pos);

	if(nASC > 64 && nASC < 91){
		nASC = nASC +13;
		if(nASC > 90){nASC -= 26;}
		out += String.fromCharCode(nASC);
	}else if(nASC > 96 && nASC < 123){
		nASC = nASC +13;
		if(nASC > 122){nASC -= 26;}
		out += String.fromCharCode(nASC);
	}else{ 
		out += Sel.charAt(Pos);
	}

}
// OUTPUT =================================
// //Out to an dialog:
// if(Sel.length > 1000) Sel = Sel.substr(0, 1000); //shorten for the dialog box
// if(out.length > 1000) out = out.substr(0, 1000); //   remove for to insert into an document
// alert(Sel + '\n\n' + Sel.length + ' signs ROT13 =>\n\n' + out);

// //Replace clipboard with processed text: 
// clipboardData.setData("Text", out);

//Replace selected text with processed text:
document.selection.Text = out;


(why are this code blocks always that small in this forum? Or is this an firefox issue?)
Threaded | Newest First Previous Topic | Next Topic | Top


Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文