Sublime Forum

Encrypt Line / Selection (ROT 13)

#1

Hello,
Recent convert from TextMate and gotta say that I’m really liking ST2. One feature that I do miss on occasion is encrypting selected text. This comes in handy when displaying email addresses on the page in a way where the email address is obfuscated from spambots. Directly from Textmate is this command:

#!/usr/bin/env ruby

def e_js(str)
  str.gsub(/(?=\\"])/, '\\').gsub(/\n/, '\n').gsub(/@.\/]/) { |ch| sprintf('\\%03o', ch[0]) }
end

def rot_13(str)
  str.tr('A-Za-z', 'N-ZA-Mn-za-m')
end

print %{<script type="text/javascript">document.write(
"#{e_js(rot_13(STDIN.read))}".replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);}));
</script>}

I also found this on Github, although it looks a bit different:
https://github.com/textmate/html.tmbundle/blob/master/Commands/Encrypt%20Line%20:%20Selection%20(ROT%2013).tmCommand

Can this be somehow implemented into ST2??

Thanks!

0 Likes

#2

You can make a quick plugin for this.

Here is the api reference sublimetext.com/docs/2/api_reference.html

Not sure how well this works but it’s the first thing that popped up in Google:
stackoverflow.com/questions/3269 … 3-function

0 Likes

#3

This used to be built in to Sublime 1 - or maybe it was just an example plugin in the docs

In any case, rot13 encoding is built into Sublime.

>>> 'rot13'.encode('rot13') 'ebg13'

sublimetext.com/docs/plugin-examples

0 Likes