Find ALL PERFORMANCE CHANGE FREEDOM TO VARIOUS letter

I am working on an encryption method that changes all letters to a string of numbers that follow an example:

set a=a set b=b set c=c set aa=543241254 set bb=785214185 set cc=842501445 

My problem: how can I scan a file entered by the user and change all letters to numbers. (The file with the modified text is similar to " hihowareyou " without spaces or capitals) I tried to find "a" in the specified file and replace it with numbers, but my section did not work.

 (for /f "delims=" %%i in ('findstr /n "^" "%textfile%"') do ( set "line=%%i" setlocal enabledelayedexpansion set "line=!line:%b%=%bb%!" echo(!line! endlocal ))>"%newfile%" type "%newfile%" >>%newfile% 

I'm not sure what to do to scan the letter in a text file and replace it with% a%,% b%,% c%, etc.

+1
file cmd encryption batch-file
Feb 25 '16 at 21:59
source share
1 answer

You must first understand that these commands:

 set a=a set b=b set c=c 

... are "by definition" useless (that is, without any further explanation), although it should be obvious that in this case the spelling of %a% will always be the same as spelling only a (the same will happen for the rest of the letters) .

If you want to change one letter to a string of numbers, then the correct path should be as follows:

 set a=543241254 set b=785214185 set c=842501445 

Then, to change the letter "a" to the contents of the variable, you can do something like this in your for command:

 set "line=!line:a=%a%!" 

Again: this will change the letter a to the contents of the variable a .




Now you should understand that you need to perform the previous replacement not by a single letter / variable a , but by a number of variables represented by each one letter. The standard way to handle a sequence of variables in the same way (which actually means “using the same code”) is the for command, which changes the index value in combination with array . For example, if we select the letter “name” for the name of the array and determine the required replacement values ​​in different elements of the array, we will do something like this:

 set letter[a]=543241254 set letter[b]=785214185 set letter[c]=842501445 

After that, we just need to know how to manipulate these variables / values. Full details on this are given in arrays, linked lists, and other data structures in the cmd.exe (batch) script , so I won’t repeat them here again. However, managing the array needed to solve this problem is simpler than the full explanation given in this link.

If you run this command: set letter , all variables starting with a letter will be displayed, including their values; eg:

 letter[a]=543241254 letter[b]=785214185 letter[c]=842501445 

If we use the for /F "tokens=2,3 delims=[]=" %%a in ('set letter') do ... command for /F "tokens=2,3 delims=[]=" %%a in ('set letter') do ... , then the replaceable parameter %%a will contain each of the array indices, that is, the letters a , b , c etc. and the %%b parameter will contain the corresponding numeric values.

Thus, to complete your program and replace all the specific letters, you just need to put your line set "line=!line:%b%=%bb%!" into the previous for command and correctly change the part of %b% representing the letter to %%a ; and replace the %bb% part that represents the numeric value with %%b :

 for /F "tokens=2,3 delims=[]=" %%a in ('set letter') do ( set "line=!line:%%a=%%b!" ) 

Of course, you should also define a letter array at the beginning of the program ...

+2
Feb 26 '16 at 3:23
source share



All Articles