Batch file to allow encrypt and decrypt capital letters for this code

1.2k views Asked by At

i want this code to be able to encrypt the capital letters because when i add capital letters it will be encrypted like the small letters

this is the code

encryption code

http://pastebin.com/Xy2gCmtQ

decryption code

http://pastebin.com/rZtrwaJD

2

There are 2 answers

0
SachaDee On BEST ANSWER

You have to make a loop with an IF test to check if the char is lower or upper case :

Example :

@echo off

::The string to Encrypt

set "$string=aBA baB"

setlocal enabledelayedexpansion

for /l %%i in (0,1,9000) do (
   set char=!$string:~%%i,1!
      if "!char!"==" " set char=#
      if defined char (

REM here the tests and substitutions
         if !char!==a set "char=!char:a=[aSmall]!"
         if !char!==A set "char=!char:A=[ACapital]!"
         if !char!==b set "char=!char:b=[bSmall]!"
         if !char!==B set "char=!char:B=[BCapital]!"

         set "$final=!$final!!char!"
        )
)
echo %$String% --^> !$final:#= !
2
Aacini On

Well, if the code is too long, you should also requested to shrink it! :-) This is the solution for encrypt part:

@echo off
setlocal  EnableDelayedExpansion

rem Create the encryption array
for %%a in ("UA=45UDFM" "UB=GFH21D" "UC=6DFDH5" "UD=46FGS5" "UE=JHJUK4" "UF=4SERG5" 
            "UG=FDT5H4" "UH=1GRG64" "UI=4DRG4F" "UJ=F6RT56" "UK=3BVCBC" "UL=GFF8G9"
            "UM=JSFD4C" "UN=FGG423" "UO=C2F45G" "UP=F5TH5D" "UQ=6RCV4F" "UR=TSXF64"
            "US=GTX78D" "UT=SJTH74" "UU=DFBCX6" "UV=SDFG65" "UW=5D4KL4" "UX=F2GFH3"
            "UY=GFGH56" "UZ=FG45T1"
            "a=UDFM45" "b=H21DGF" "c=FDH56D" "d=FGS546" "e=JUK4JH" "f=ERG54S" "g=T5H4FD" 
            "h=RG641G" "i=RG4F4D" "j=RT56F6" "k=VCBC3B" "l=F8G9GF" "m=FD4CJS" "n=G423FG"
            "o=F45GC2" "p=TH5DF5" "q=CV4F6R" "r=XF64TS" "s=X78DGT" "t=TH74SJ" "u=BCX6DF"
            "v=FG65SD" "w=4KL45D" "x=GFH3F2" "y=GH56GF" "z=45T1FG" "1=D4G23D" "2=GB56FG"
            "3=SF45GF" "4=P4FF12" "5=F6DFG1" "6=56FG4G" "7=USGFDG" "8=FKHFDG" "9=IFGJH6"
            "0=87H8G7" "@=G25GHF" "#=45FGFH" "$=75FG45" "*=54GDH5" "(=45F465" ".=HG56FG"
            ",=DF56H4" "-=F5JHFH" " =SGF4HF" "\=45GH45" "/=56H45G") do (
   for /F "tokens=1,2 delims==" %%b in (%%a) do set "CHAR[%%b]=%%c"
)

set lowCase=abcdefghijklmnopqrstuvwxyz

set /p "Encrypt=Enter a string to encrypt: "
set "Encrypt2=%Encrypt%"
set "EncryptOut="
:encrypt2
   set char=%Encrypt2:~0,1%
   if "!lowCase:%char%=%char%!" neq "%lowCase%" set char=U%char%
   set "EncryptOut=%EncryptOut%!CHAR[%char%]!"
   set "Encrypt2=%Encrypt2:~1%"
if defined Encrypt2 goto encrypt2

echo Encrypted: %EncryptOut%

The decrypt part is exactly as the original, just add the set of capital letters...