PDA

View Full Version : C++ DCT4 Calc



gsmjohn
14-03-2004, 08:08 PM
Please excuse me if this sounds like a stupid question. I have just started c++ course at college and am a total newbie.

But ultimatly I want to get into producing GSM programs.

Firstly I would welcome any help advice on this matter.

Secondly is there a C++ source code for the DCT4 calc and if yes do you think me as a newbie would be able to produce a basic program with one.

Thanks

John

Crux
22-03-2004, 02:32 AM
do pigs fly? :-?

i dont think u will get any help there. sorry

capotixplus
01-04-2004, 11:08 PM
hope it helps you... is not mine... i'm not sure it works... but is a start...

capotixplus
01-04-2004, 11:10 PM
i must be doing something wrong....
just change .zip to .arj

Crux
02-04-2004, 02:57 PM
thats a shell only.

i dont think this is what he wants

stantheman
02-04-2004, 09:18 PM
Someone must be able to help this guy. you not telling me the source code for the old dct4 calc is still locked up in fort knox. theres zillions of calcs about. its got to be old crap available at tesco's by now surely.

Cosmictej
04-04-2004, 08:37 PM
Someone must be able to help this guy. you not telling me the source code for the old dct4 calc is still locked up in fort knox. theres zillions of calcs about. its got to be old crap available at tesco's by now surely.
Im looking for the algos too, like you said there are loads of calc, but they all run on Jozso calc, and are shelled, only Unique has the algos, I have my own calc, but its a shell

capotixplus
04-04-2004, 10:19 PM
unit algounit_dct4;

interface
uses MBUS_Constants;
type
Array8= array[0..7] of byte;
var
MirrorRecdIMEI, Calced8Bytes, RecdIMEI, XOREncodedIMEI: array8;
Lookup1Cntr, RollOver1, RollOver2: byte;
const
{$I maskarr.inc} //maskarray
{$I tblook1.inc}
{$I tblook2.inc}
{$I tblook3.inc}
DecodeIMEIMask:array8=($4A,$33,$78,$90,$11,$AF,$F2,$3C);
EncodeIMEIMask:array8=($30,$49,$02,$EA,$6B,$D5,$88,$46);
BitsOrder:array[0..16] of byte=(0,3,6,1,4,7,2,5,0,3,6,1,4,7,2,5,0);


procedure dct4_CalcSP(SomeImei: string; var SLMatrix: TSLMatrix);

implementation

procedure XORIMEI(Mask,SourceImei: array8; var DestIMEI: array8);
var f: integer;
a: byte;
begin
for f:=0 to 7 do begin
a:=Mask[f];
DestIMEI[f]:=SourceIMEI[f] xor a;
end;
end;

procedure MaskIMEI(var SomeRollOver: byte; Idx: integer; SomeMirror: array8; var DestIMEI: array8);
var f,g: integer;
a: byte;
begin
g:=0;
for f:=Idx to (Idx+7) do begin
a:=MaskArray[f] xor $FF;
inc(SomeRollOver,a);
DestIMEI[g]:=SomeMirror[g] xor a;
inc(g);
end;
end;

function Lookup1(var Counter: byte; SomeXorEncodedIMEI: array8):byte;
var a,R0,R6,R7: byte;
f: integer;
begin
Lookup1:=0;
if Counter>136 then exit;
R6:=Counter;a:=R6;
inc(Counter);
a:=a and 7;
a:=SomeXOREncodedIMEI[a];
R7:=a;
a:=R6;

//a:=(a shr 3) and $1F;
asm
push ax
mov al,a
rcr al,1
rcr al,1
rcr al,1
and al,$1F
mov a,al
pop ax
end;
a:=BitsOrder[a];
R0:=a;
a:=R7;
//inc(R0);
for f:=1 to R0 do begin
asm
push ax
mov al,a
rol al,1
mov a, al
pop ax
end;
end;
R7:=a;
a:=R6;
a:=TblLookup3[a] xor $FF;
inc(a,R7);
R7:=a;
Lookup1:=R7;
end;

