title: How to store function with variable in a batch Script?
body: <p>I have a Batch Script where I am trying to encode a string. I have successfully encoded the string with the help of <a href="https://stackoverflow.com/questions/25582295/xor-a-string-in-a-bat-file/25583032">Xor a string in a bat file</a></p>
  
  <p>But now I want to store the value %show% !val! in a variable so that it can be used any where in the script. Below is my code. Any suggestion would be greatly appreciated.</p>
  
  <pre><code>    @echo off
  setlocal enableDelayedExpansion
  call :init
  
  :: Curly braces are used to denote text that should be encrypted.
  :: Encryption can span multiple lines
  :: {
  :::password
  :: }
  
  :: Here I use a FOR loop to show all encrypted lines within this script
  :: that begin with :::
  
  for /f "delims=: tokens=*" %%A in ('findstr /b ":::" "%~f0"') do (
  
      set val=%%A
      set pwd = %show% !val!
  
      )
  echo %pwd%
  
  exit /b
  
  
  :show  Str
  ::{
  ::  Nccyvrf gur fvzcyr "ebgngr nycunorg 13 cynprf" pvcure gb fgevat Fge
  ::  naq jevgrf gur erfhyg gb fgqbhg. Pbafrphgvir dhbgrf ("") ner pbairegrq
  ::  vagb n fvatyr dhbgr (").
  ::}
    setlocal disableDelayedExpansion
    set "str=%~1"
    setlocal enableDelayedExpansion
    set "str=!str:""="!^"
    if defined {boshfpngrq} (
      set "len=0"
      set "str2=.!str!"
      for /L %%A in (12,-1,0) do (
        set /a "len|=1&lt;&lt;%%A"
        for %%B in (!len!) do if "!str2:~%%B,1!"=="" set /a "len&amp;=~1&lt;&lt;%%A"
      )
      set /a len-=1
      set rtn=
      for /l %%n in (0,1,!len!) do (
        set "c=!str:~%%n,1!"
        if defined {hccre}!c! for /f %%c in ("!c!") do (
          if "!{hccre}:%%c=%%c!" equ "!{hccre}!" (
            set "c=!{hccre}%%c!"
          ) else (
            set "c=!{ybjre}%%c!"
          )
        )
        set "rtn=!rtn!!c!"
      )
    ) else set "rtn=!str!"
    echo(!rtn!
  exit /b 0
  
  
  :init
    set "}="
    set "{="}
    set "{hccre}=ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    set "{ybjre}=abcdefghijklmnopqrstuvwxyz"
    for /l %%A in (0 1 25) do (
      set /a "B=(%%A+13)%%26"
      for /f %%B in ("!B!") do (
        set "{hccre}!{hccre}:~%%A,1!=!{hccre}:~%%B,1!"
        set "{ybjre}!{ybjre}:~%%A,1!=!{ybjre}:~%%B,1!"
      )
    )
    set "{boshfpngrq}="
    set "{boshfpngvbaGrfg}={N}"
    if "!{boshfpngvbaGrfg}:A=!" equ "!{boshfpngvbaGrfg}!" set {boshfpngrq}=1
    set "show=call :show"
  exit /b
  </code></pre>