Created
March 28, 2017 10:15
-
-
Save boxabirds/556d83c1e79b4302fe860c37ccda8bc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub ROT13UX() | |
' Obscure material on screen temporarily. | |
' Problem: how do I share screens and avoid accidental sharing of content? | |
Selection.text = ROT13(Selection.text) | |
End Sub | |
' Formatting preserved (yay) | |
Function ROT13(ByRef text As String) | |
Const kLowerCaseStart = 97 | |
Const kAlphabetRange = 26 | |
Const kUpperCaseStart = 65 | |
Const kRotRange = kAlphabetRange / 2 | |
Dim baseOffset As Long | |
Dim result As String | |
'' we have a nonzero length selection | |
If Len(text) > 0 Then | |
For i = 1 To Len(text) | |
baseOffset = 0 | |
c = Mid(text, i, 1) | |
cc = Asc(c) | |
' Determine if we found a rot13-capable char | |
If cc >= kLowerCaseStart And cc < (kLowerCaseStart + kAlphabetRange) Then | |
baseOffset = kLowerCaseStart | |
ElseIf cc >= kUpperCaseStart And cc < (kUpperCaseStart + kAlphabetRange) Then | |
baseOffset = kUpperCaseStart | |
End If | |
' do a ROT13 if we found a char that can be rotated | |
If baseOffset > 0 Then | |
theRot13Code = (((cc - baseOffset) + kRotRange) Mod kAlphabetRange) + baseOffset | |
theRot13Char = Chr(theRot13Code) | |
result = result + theRot13Char | |
Else | |
result = result + c | |
End If | |
Next | |
End If | |
ROT13 = result | |
End Function | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment