Solved algorithm decoder with table

June 24, 2015 at 15:42:42
Specs: Windows 7
Ok so here's how this decoder works.

Each character can be represented by a maximum number of 20 different numbers depending on its position.
The dot between the numbers is the delimiter per each character represented.

aaaaaaaaaaaaaaaaaaaa =

a in position 1 is 25, a in position 2 is 62.
So lets take an example of a string such as:

the two a's are in position 5 and 6, this means the last 2 characters (aa) encoded will be:

The entire table which includes all the combinations of 20 digits representing each character depending on its position can be found here:

So encoding the string:
will become:

1 is in the first position, so using this:

We can see 73 is the 1st.

2 is in the second position so using this:

We can see 109 is in the 2nd position.

3 is in the third position so using this:

We can see 51 is in the 3rd position

4 is in the 4th position so using this:

we can see 155 is in the 4th position

a is in the 5th position so using this:

we can see 126 is in the 5th position.

the second a is in the 6th position so using this:

we can see 243 is in the 6th position, leading to:

Now what i want to be able to do is, enter a set of numbers with the dot delimiter which is a maximum total of 20 characters and a minimum of one and get the decoded string back.
So if i enter e.g:

i will get:

if i enter:

i will get:

How can this be done in batch?

I have a pretty rough idea, calculate the number of dots inside the inputted set of numbers and add one to it, that will show the number of characters.
then do the for /f in () do (
set a = %%a
set b = %%b
depending on how many chars it is.
Then do something like:
type table.txt | find firstchar
and then check each number set and see if position of number found matches completely, if it is, then the 1st char is found, move onto 2nd char until all characters are found.

See More: algorithm decoder with table

Report •

June 25, 2015 at 02:04:36
First, (one time only), split the alpha and the dot-numbers into two files OR a file and a one-line file consisting of the alphabet etc.. Then use FINDSTR /N with regexp to locate the position of each input dot-value in file #1, using the dot-position of each dot-sep. input data-value. The line number returned by FINDSTR will correspond to the line number or char. position in the second (Alpha) file or string.
A loop takes each input dot-segment-value, combined with a counter, to get the coordinates, which are used to build the regexp search string for FINDSTR. F/E, to target "176" in the 3rd position (dot position):
FINDSTR /N /R "\..*\..*\176\..*"
note that each line of the search-file must be "book-ended" with a dot to avoid unnecessary hoop-jumping. That way, for each dot-offset of the input data, you will add one set of \..* to your regexp FINDSTR submission.

Here's a crappy "parser":

@echo off & setlocal
set out=
set /p x=enter dot separated integers:
set x=%x:.= %
set c=0
call :1 %x%
if not defined z goto :ex
echo z: %z%--c:%c%
set /a c+=1
goto :0

for /L %%a in (1 1 %c%) do shift
set z=%1
echo dot offset: %c%
echo dot-segment value: %z%
set out=!out! %1
goto :eof

echo %out%

Report •

June 25, 2015 at 03:24:11
I have no idea how to do what you specified in the beginning.
Thank you for the effort.
However, I just want a batch file that can use the table.txt file in the same directory (that text from pastebin) and use that to decode it (the set of numbers), can you provide such a script and provide the correct format of the table to be able to accomplish this?

Thanks again.

Report •

June 25, 2015 at 21:18:04
✔ Best Answer
Yeh, I apologize. It was getting very late (or early). I thought it would be fairly simple, but it took some work. This solution worked in my tests, using the table from paste-bin, with the exception of the exclamation mark, which might be accomodated with additional coding headache. I would just substitute some other character if you plan to use batch.
::-------- begin batchscript
@echo off & setlocal
if exist table2 goto :1
::--- this part reconfigures the table taken from pastebin, only needs done once.
for /f "tokens=1-3" %%a in (table) do (
set x=%%a
echo !x:~0,1!
echo %%c
>>table2 echo .%%c. !x:~0,1!

::---- begin main
set out=
set c=0
::--- you could eliminate the dots and just use spaces here
set /p x=enter dot separated integers:
set x=%x:.= %
call :2 %x%
echo out:%out%
goto :eof

if "%1" equ "" goto :eof
set m=^^
for /L %%a in (1 1 %c%) do set m=!m!\.[^^^^^^^^\.]*
set m=%m%\.%1\..*
for /f "tokens=1-2" %%a in ('findstr /r /b "%m%" table2') do (
rem echo A:%%a B:%%b
set out=!out!%%b
set /a c+=1
goto :2

message edited by nbrane

Report •

Related Solutions

June 25, 2015 at 23:11:43
Wow, insane, thanks nbrane :D.

Report •

Ask Question