Page 1 of 1

ROT13 Support?

Posted: Mon Apr 09, 2001 8:18 pm
by Roy Beatty
Greetings,

Does anyone have a macro or whatever to do a ROT13 transformation on selected text?

ROT13 is a simple excryption cypher implemented via the following Perl *translate* command:<br>
<t>tr {a-zA-z}{n-za-mN-ZA-M}<br>
which replaces the letters in the first term with the letters in the second term. TextPad's Replace dialog to does the equivalent of a Perl substitution operator<br>
<t>s {a-zA-z}{n-za-mN-ZA-M}<br>

[To TextPad development: This is yet another request that could have been obviated by exposing the objects within TextPad for manipulation with Perl (or whatever) as described above. If this is ever implemented, there will be an explosion of user-base synergy equal in impact to those jillions of syntax files and cliplibs available for download. Like the perennial "edittable macros" request, this one is basically a plea from hundreds of paying customers begging Helios to let them do product development for them for free. It would be nice if we could at least be told whether requests like these have been slated for a specific future version number or not -- even if we are not told what that future version number is.]

Meanwhile, I'd appreciate any help insights into implementing ROT13 in TextPad in its current form.

Thanks,

Roy Beatty

Re: ROT13 Support?

Posted: Tue Apr 10, 2001 9:55 am
by Thomas Schremser
Hi Roy!

As a quick and dirty hack I've written a small C-program which will do a rot13 with the text in the clipboard. You can use it with the $Clip to get the text into the command result window.

Here's the source:

#include <stdio.h>
#include <string.h>
#include <windows.h>

int main(int argc, char **argv)
{
char *RotTxt, *Tmp ;
char *ClpTxt ;
HANDLE hClpMem ;

if (!IsClipboardFormatAvailable(CF_TEXT))
return 1 ;

OpenClipboard(NULL) ;
hClpMem = GetClipboardData(CF_TEXT) ;
ClpTxt = GlobalLock(hClpMem) ;
RotTxt = (char *) malloc(GlobalSize(hClpMem)) ;
Tmp = RotTxt ;

// Transforming the text and removing 0x0D to avoid doubling of
// newlines in TextPads command result window
do
{
if ((*ClpTxt >= 'a' && *ClpTxt <= 'm') ||
(*ClpTxt >= 'A' && *ClpTxt <= 'M'))
*Tmp++ = *ClpTxt + 13 ;
else if ((*ClpTxt >= 'n' && *ClpTxt <= 'z') ||
(*ClpTxt >= 'N' && *ClpTxt <= 'Z'))
*Tmp++ = *ClpTxt - 13 ;
else if (*ClpTxt == 0x0D)
; // Skip the 0x0D character
else
*Tmp++ = *ClpTxt ; // No conversion
}
while (*++ClpTxt) ;

GlobalUnlock(hClpMem) ;
CloseClipboard() ;

// Convert output to OEM character set if desired
if (argc == 2)
if (argv[1][0] == '-' || argv[1][0] == '/')
if (argv[1][1] == 'o' || argv[1][1] == 'O')
CharToOem(RotTxt, RotTxt) ;

printf("%s\n", RotTxt) ;
free(RotTxt) ;
return 0 ;
}

If you don't have a compiler to compile it, just send me a message and I'll mail the exe file to you.

HTH
Greetings from Austria
Thomas