Advertisement
IcarusLives

ROT13 text cipher

Jun 5th, 2017
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.28 KB | None | 0 0
  1. @echo off & setlocal enableDelayedExpansion
  2.  
  3. set /p "text=Text:   "
  4. set /p "key=Shift:  "
  5. call :rot13 "text" key ciphered
  6.  
  7. echo Cipher: %ciphered%
  8.  
  9. pause & exit
  10.  
  11.  
  12. :rot13
  13.     setlocal
  14.         set "alphaNum="a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z" "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" " ""
  15.         set /a "num=%~2" 2>nul & if "!num!" equ "!%~2!" ( set /a "shiftAlphaNum=4 * num" ) else ( set /a "shiftAlphaNum=4 * 13")
  16.         set "str=X!%~1!" & set "backward=!alphaNum:~%shiftAlphaNum%! !alphaNum:~0,%shiftAlphaNum%!"
  17.  
  18.         for /L %%a in (8,-1,0) do (
  19.             set /a "length|=1<<%%a"
  20.             for %%b in (!length!) do if "!str:~%%b,1!" equ "" set /a "length&=~1<<%%a"
  21.         )
  22.         (for /l %%a in (0,1,%length%) do ( set "c="!%~1:~%%a,1!" " & set "spaced=!spaced!!c!" )) & set "spaced=!spaced:~0,-3!"
  23.         for %%a in (!spaced!) do (                                set /a "n=0", "m=0"
  24.             for %%b in (!alphaNum!) do (                          set /a "n+=1"
  25.                 if %%b equ %%a for %%c in (%backward%) do (       set /a "m+=1"
  26.                     if !n! equ !m! set "out=!out!%%~c"
  27.         )))
  28.        
  29.     (endlocal
  30.         if "%~3" neq "" ( set "%~3=%out%" ) else ( echo %out%)
  31.     )
  32. goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement