Last active
June 3, 2018 02:07
-
-
Save QuadStorm/05a8478b7e150434789890ded530d9ed to your computer and use it in GitHub Desktop.
Shift characters in a string like rot-13
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
// made on 12/24/2017 | |
// rotNString 'string', shift # (postive or negative work), %m for whether to allow nonletters to pass through | |
function shiftCharS(%c, %offset, %mode) | |
{ | |
%letters = "abcdefghijklmnopqrstuvwxyz"; | |
if (%offset !$= (%offset | 0)) // first %offse | |
return "offset isn't a number"; | |
if (strLen(%c) != 1) | |
return "one character only"; | |
if (%c $= (%c | 0)) | |
switch(%mode) | |
{ | |
case (0): | |
return "letters only - no numbers"; | |
case (1): | |
return %c; | |
} | |
if (strPos(%letters, %c) == -1 && strPos(strUpr(%letters), %c) == -1) // not 0 | |
switch(%mode) | |
{ | |
case (0): | |
return "no symbols"; | |
case (1): | |
return %c; | |
} | |
if (strCmp(%c, strUpr(%c))) | |
return getSubStr(%letters, ((strPos(%letters, %c) + %offset) % 26), 1); | |
else | |
return getSubStr(strUpr(%letters), ((strPos(strUpr(%letters), %c) + %offset) % 26), 1); | |
} | |
function rotNString(%string, %n, %m) | |
{ | |
if (%string $= "") | |
{ | |
error("No blank strings."); | |
return; | |
} | |
for (%i = 0; %i < %strLen = strLen(%string); %i++) | |
{ | |
%rotNString = %rotNString @ shiftCharS(getSubStr(%string, %i, 1), %n, %m); // %m was 1 | |
} | |
return %rotNString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment