• Welcome to Valhalla Legends Archive.
 

CDKey Checks

Started by Barabajagal, April 28, 2008, 08:14 PM

Previous topic - Next topic

Barabajagal

Is there a checksum value for D2/W2 and W3 keys like the last digit of SC keys? Just wondering...

iago

They are verified in some way, yes.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Barabajagal

That's not what I asked...

Ringo

Quote from: Andy on April 29, 2008, 09:52 AM
That's not what I asked...
Looked like it was to me.
IIRC, the install valid algorithm check is the same for SC cdkeys, but just remmber d2 keys are not numeric like SC keys.
See the 1st few steps of a decode d2 cdkey function (which you should have looked at already, unless you use BNCSutli for everything)

Barabajagal

No, I only use BNCSUtil for NLS... And I don't see any validation checksum in it.

I asked if there was a checksum like SC, not if they're "validated in some way".

Ringo

Quote from: Andy on April 29, 2008, 10:19 AM
No, I only use BNCSUtil for NLS... And I don't see any validation checksum in it.

I asked if there was a checksum like SC, not if they're "validated in some way".
They are the same thing.. the algorithm validates the cdkey for install


    R = 3
    For i = 0 To 15
        R = R + (iff(IsNumeric(Key(i)), Asc(Key(i)) - &H30, Asc(Key(i)) - &H37) Xor (R * 2))
    Next i
    If Not ((R And &HFF) = tmpByte) Then
        'Cdkey is shit

tmpByte is or'ed if the 0x100 bit is set from the hex value of the cdkey (derived from the key codes)
See the 1st few steps of the cdkey decode function, its right there.

Barabajagal

Oh... I sort of don't have that part in my decode function:

FUNCTION DecodeD2W2Key(BYVAL key AS STRING) AS STRING
DIM N               AS DWORD
DIM N2              AS DWORD
DIM v               AS DWORD
DIM V2              AS DWORD
DIM KeyValue        AS DWORD
DIM C1              AS BYTE
DIM C2              AS BYTE
DIM C               AS BYTE
DIM I               AS INTEGER
DIM aryKey(0 TO 15) AS STRING
DIM CodeValues      AS STRING
    CodeValues = "246789BCDEFGHJKMNPRTVWXZ"
    KeyValue = 0
    FOR I = 1 TO 16
        aryKey(I - 1) = MID$(key, I, 1)
    NEXT I
    FOR I = 0 TO 15 STEP 2
        C1 = INSTR(1, CodeValues, aryKey(I)) - 1
        IF C1 = -1 THEN C1 = &HFF
        N = C1 * 3
        C2 = INSTR(1, CodeValues, aryKey(I + 1)) - 1
        IF C2 = -1 THEN C2 = &HFF
        N = C2 + N * 8
        IF N >= &H100 THEN
            N = N - &H100
            KeyValue = KeyValue OR R
        END IF
        N2 = N
        SHIFT RIGHT N2, 4
        aryKey(I) = GetHexValue(N2)
        aryKey(I + 1) = GetHexValue(N)
        SHIFT LEFT R, 1
    NEXT I
    v = 3
    FOR I = 0 TO 15
        C = GetNumValue(aryKey(I))
        N = C
        N2 = v * 2
        N = N XOR N2
        v = v + N
    NEXT I
    v = v AND &HFF
    FOR I = 15 TO 0 STEP -1
        C = ASC(aryKey(I))
        IF I > 8 THEN
            N = I - 9
        ELSE
            N = &HF - (8 - I)
        END IF
        N = N AND &HF
        C2 = ASC(aryKey(N))
        aryKey(I) = CHR$(C2)
        aryKey(N) = CHR$(C)
    NEXT I
    V2 = &H13AC9741
    FOR I = 15 TO 0 STEP -1
        C = ASC(UCASE$(aryKey(I)))
        aryKey(I) = CHR$(C)
        IF C <= &H37 THEN
            v = V2
            C2 = v AND &HF
            C2 = C2 AND 7
            C2 = C2 XOR C
            SHIFT RIGHT V, 3
            aryKey(I) = CHR$(C2)
            V2 = v
        ELSEIF C < &H41 THEN
            C2 = CBYT(I)
            C2 = C2 AND 1
            C2 = C2 XOR C
            aryKey(I) = CHR$(C2)
        END IF
    NEXT I
    FUNCTION = JOIN$(aryKey(), "")
    ERASE aryKey()