procedure Calc_1(SomeXorEncodedIMEI: array8; var DestIMEI: array8);
var
f: integer;
LookUpCtr: byte;
a,b: byte;
begin
LookupCtr:=0;
for f:=0 to 7 do begin
//no-lookup operations here
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
DestIMEI[0]:=DestIMEI[0] xor a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
DestIMEI[1]:=DestIMEI[1] + a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
DestIMEI[2]:=DestIMEI[2] + a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
DestIMEI[3]:=DestIMEI[3] xor a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
DestIMEI[4]:=DestIMEI[4] xor a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
DestIMEI[5]:=DestIMEI[5] + a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
DestIMEI[6]:=DestIMEI[6] + a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
DestIMEI[7]:=DestIMEI[7] xor a;
//Lookup operations here
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
b:=TblLookup1[DestIMEI[0]] xor $FF;
DestIMEI[0]:=b+a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
b:=TblLookup2[DestIMEI[1]] xor $FF;
DestIMEI[1]:=b xor a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
b:=TblLookup2[DestIMEI[2]] xor $FF;
DestIMEI[2]:=b xor a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
b:=TblLookup1[DestIMEI[3]] xor $FF;
DestIMEI[3]:=b+a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
b:=TblLookup1[DestIMEI[4]] xor $FF;
DestIMEI[4]:=b+a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
b:=TblLookup2[DestIMEI[5]] xor $FF;
DestIMEI[5]:=b xor a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
b:=TblLookup2[DestIMEI[6]] xor $FF;
DestIMEI[6]:=b xor a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
b:=TblLookup1[DestIMEI[7]] xor $FF;
DestIMEI[7]:=b+a;
//Permutations here
a:=DestIMEI[0]; //perm 1
inc(a,DestIMEI[1]);
DestIMEI[1]:=a;
inc(a,DestIMEI[0]);
DestIMEI[0]:=a;
a:=DestIMEI[2]; //perm 2
inc(a,DestIMEI[3]);
DestIMEI[3]:=a;
inc(a,DestIMEI[2]);
DestIMEI[2]:=a;
a:=DestIMEI[4]; //perm 3
inc(a,DestIMEI[5]);
DestIMEI[5]:=a;
inc(a,DestIMEI[4]);
DestIMEI[4]:=a;
a:=DestIMEI[6]; //perm 4
inc(a,DestIMEI[7]);
DestIMEI[7]:=a;
inc(a,DestIMEI[6]);
DestIMEI[6]:=a;
a:=DestIMEI[0]; //perm 5
inc(a,DestIMEI[2]);
DestIMEI[2]:=a;
inc(a,DestIMEI[0]);
DestIMEI[0]:=a;
a:=DestIMEI[4]; //perm 6
inc(a,DestIMEI[6]);
DestIMEI[6]:=a;
inc(a,DestIMEI[4]);
DestIMEI[4]:=a;
a:=DestIMEI[1]; //perm 7
inc(a,DestIMEI[3]);
DestIMEI[3]:=a;
inc(a,DestIMEI[1]);
DestIMEI[1]:=a;
a:=DestIMEI[5]; //perm 8
inc(a,DestIMEI[7]);
DestIMEI[7]:=a;
inc(a,DestIMEI[5]);
DestIMEI[5]:=a;
a:=DestIMEI[0]; //perm 9
inc(a,DestIMEI[4]);
DestIMEI[4]:=a;
inc(a,DestIMEI[0]);
DestIMEI[0]:=a;
a:=DestIMEI[1]; //perm 10
inc(a,DestIMEI[5]);
DestIMEI[5]:=a;
inc(a,DestIMEI[1]);
DestIMEI[1]:=a;
a:=DestIMEI[2]; //perm 11
inc(a,DestIMEI[6]);
DestIMEI[6]:=a;
inc(a,DestIMEI[2]);
DestIMEI[2]:=a;
a:=DestIMEI[3]; //perm 12
inc(a,DestIMEI[7]);
DestIMEI[7]:=a;
inc(a,DestIMEI[3]);
DestIMEI[3]:=a;
//Final swap //perm 13
a:=DestIMEI[1];
DestIMEI[1]:=DestIMEI[4];
DestIMEI[4]:=DestIMEI[2];
DestIMEI[2]:=a;
a:=DestIMEI[3];
DestIMEI[3]:=DestIMEI[5];
DestIMEI[5]:=DestIMEI[6];
DestIMEI[6]:=a;
end;

a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
DestIMEI[0]:=DestIMEI[0] xor a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
DestIMEI[1]:=DestIMEI[1] + a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
DestIMEI[2]:=DestIMEI[2] + a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
DestIMEI[3]:=DestIMEI[3] xor a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
DestIMEI[4]:=DestIMEI[4] xor a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
DestIMEI[5]:=DestIMEI[5] + a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
DestIMEI[6]:=DestIMEI[6] + a;
a:=lookup1(LookUpCtr,SomeXorEncodedIMEI);
DestIMEI[7]:=DestIMEI[7] xor a;
end;

function Hex2int(Digit: Char): byte;
var b: byte;
c: char;
begin
c:=Digit;
b:=ord(c);
if (b<=$39) and (b>=$30) then b:=b-$30
else
b:=b-$41+10;
Hex2Int:=b;
end;

procedure dct4_CalcSP(SomeImei: string; var SLMatrix: TSLMatrix);
var
f,g,h: integer;
a,b: byte;
begin
f:=0;g:=0;
FillChar(SLMatrix,SizeOf(SLMatrix),0);
repeat
a:=(Hex2Int(SomeIMEI[f+1]))*16;
b:=Hex2Int(SomeIMEI[f+2]);
RecdIMEI[g]:=a + b;
inc(f,2);
inc(g);
until f=14;
RecdIMEI[7]:=$00;

for f:=0 to 7 do MirrorRecdIMEI[f]:=0; //Initialize mirror array

XORIMEI(DecodeIMEIMask,RecdIMEI,XOREncodedIMEI); //calculate XOR Encoded IMEI
RollOver1:=0; RollOver2:=0; //init CRC counters
f:=0;
repeat
MaskIMEI(RollOver1, f, MirrorRecdIMEI, Calced8Bytes);
Calc_1(XorEncodedIMEI, Calced8Bytes);
h:=0;
for g:=f to (f+7) do begin
a:=Calced8Bytes[h];
mirrorrecdimei[h]:=a;
SLMatrix[g]:=a; inc(h);
inc(RollOver2,a);
end;
inc(f,8);
until f=$3a0;

//Here calculation of verification data
Calced8Bytes[0]:=RollOver1;
Calced8Bytes[1]:=not RollOver1;
Calced8Bytes[2]:=RollOver2;
Calced8Bytes[3]:=not RollOver2;
Calced8Bytes[4]:=$5B;
Calced8Bytes[5]:=$72;
Calced8Bytes[6]:=$AE;
Calced8Bytes[7]:=$36;
XORIMEI(EncodeIMEIMask,RecdIMEI,XOREncodedIMEI);
Calc_1(XorEncodedIMEI, Calced8Bytes);
for f:=$3a0 to $3a7 do SLMatrix[f]:=Calced8Bytes[f-$3a0];
end;

end.


I have disabled smilies in this post as they replace parts of the code.
Yotamz.

Cosmictej
04-04-2004, 10:35 PM
m8 thats d code 4 mbus not calcing codes

indear
15-04-2004, 02:18 AM
see here http://nokiafree.org/forums/t60683/h/s.html :)