• Welcome to Valhalla Legends Archive.
 

MS-DOS String Parsing

Started by Yegg, May 20, 2005, 04:04 PM

Previous topic - Next topic

Yegg

Ok ok, I should have referred to it as Batch. Also, I seem to be having fun programming in Batch. I'm creating a starcraft cdkey decoder in it. Yes I know it probably won't have much of a purpose, but I'm just doing it for fun.

Adron

Quote from: Yegg on May 21, 2005, 01:55 PM
Ok ok, I should have referred to it as Batch. Also, I seem to be having fun programming in Batch. I'm creating a starcraft cdkey decoder in it. Yes I know it probably won't have much of a purpose, but I'm just doing it for fun.

It's impossible with only what's built-in to the MS-DOS batch file (command) interpreter. You need to call some program.

Yegg

    def starkey(key):
        arrayKey = list(key);
        v = 3;
        for i in range(0, 12):
            c = arrayKey[i];
            n = int(c);
            n2 = v * 2;
            n ^= n2;
            v += n;
        v %= 10;
        if(hex(v) == arrayKey[12]):
            valid = [True];
        v = 194;
        for i in range(11, -1, -1):
            if(v < 7):
                break;
            c = arrayKey[i];
            n = int(v/12);
            n2 = v % 12;
            v -= 17;
            c2 = arrayKey[n2];
            arrayKey[i] = c2;
            arrayKey[n2] = c;
        v2 = 0x13AC9741;
        for i in range(11, -1, -1):
            c = arrayKey[i].upper();
            arrayKey[i] = c;
            if(ord(c) <= ord('7')):
                v = v2;
                c2 = v & 0xFF;
                c2 &= 7;
                c2 ^= int(c);
                v = int(v) >> 3;
                arrayKey[i] = c2;
                v2 = v;
            elif(ord(c) < 65):
                c2 = int(i);
                c2 &= 1;
                c2 ^= int(c);
                arrayKey[i] = c2;
        decode_starcraft_key = ''.join(map(str, arrayKey));
        return decode_starcraft_key;

Look at this code and tell me what this has that a MS-DOS batch file is not capable of. I'd really like to know.

Kp

It's been a while since I actually deigned to use something as weak as a DOS batch job, but I think the only thing in that code you could do without calling an external program would be a passable imitation at looping. :)
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Yegg

If Adron's concern was looping then I guess he wasn't thinking clearly when he made that post. Of course I couldn't use anything built into DOS that works like a for loop (the way I needed it to work), that is why I created my own "loop" functions in my program. They work fine too.

Adron

Quote from: Yegg on May 21, 2005, 07:14 PM
If Adron's concern was looping then I guess he wasn't thinking clearly when he made that post. Of course I couldn't use anything built into DOS that works like a for loop (the way I needed it to work), that is why I created my own "loop" functions in my program. They work fine too.

As Kp said, close to the only thing you can do is looping. You can't divide, you can't multiply, you can't xor, you can't index characters, you can't round, you can't take the ascii value of a character ... the list goes on.

You can use something built into DOS for a for loop though:


for %%a in (0 1 2 3 4 5 6 7 8 9 10 11 12) do ...

Yegg

Quote from: Adron on May 22, 2005, 10:47 AM
You can't divide, you can't multiply, you can't xor, you can't index characters, you can't round, you can't take the ascii value of a character ... the list goes on.
What are you talking about?? Batch can use bit shifting functions, or, xor, ad/subtract, multiply/divide, and more. I've already done that with Batch. If that wern't possible then I wouldn't be creating this program.

Kp

Then how about you show us the statements you're using which supposedly implement this?  To the best of my knowledge, no traditional DOS interpreter can do any of those operations.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

R.a.B.B.i.T

Maybe he's writing in BASIC?

Adron

Quote from: Yegg on May 22, 2005, 05:24 PM
Quote from: Adron on May 22, 2005, 10:47 AM
You can't divide, you can't multiply, you can't xor, you can't index characters, you can't round, you can't take the ascii value of a character ... the list goes on.
What are you talking about?? Batch can use bit shifting functions, or, xor, ad/subtract, multiply/divide, and more. I've already done that with Batch. If that wern't possible then I wouldn't be creating this program.

You are then not using MS-DOS' batch file language. Its command interpreter does not have any of those commands. You are probably just confused.

Yegg

I hope I'm not confused......Here is my code, so far. There are a few minor errors but the math operators works (I've got to do a little more work to make the % operator work correctly).
:: MS-DOS Starcraft CDKey Decoder was created by Yegg
@title Starcraft CDKey Decoder
@color 78