END FUNCTION

iago

Quote from: Andy on April 29, 2008, 09:52 AM
That's not what I asked...
Ok, I'll answer the question you asked: No.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


UserLoser

Quote from: Andy on April 29, 2008, 10:31 AM
Oh... I sort of don't have that part in my decode function:

FUNCTION DecodeD2W2Key(BYVAL key AS STRING) AS STRING
DIM N               AS DWORD
DIM N2              AS DWORD
DIM v               AS DWORD
DIM V2              AS DWORD
DIM KeyValue        AS DWORD
DIM C1              AS BYTE
DIM C2              AS BYTE
DIM C               AS BYTE
DIM I               AS INTEGER
DIM aryKey(0 TO 15) AS STRING
DIM CodeValues      AS STRING
    CodeValues = "246789BCDEFGHJKMNPRTVWXZ"
    KeyValue = 0
    FOR I = 1 TO 16
        aryKey(I - 1) = MID$(key, I, 1)
    NEXT I
    FOR I = 0 TO 15 STEP 2
        C1 = INSTR(1, CodeValues, aryKey(I)) - 1
        IF C1 = -1 THEN C1 = &HFF
        N = C1 * 3
        C2 = INSTR(1, CodeValues, aryKey(I + 1)) - 1
        IF C2 = -1 THEN C2 = &HFF
        N = C2 + N * 8
        IF N >= &H100 THEN
            N = N - &H100
            KeyValue = KeyValue OR R
        END IF
        N2 = N
        SHIFT RIGHT N2, 4
        aryKey(I) = GetHexValue(N2)
        aryKey(I + 1) = GetHexValue(N)
        SHIFT LEFT R, 1
    NEXT I
    v = 3
    FOR I = 0 TO 15
        C = GetNumValue(aryKey(I))
        N = C
        N2 = v * 2
        N = N XOR N2
        v = v + N
    NEXT I
    v = v AND &HFF
    FOR I = 15 TO 0 STEP -1
        C = ASC(aryKey(I))
        IF I > 8 THEN
            N = I - 9
        ELSE
            N = &HF - (8 - I)
        END IF
        N = N AND &HF
        C2 = ASC(aryKey(N))
        aryKey(I) = CHR$(C2)
        aryKey(N) = CHR$(C)
    NEXT I
    V2 = &H13AC9741
    FOR I = 15 TO 0 STEP -1
        C = ASC(UCASE$(aryKey(I)))
        aryKey(I) = CHR$(C)
        IF C <= &H37 THEN
            v = V2
            C2 = v AND &HF
            C2 = C2 AND 7
            C2 = C2 XOR C
            SHIFT RIGHT V, 3
            aryKey(I) = CHR$(C2)
            V2 = v
        ELSEIF C < &H41 THEN
            C2 = CBYT(I)
            C2 = C2 AND 1
            C2 = C2 XOR C
            aryKey(I) = CHR$(C2)
        END IF
    NEXT I
    FUNCTION = JOIN$(aryKey(), "")
    ERASE aryKey()
END FUNCTION


where is R defined at? that's some odd looking vb

Barabajagal

#9
Top of the module(I dunno why, maybe I was half asleep)... and it's not VB.

FUNCTION IsNumeric(BYVAL Value AS STRING) AS LONG
    FUNCTION = RETAIN$(Value, ANY CHR$(48 TO 57)) = Value
END FUNCTION

FUNCTION GetHexValue(BYVAL lVAL AS DOUBLE) AS STRING
    lVAL = lVAL AND &HF
    IF lVAL < 10 THEN
        FUNCTION = CHR$(lVAL + &H30)
    ELSE
        FUNCTION = CHR$(lVAL + &H37)
    END IF
END FUNCTION

