Ok I don't know what you guys have done exactly, I'm not going to read it all, but this is my solution. This will be my first encryptor, I wrote this based on a concatenator I wrote yesterday for extracting in order, all numbers within a string (with some other features but it's irrelevant).
If this is just for file path strings, you will have no problems. Otherwise,
Caveats (these are typical to DOS):1. In a variable, ! needs to be escaped ^!, % needs to be escaped %%.-If you enter a variable with /p, or text file with for etc, they will be escaped automatically of course.
2. " will cause a failure if they happen to expose a special character to the interpreter, outside of a string context.-In this case, special characters are escaped as follows: ^^^^ , ^^^! , ^^^& , %%
-Always fails: < > | (redirection characters)
Notes:-This could easily be turned into a function/subroutine but I was lazy, it's just in-order as it is.
-I was also lazy and predominantly used ! instead of % for variable expansion.
Code: Select all
@echo off&setlocal enabledelayedexpansion
set "input=UEME_RUNPATH:C:\Program Files\myProggy\"
:: Set character conversion maps.
set "upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set "upmap=NOPQRSTUVWXYZABCDEFGHIJKLM"
set "lomap=nopqrstuvwxyzabcdefghijklm"
:: Sets temp string that is nibbled at. Prepares exclamation marks.
set "step=%input:!=^!%"
:: Checks character by character. First checks if letter, then checks case.
:: If not a letter, appends current character.
:rotloop
if defined step (
set "isletter=false"
for /l %%x in (0,1,25) do (
if /i "!step:~0,1!"=="!upper:~%%x,1!" (
if "!step:~0,1!"=="!upper:~%%x,1!" (
set "out=!out!!upmap:~%%x,1!"
) else (
set "out=!out!!lomap:~%%x,1!"
)
set "isletter=true"
)
)
if "!isletter!"=="false" (
set "out=!out!!step:~0,1!"
)
set "step=!step:~1!"
goto rotloop
)
echo:
echo: Your input string: "!input!"
echo:
echo: Your output string: "!out!"
echo:
echo: Match test string: "HRZR_EHACNGU:P:\Cebtenz Svyrf\zlCebttl\"
echo:
pause
Is this what you guys were working towards? Please let me know.
I'm starting to think using ! instead of % predominantly is far more advantageous though situational.
FYI: This could also be modified to be a more formidable encryptor by using one set of compare maps, including spaces and punctuation, then randomizing all the characters on the conversion side.