:begin
@set input=
@set /p input=Enter a CDKey:
@if '%input%'=='' (
  @echo You have not entered in a cdkey, please try again.
  @goto begin)
@call :makelist %input%

:makelist
@set listkey=[%1]
@call :decode %listkey%

:decode
@set newkey=%1
@set newkey=%newkey:~1, 13%
@set original=%newkey%
@set dig1=%newkey:~0, 1%
@set dig2=%newkey:~1, 1%
@set dig3=%newkey:~2, 1%
@set dig4=%newkey:~3, 1%
@set dig5=%newkey:~4, 1%
@set dig6=%newkey:~5, 1%
@set dig7=%newkey:~6, 1%
@set dig8=%newkey:~7, 1%
@set dig9=%newkey:~8, 1%
@set dig10=%newkey:~9, 1%
@set dig11=%newkey:~10, 1%
@set dig12=%newkey:~11, 1%
@set v=3
@for %%i in (1 2 3 4 5 6 7 8 9 10 11 12) do (
  @for %%d in (%dig1% %dig2% %dig3% %dig4% %dig5% %dig6% %dig7% %dig8% %dig9% %dig10% %dig11% %dig12%) do (
    @set c=%%d
    @set n=%c%
    @set /a n2=%v%*2
    @set /a n^=%n2%
    @set /a v+=%n%))
@set v=194
for %%1 in (12 11 10 9 8 7 6 5 4 3 2 1) do (
  for %%d in (%dig1% %dig2% %dig3% %dig4% %dig5% %dig6% %dig7% %dig8% %dig9% %dig10% %dig11% %dig12%) do (
    if not %v% lss 7 (
      @if %n2%==0 set var=%dig1%
      @if %n2%==1 set var=%dig2%
      @if %n2%==2 set var=%dig3%
      @if %n2%==3 set var=%dig4%
      @if %n2%==4 set var=%dig5%
      @if %n2%==5 set var=%dig6%
      @if %n2%==6 set var=%dig7%
      @if %n2%==7 set var=%dig8%
      @if %n2%==8 set var=%dig9%
      @if %n2%==9 set var=%dig10%
      @if %n2%==10 set var=%dig11%
      @if %n2%==11 set var=%dig12%
      @set c=%%d
      @set /a n=%v%/12
      @set /a n2=%v% % 12
      @set /a v-=17
      @set c2=%var%
      @set %%d=%c2%
      @set %var%=%c%)))
@set v2=330078017
@for %%i in (12 11 10 9 8 7 6 5 4 3 2 1) do (
  @for %%d in (%dig1% %dig2% %dig3% %dig4% %dig5% %dig6% %dig7% %dig8% %dig9% %dig10% %dig11% %dig12%) do (
    @set c=%%d
    @echo %%d
    @set %%d=%c%
    @if %c%==0 set val=48
    @if %c%==1 set val=49
    @if %c%==2 set val=50
    @if %c%==3 set val=51
    @if %c%==4 set val=52
    @if %c%==5 set val=53
    @if %c%==6 set val=54
    @if %c%==7 set val=55
    @if %c%==8 set val=56
    @if %c%==9 set val=57
    @if %val% leq 55 (
      @set v=%v2%
      @set /a c2=%v%&0xFF
      @set /a c2&=7
      @set /a c2^=%c%
      @set /a v>>=3
      @set %%d=%c2%
      @set v2=%v%)
    @if %val% lss 65 (
      @set c2=%%i
      @set /a c2&=1
      @set /a c2^=%c%
      @set %%d=%c2%)))
:finish
@echo %dig1%%dig2%%dig3%%dig4%%dig5%%dig6%%dig7%%dig8%%dig9%%dig10%%dig11%%dig12%
@goto begin

iNsAnE-MS

#26
um... fyi...

@echo off

last DOS version I wrote batch processing for was 6.22, and it didn't support a majority of that (IE mathmatical routines LoL)>.<

still supported "@echo off" so you don't have to put @ at the beginning of each line though!

Yegg

I enjoy typing @ at the beginning of each line for your information. :). Plus I have echo on temporarily, for erorr finding purposes, until the program is done. When an error occurs, I remove the @ at the beginning of the suspected line and try to fix the problem. My program apparently supports all of that. I have no clue why it doesn't work for you. Maybe I installed some kind of add-on that I can't remember?

Kp

What version of DOS is this, btw?  A Win9x-related DOS, or something earlier?
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Yegg

Actually, I have no cluu what version this is. Is something different about it than usual?

|