FUNCTION GetNumValue(BYVAL lVAL AS STRING) AS BYTE
    lVAL = UCASE$(lVAL)
    IF IsNumeric(lVAL) THEN
        FUNCTION = ASC(lVAL) - &H30
    ELSE
        FUNCTION = ASC(lVAL) - &H37
    END IF
END FUNCTION

FUNCTION DecodeD2W2Key(BYVAL key AS STRING) AS STRING
DIM R               AS DWORD
DIM N               AS DWORD
DIM N2              AS DWORD
DIM v               AS DWORD
DIM V2              AS DWORD
DIM KeyValue        AS DWORD
DIM C1              AS BYTE
DIM C2              AS BYTE
DIM C               AS BYTE
DIM I               AS INTEGER
DIM aryKey(0 TO 15) AS STRING
DIM CodeValues      AS STRING
    CodeValues = "246789BCDEFGHJKMNPRTVWXZ"
    R = 1
    KeyValue = 0
    FOR I = 1 TO 16
        aryKey(I - 1) = MID$(key, I, 1)
    NEXT I
    FOR I = 0 TO 15 STEP 2
        C1 = INSTR(1, CodeValues, aryKey(I)) - 1
        IF C1 = -1 THEN C1 = &HFF
        N = C1 * 3
        C2 = INSTR(1, CodeValues, aryKey(I + 1)) - 1
        IF C2 = -1 THEN C2 = &HFF
        N = C2 + N * 8
        IF N >= &H100 THEN
            N = N - &H100
            KeyValue = KeyValue OR R
        END IF
        N2 = N
        SHIFT RIGHT N2, 4
        aryKey(I) = GetHexValue(N2)
        aryKey(I + 1) = GetHexValue(N)
        SHIFT LEFT R, 1
    NEXT I
    v = 3
    FOR I = 0 TO 15
        C = GetNumValue(aryKey(I))
        N = C
        N2 = v * 2
        N = N XOR N2
        v = v + N
    NEXT I
    v = v AND &HFF
    FOR I = 15 TO 0 STEP -1
        C = ASC(aryKey(I))
        IF I > 8 THEN
            N = I - 9
        ELSE
            N = &HF - (8 - I)
        END IF
        N = N AND &HF
        C2 = ASC(aryKey(N))
        aryKey(I) = CHR$(C2)
        aryKey(N) = CHR$(C)
    NEXT I
    V2 = &H13AC9741
    FOR I = 15 TO 0 STEP -1
        C = ASC(UCASE$(aryKey(I)))
        aryKey(I) = CHR$(C)
        IF C <= &H37 THEN
            v = V2
            C2 = v AND &HF
            C2 = C2 AND 7
            C2 = C2 XOR C
            SHIFT RIGHT V, 3
            aryKey(I) = CHR$(C2)
            V2 = v
        ELSEIF C < &H41 THEN
            C2 = CBYT(I)
            C2 = C2 AND 1
            C2 = C2 XOR C
            aryKey(I) = CHR$(C2)
        END IF
    NEXT I
    FUNCTION = JOIN$(aryKey(), "")
    ERASE aryKey()
END FUNCTION
better?

UserLoser

well it looks like vb, idk what of that syntax lets you declare something as DWORD

Barabajagal

It's PowerBASIC. It looks like a BASIC language because it is.

Barabajagal

#12
Alright, got that one done, thanks Ringo. What about W3 keys? I don't even seem to have what the Product values are supposed to be; is it 0x0E for WAR3 and 0x12 for W3XP?

Edit: I just did a run through of a lot of keys, and I got some Product values I'd like to have double-checked:
NYVXXMMC9P6VDYBY48F67RCZZW got 0xCE2
QXK0QNOKK6CFHZ8JI4PEHG3RIH got 0x0F
FXDB9GZYWVFD7R698W2P42C7YC got 0x36AF
DXY268ZRBVTEBNKP8P6MB4NKYN got 0x16B6
H2V49NTMCE778CY77KXXCN6NMC got 0x2A00

Are they just illegal keys, are those products valid, or is there something wrong with my decoder functions?
Nevermind, tested them myself.