AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Simple ROT13/ROT47 text convertor

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
CarlosTheTackle



Joined: 19 Oct 2004
Posts: 102

PostPosted: Mon May 02, 2005 12:45 pm    Post subject: Simple ROT13/ROT47 text convertor Reply with quote

Here is a simple ROT13 and ROT47 text convertor.

Note:
-The default Edit box content is your text clipboard, so you can call the script from a hotkey and whatever you've just copied will be right there ready for conversion.
-An ini file is created after the first run to save your default settings.
-The actual conversions are written as function calls, so you can easily pinch them for another script if you need.

Enjoy.


C
Code:
#NoTrayIcon
OnExit, SaveSettings
StringCaseSense, On
AutoTrim, Off

IniRead, ROT, ROT13-47.ini, Settings, ROT, 13
IniRead, AutoClip, ROT13-47.ini, Settings, AutoClip, 1
IniRead, OnTop, ROT13-47.ini, Settings, AlwaysOnTop, 1

Gui, Add, Text,, Enter text to convert.
Gui, Add, Edit, r10 w300 vText_orig, %clipboard%
Gui, Add, Button, w50 Default, &Convert
Gui, Add, Button, w50 x+200 Quit, Quit
If ROT=13
  {
  Gui, Add, Radio, xm vROT_type checked, ROT-13
  Gui, Add, Radio,, ROT-47
  }
else
  {
  Gui, Add, Radio, xm vROT_type, ROT-13
  Gui, Add, Radio, checked, ROT-47
  }
If AutoClip=1
  Gui, Add, Checkbox, vAutoClip checked, Auto-copy result to clipboard?
else
  Gui, Add, Checkbox, vAutoClip, Auto-copy result to clipboard?
If OnTop=1
  {
  Gui, Add, Checkbox, vOnTop gOnTop checked, Always On Top?
  Gui, +ALWAYSONTOP
  }
else
  Gui, Add, Checkbox, vOnTop gOnTop, Always On Top?
Gui, Add, Text,vProcessing w200,
Gui, Show
WinSetTitle,,Enter text to convert , ROT-13/ROT-47 Conversion Tool
return

ButtonConvert:
GuiControl,,Processing, Converting... please wait.
GuiControl, Disable, Button1
Gui, Submit, NoHide
If ROT_type=1
  {
  New_text:= ROT13(Text_orig)
  GuiControl,, Text_orig, %New_text%
  If AutoClip=1
    clipboard = %New_text%
  }
If ROT_type=2
  {
  New_text:= ROT47(Text_orig)
  GuiControl,, Text_orig, %New_text%
  If AutoClip=1
    clipboard = %New_text%
  }
GuiControl,,Processing,
GuiControl, Enable, Button1
return

ButtonQuit:
ExitApp

GuiClose:
ExitApp

SaveSettings:
Gui, Submit
If ROT_type=1
  IniWrite, 13, ROT13-47.ini, Settings, ROT
else
  IniWrite, 47, ROT13-47.ini, Settings, ROT
If AutoClip=1
  IniWrite, 1, ROT13-47.ini, Settings, AutoClip
else
  IniWrite, 0, ROT13-47.ini, Settings, AutoClip
If OnTop=1
  IniWrite, 1, ROT13-47.ini, Settings, AlwaysOnTop
else
  IniWrite, 0, ROT13-47.ini, Settings, AlwaysOnTop
ExitApp 
 
 
OnTop:
Winset, AlwaysOnTop, toggle
return


ROT13(Text_orig)
{
  StringCaseSense, On
  AutoTrim, Off
  StringLen, length, Text_orig
  source=abcdefghijklmnopqrstuvwxyz
  sourcecaps=ABCDEFGHIJKLMNOPQRSTUVWXYZ
  StringSplit, source, source
  StringSplit, sourcecaps, sourcecaps
  StringSplit, Text_orig, Text_orig

  Loop, %length% 
  {
  char_pos=%A_INDEX%
  Loop, 26
    {
    comp_char:=source%A_INDEX%
    If Text_orig%char_pos% = %comp_char%
      {
      replace_no := A_Index+13
        If replace_no > 26
          replace_no -=26
        Text_orig%char_pos% := source%replace_no%
      break
      }
    comp_char:=sourcecaps%A_INDEX%
    If Text_orig%char_pos% = %comp_char%
      {
      replace_no := A_Index+13
      If replace_no > 26
        replace_no -=26
      Text_orig%char_pos% := sourcecaps%replace_no%
      break
      }
    }
  }
 
  ;recombine string
  Text_new=
  Loop, %length%
  {
  new_char:=Text_orig%A_INDEX%
  Text_new=%Text_New%%new_char%
  }
  return Text_new
}

ROT47(Text_orig)
{
  StringCaseSense, On
  AutoTrim, Off
  StringLen, length, Text_orig
  source=!"#$`%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_``abcdefghijklmnopqrstuvwxyz{|}~
  StringSplit, source, source
  StringSplit, Text_orig, Text_orig
 
  Loop, %length%  ;process submitted string
  {
  char_pos=%A_INDEX%
  Loop, 94
    {
    comp_char:=source%A_INDEX%
    If Text_orig%char_pos% = %comp_char%
      {
      replace_no := A_Index+47
      If replace_no > 94
        replace_no -=94
      Text_orig%char_pos% := source%replace_no%
      break
      }
     }
  }
 
  ;recombine string
  Text_new=
  Loop, %length%
  {
  new_char:=Text_orig%A_INDEX%
  Text_new=%Text_New%%new_char%
  }
  return Text_new
}
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group