GSM Shop GSM Shop
GSM-Forum  

Welcome to the GSM-Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features.
Only registered members may post questions, contact other members or search our database of over 8 million posts.

Registration is fast, simple and absolutely free so please - Click to REGISTER!

If you have any problems with the registration process or your account login, please contact contact us .

Go Back   GSM-Forum > Other Gsm/Mobile Related Forums > GSM Programming & Reverse Engineering


GSM Programming & Reverse Engineering Here you can post all Kind of GSM Programming and Reverse Engineering tools and Secrets.

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 07-30-2013, 13:41   #61 (permalink)
No Life Poster
 
oOXTCOo's Avatar
 
Join Date: Dec 2000
Location: J.A.U - Just Another Unlocker
Age: 43
Posts: 3,498
Member: 2878
Status: Offline
Thanks Meter: 9,123

here, removed some code to reduze needed components...
now the only unit u need to add is the sha1 unit.. i always use the one from W.Erhardt.

Code:
unit SL3_NCK;

interface

uses
    Windows, SysUtils, SHA1_BB;

    function SL3_CALC_NCK(TARGET_HASH, MASTER_SP_CODE : string; var  nck1, nck2, nck3, nck4, nck5, nck6, nck7 : string) : string;

implementation

function StrToHex(s: string): string;
var
    i: Integer;
begin
    Result:='';
    If length(s)>0 then
      for i:=1 to length(s) do
        result:=result+IntToHex(Ord(s[i]),2);
end;

function HexToStr(s: string): string;
var
    i: Integer;
begin
    Result:=''; i:=1;
    while i<Length(s) do
    begin
        Result:=Result+Chr(StrToIntDef('$'+Copy(s,i,2),0));
        Inc(i,2);
    end;
end;

function HexToInt(HexNum: string): LongInt;
begin
   Result:=StrToInt('$' + HexNum) ;
end;

function My_SHA1(input : string) : string;
var
  i, VAL : integer;
  ctx    : TSHA1Context;
  digest : TSHA1Digest;
begin
  result:='';
  SHA1Init(ctx);
  for i:=1 to length(input) do
  if i mod 2 = 1 then
  begin
      VAL:=hextoint(input[i] + input[i+1]);
      SHA1Update(ctx, @VAL, 1);
  end;
  Sha1Final(ctx,digest);
  for i:=0 to sizeof(digest)-1 do result := result + strtohex(Chr(Ord(digest[i])));
end;

function SimlFeistel(sh, precode:string) : string;
var
    i,prenck : integer;
    nck,nck2: string;
begin
          for i:=1 to length(precode) do
          if i mod 2 = 1 then
          begin
              nck:=sh[i]+sh[i+1];
              nck2:=precode[i]+precode[i+1];

              prenck:=( (hextoint(nck)+hextoint(nck2)) mod 10);
              result:=result+'0'+inttostr(prenck);
end;

function SL3_CALC_NCK(TARGET_HASH, MASTER_SP_CODE : string; var  nck1, nck2, nck3, nck4, nck5, nck6, nck7 : string) : string;
var
    Data, precode, levelhash : string;
    sh, precode7, precode8, final : string;
    i, j, magic : integer;
begin
    MASTER_SP_CODE:='000000'+Copy(MASTER_SP_CODE, 1, 24);

    for i:=1 to 7 do
    begin
        levelhash:=My_SHA1('0'+inttostr(i)+TARGET_HASH);
        precode8:=Copy(MASTER_SP_CODE, 0,16);
        precode7:=Copy(MASTER_SP_CODE, 17,30);

        for magic:=0 to 1 do
        begin
            sh:=My_SHA1('0'+inttostr(magic)+Copy(levelhash, 0,32)+precode8);
            precode:='';
            Precode:=SimlFeistel(sh, precode7);
            precode7:=precode;

            sh:=My_SHA1('0'+inttostr(magic)+Copy(levelhash, 0,32)+precode);
            precode:='';
            Precode:=SimlFeistel(sh, precode8);
            precode8:=precode;
        end;

        data:='';
        final:=precode8+precode7;
        for j:=1 to length(final) do if j mod 2 = 1 then data:=data+inttostr(hextoint(final[j]+final[j+1]));
        //ADDLine('#pw+'+data+'+'+inttostr(i)+'#');
        if i=1 then nck1:=(data);
        if i=2 then nck2:=(data);
        if i=3 then nck3:=(data);
        if i=4 then nck4:=(data);
        if i=5 then nck5:=(data);
        if i=6 then nck6:=(data);
        if i=7 then nck7:=(data);
    end;
end;

end.
now it should be no problem for anyone to compile it in delphi.



@..::SuB::.. i hope now you are happy?
cause you was the one how always asked for it any every sl3 tread here.


i posted the php version, cause it was intendet for ppl with sl3 bruteforce service websites...
so they can automatically calculate the unlock codes directly online...

Last edited by oOXTCOo; 07-30-2013 at 13:48.
 
The Following 2 Users Say Thank You to oOXTCOo For This Useful Post:
Old 07-30-2013, 14:09   #62 (permalink)
No Life Poster
 
calvinpower's Avatar
 
Join Date: Jul 2002
Location: Tanzania
Posts: 1,062
Member: 14229
Status: Offline
Thanks Meter: 135
Quote:
Originally Posted by ..::SuB::.. View Post
Anybody can do it in Delphi? I can do if i spend 1-2 hours on this but i don't have much time, im hanging out with my family, but my personal (sl3 job management) project really need it

Yes 1-2 hour Im a hobby programmer not a hacker g0d
copy paste less than 20min. source code already there...... just compile
 
Old 07-30-2013, 14:12   #63 (permalink)
No Life Poster
 
oOXTCOo's Avatar
 
Join Date: Dec 2000
Location: J.A.U - Just Another Unlocker
Age: 43
Posts: 3,498
Member: 2878
Status: Offline
Thanks Meter: 9,123
here is Sha1_bb.pas

............................................
Attached Files
File Type: zip Sha1_BB.zip (1.5 KB, 364 views)
 
The Following 4 Users Say Thank You to oOXTCOo For This Useful Post:
Show/Hide list of the thanked
Old 07-30-2013, 15:13   #64 (permalink)
No Life Poster
 
..::SuB::..'s Avatar
 
Join Date: Aug 2008
Location: The Matrix :)
Age: 36
Posts: 654
Member: 833760
Status: Offline
Sonork: 100.1597150
Thanks Meter: 114
Thank you im finally got it and im happy I've built a job manager for myself it is loading jobs for oclhashcat from MySQL database, i will post the source soon just need some correction BTW im using Lazarus, im wondering how can i port the functions
 
Old 07-30-2013, 15:54   #65 (permalink)
No Life Poster
 
Join Date: Oct 2010
Posts: 723
Member: 1422878
Status: Offline
Thanks Meter: 164
Hi oOXTCOo

I made some corrections in your code, for use it mor easy.

Code:
unit SL3_NCK;

interface

uses
    Windows, SysUtils, SHA1;

    function GetTokenCount(Cadena,Separador:string):integer;
    function GetToken(sCadena, sSeparador: String; iToken: Integer): String;
    function SL3_CALC_NCK(TARGET_HASH, MASTER_SP_CODE : string):string;

implementation

function StrToHex(s: string): string;
var
    i: Integer;
begin
    Result:='';
    If length(s)>0 then
      for i:=1 to length(s) do
        result:=result+IntToHex(Ord(s[i]),2);
end;


function HexToStr(s: string): string;
var
    i: Integer;
begin
    Result:=''; i:=1;
    while i<Length(s) do
    begin
        Result:=Result+Chr(StrToIntDef('$'+Copy(s,i,2),0));
        Inc(i,2);
    end;
end;


function HexToInt(HexNum: string): LongInt;
begin
   Result:=StrToInt('$' + HexNum) ;
end;

function My_SHA1(input : string) : string;
var
  i, VAL : integer;
  ctx    : TSHA1Context;
  digest : TSHA1Digest;
begin
  result:='';
  SHA1Init(ctx);
  for i:=1 to length(input) do
  if i mod 2 = 1 then
  begin
      VAL:=hextoint(input[i] + input[i+1]);
      SHA1Update(ctx, @VAL, 1);
  end;
  Sha1Final(ctx,digest);
  for i:=0 to sizeof(digest)-1 do result := result + strtohex(Chr(Ord(digest[i])));
end;


function GetTokenCount(Cadena,Separador:string):integer;
var
    Posicion:integer;
begin
    Posicion := Pos(Separador,Cadena);
    Result := 1;

    if Cadena <> '' then begin
        if Posicion <> 0 then
            while Posicion <> 0 do begin
                Delete(Cadena,1,Posicion);
                Posicion := Pos(Separador,Cadena);
                Inc (Result);
            end;
        end
        else
            Result := 0;
end;


function GetToken(sCadena, sSeparador: String; iToken: Integer): String;
var
    iPosicion: Integer;
begin
    while iToken > 1 do begin
        Delete(sCadena, 1, Pos(sSeparador,sCadena) + Length(sSeparador) - 1);
        Dec(iToken);
    end;
    iPosicion := Pos(sSeparador, sCadena);
    if iPosicion = 0 then
        Result:= sCadena
    else
        Result:= Copy(sCadena, 1, iPosicion - 1);
end;


function SimlFeistel(sh, precode:string) : string;
var
    i,prenck : integer;
    nck,nck2: string;
begin
          for i:=1 to length(precode) do
          if i mod 2 = 1 then
          begin
              nck:=sh[i]+sh[i+1];
              nck2:=precode[i]+precode[i+1];

              prenck:=( (hextoint(nck)+hextoint(nck2)) mod 10);
              result:=result+'0'+inttostr(prenck);
          end;
end;

function SL3_CALC_NCK(TARGET_HASH, MASTER_SP_CODE : string):string;
var
    Data, precode, levelhash : string;
    sh, precode7, precode8, final : string;
    i, j, magic : integer;
    TCod :String;
begin
    MASTER_SP_CODE:='000000'+Copy(MASTER_SP_CODE, 1, 24);

    for i:=1 to 7 do
    begin
        levelhash:=My_SHA1('0'+inttostr(i)+TARGET_HASH);
        precode8:=Copy(MASTER_SP_CODE, 0,16);
        precode7:=Copy(MASTER_SP_CODE, 17,30);

        for magic:=0 to 1 do
        begin
            sh:=My_SHA1('0'+inttostr(magic)+Copy(levelhash, 0,32)+precode8);
            precode:='';
            Precode:=SimlFeistel(sh, precode7);
            precode7:=precode;

            sh:=My_SHA1('0'+inttostr(magic)+Copy(levelhash, 0,32)+precode);
            precode:='';
            Precode:=SimlFeistel(sh, precode8);
            precode8:=precode;
        end;

        data:='';
        final:=precode8+precode7;
        for j:=1 to length(final) do if j mod 2 = 1 then data:=data+inttostr(hextoint(final[j]+final[j+1]));
        //ADDLine('#pw+'+data+'+'+inttostr(i)+'#');
        data := '#pw+' + data + '+' + inttostr(i)+'#';
        if (i = 1)
         then  Result := (data)
         else Result := Result+','+(data);
    end;
end;

end.
For use the tokens see this code

Code:
procedure TFNokiaSL3Hash2NCK.btnCalcClick(Sender: TObject);
var
 TCods :String;
 n:byte;
begin
 Self.Cursor := crHourGlass;
 MLogs.Lines.Clear;
 MLogs.Lines.Add('TARGET_HASH   : ');
 MLogs.Lines.Add('   '+ LabeledEdit1.Text);
 MLogs.Lines.Add('MASTER_SP_CODE: ');
 MLogs.Lines.Add('   '+ LabeledEdit2.Text);
 MLogs.Lines.Add('   ');

 TCods := SL3_CALC_NCK (LabeledEdit1.Text, LabeledEdit2.Text);
 for n := 1 to GetTokenCount(TCods,',')
   do begin
       MLogs.Lines.Add(GetToken(TCods,',',n)) ;
     end;
   Self.Cursor := crDefault;
end;
I Build my own demo with the options to check online from your site an Calc offline






Big thanks oOXTCOo

BR

Helpinterchange
Attached Images
File Type: jpg j2k_hash2nck_offline.jpg (60.7 KB, 634 views)
 
Old 07-30-2013, 16:20   #66 (permalink)
No Life Poster
 
Join Date: Oct 2010
Posts: 723
Member: 1422878
Status: Offline
Thanks Meter: 164
Modifications to unit SHA1

it needs the unit tools.pas for using

function LRot32(X: dword; c: integer): dword; assembler;

Code:
function LRot32(X: dword; c: integer): dword; register; assembler;
asm
  mov ecx, edx
  rol eax, cl
end;
i change it for

Code:
function LRot32(a, b: longword): longword;
 begin
   result:= (a shl b) or (a shr (32 - b));
 end;
for make compatible with other languages like Lazarus.

and add the type DWord

Code:
type
{$IFDEF VER120}
  dword= longword;
{$ELSE}
  dword= longint;
{$ENDIF}


unit j2k_Sha1 Source code
------------------------------------

Code:
{
***************************************************
* A binary compatible SHA1 implementation         *
* written by Dave Barton ([email protected]) *
***************************************************
* 160bit hash size                                *
***************************************************
}
unit j2k_Sha1;

interface
uses
  Sysutils;

type
{$IFDEF VER120}
  dword= longword;
{$ELSE}
  dword= longint;
{$ENDIF}

  TSHA1Digest= array[0..19] of byte;
  TSHA1Context= record
    Hash: array[0..4] of DWord;
    Hi, Lo: integer;
    Buffer: array[0..63] of byte;
    Index: integer;
  end;

function SHA1SelfTest: boolean;
procedure SHA1Init(var Context: TSHA1Context);
procedure SHA1Update(var Context: TSHA1Context; Buffer: pointer; Len: integer);
procedure SHA1Final(var Context: TSHA1Context; var Digest: TSHA1Digest);

//******************************************************************************
implementation
{$R-}


function LRot32(a, b: longword): longword;
 begin
   result:= (a shl b) or (a shr (32 - b));
 end;

function SHA1SelfTest: boolean;
const
  s: string= 'abc';
  OutDigest: TSHA1Digest=
    ($a9,$99,$3e,$36,$47,$06,$81,$6a,$ba,$3e,$25,$71,$78,$50,$c2,$6c,$9c,$d0,$d8,$9d);
var
  Context: TSHA1Context;
  Digest: TSHA1Digest;
begin
  SHA1Init(Context);
  SHA1Update(Context,@s[1],length(s));
  SHA1Final(Context,Digest);
  if CompareMem(@Digest,@OutDigest,Sizeof(Digest)) then
    Result:= true
  else
    Result:= false;
end;

//******************************************************************************
function F1(x, y, z: DWord): DWord;
begin
  Result:= z xor (x and (y xor z));
end;
function F2(x, y, z: DWord): DWord;
begin
  Result:= x xor y xor z;
end;
function F3(x, y, z: DWord): DWord;
begin
  Result:= (x and y) or (z and (x or y));
end;

//******************************************************************************
function RB(A: DWord): DWord;
begin
  Result:= (A shr 24) or ((A shr 8) and $FF00) or ((A shl 8) and $FF0000) or (A shl 24);
end;

procedure SHA1Compress(var Data: TSHA1Context);
var
  A, B, C, D, E, T: DWord;
  W: array[0..79] of DWord;
  i: integer;
begin
  Move(Data.Buffer,W,Sizeof(Data.Buffer));
  for i:= 0 to 15 do
    W[i]:= RB(W[i]);
  for i:= 16 to 79 do
    W[i]:= LRot32(W[i-3] xor W[i-8] xor W[i-14] xor W[i-16],1);
  A:= Data.Hash[0]; B:= Data.Hash[1]; C:= Data.Hash[2]; D:= Data.Hash[3]; E:= Data.Hash[4];
  for i:= 0 to 19 do
  begin
    T:= LRot32(A,5) + F1(B,C,D) + E + W[i] + $5A827999;
    E:= D; D:= C; C:= LRot32(B,30); B:= A; A:= T;
  end;
  for i:= 20 to 39 do
  begin
    T:= LRot32(A,5) + F2(B,C,D) + E + W[i] + $6ED9EBA1;
    E:= D; D:= C; C:= LRot32(B,30); B:= A; A:= T;
  end;
  for i:= 40 to 59 do
  begin
    T:= LRot32(A,5) + F3(B,C,D) + E + W[i] + $8F1BBCDC;
    E:= D; D:= C; C:= LRot32(B,30); B:= A; A:= T;
  end;
  for i:= 60 to 79 do
  begin
    T:= LRot32(A,5) + F2(B,C,D) + E + W[i] + $CA62C1D6;
    E:= D; D:= C; C:= LRot32(B,30); B:= A; A:= T;
  end;
  Data.Hash[0]:= Data.Hash[0] + A;
  Data.Hash[1]:= Data.Hash[1] + B;
  Data.Hash[2]:= Data.Hash[2] + C;
  Data.Hash[3]:= Data.Hash[3] + D;
  Data.Hash[4]:= Data.Hash[4] + E;
  FillChar(W,Sizeof(W),0);
  FillChar(Data.Buffer,Sizeof(Data.Buffer),0);
end;

//******************************************************************************
procedure SHA1Init(var Context: TSHA1Context);
begin
  Context.Hi:= 0; Context.Lo:= 0;
  Context.Index:= 0;
  FillChar(Context.Buffer,Sizeof(Context.Buffer),0);
  Context.Hash[0]:= $67452301;
  Context.Hash[1]:= $EFCDAB89;
  Context.Hash[2]:= $98BADCFE;
  Context.Hash[3]:= $10325476;
  Context.Hash[4]:= $C3D2E1F0;
end;

//******************************************************************************
procedure SHA1UpdateLen(var Context: TSHA1Context; Len: integer);
var
  i, k: integer;
begin
  for k:= 0 to 7 do
  begin
    i:= Context.Lo;
    Inc(Context.Lo,Len);
    if Context.Lo< i then
      Inc(Context.Hi);
  end;
end;

//******************************************************************************
procedure SHA1Update(var Context: TSHA1Context; Buffer: pointer; Len: integer);
type
  PByte= ^Byte;
begin
  SHA1UpdateLen(Context,Len);
  while Len> 0 do
  begin
    Context.Buffer[Context.Index]:= PByte(Buffer)^;
    Inc(PByte(Buffer));
    Inc(Context.Index);
    Dec(Len);
    if Context.Index= 64 then
    begin
      Context.Index:= 0;
      SHA1Compress(Context);
    end;
  end;
end;

//******************************************************************************
procedure SHA1Final(var Context: TSHA1Context; var Digest: TSHA1Digest);
type
  PDWord= ^DWord;
begin
  Context.Buffer[Context.Index]:= $80;
  if Context.Index>= 56 then
    SHA1Compress(Context);
  PDWord(@Context.Buffer[56])^:= RB(Context.Hi);
  PDWord(@Context.Buffer[60])^:= RB(Context.Lo);
  SHA1Compress(Context);
  Context.Hash[0]:= RB(Context.Hash[0]);
  Context.Hash[1]:= RB(Context.Hash[1]);
  Context.Hash[2]:= RB(Context.Hash[2]);
  Context.Hash[3]:= RB(Context.Hash[3]);
  Context.Hash[4]:= RB(Context.Hash[4]);
  Move(Context.Hash,Digest,Sizeof(Digest));
  FillChar(Context,Sizeof(Context),0);
end;


end.
BR

Helpinterchange
 
Old 07-30-2013, 16:43   #67 (permalink)
No Life Poster
 
..::SuB::..'s Avatar
 
Join Date: Aug 2008
Location: The Matrix :)
Age: 36
Posts: 654
Member: 833760
Status: Offline
Sonork: 100.1597150
Thanks Meter: 114
Im used this sha1.pas
Code:
{
    This file is part of the Free Pascal packages.
    Copyright (c) 2009 by the Free Pascal development team

    Implements a SHA-1 digest algorithm (RFC 3174)

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}

unit sha1;

{$mode objfpc}{$h+}

interface

type
  TSHA1Digest = array[0..19] of byte;

  TSHA1Context = record
    State: array[0..4] of cardinal;
    Buffer: array[0..63] of byte;
    BufCnt: PtrUInt;   { in current block, i.e. in range of 0..63 }
    Length: QWord;     { total count of bytes processed }
  end;

{ core }
procedure SHA1Init(var ctx: TSHA1Context);
procedure SHA1Update(var ctx: TSHA1Context; const Buf; BufLen: PtrUInt);
procedure SHA1Final(var ctx: TSHA1Context; var Digest: TSHA1Digest);

{ auxiliary }
function SHA1String(const S: string): TSHA1Digest;
function SHA1Buffer(const Buf; BufLen: PtrUInt): TSHA1Digest;
function SHA1File(const Filename: string; const Bufsize: PtrUInt = 1024): TSHA1Digest;

{ helpers }
function SHA1Print(const Digest: TSHA1Digest): string;
function SHA1Match(const Digest1, Digest2: TSHA1Digest): boolean;

implementation

// inverts the bytes of (Count div 4) cardinals from source to target.
procedure Invert(Source, Dest: Pointer; Count: PtrUInt);
var
  S: PByte;
  T: PCardinal;
  I: PtrUInt;
begin
  S := Source;
  T := Dest;
  for I := 1 to (Count div 4) do
  begin
    T^ := S[3] or (S[2] shl 8) or (S[1] shl 16) or (S[0] shl 24);
    Inc(S, 4);
    Inc(T);
  end;
end;

procedure SHA1Init(var ctx: TSHA1Context);
begin
  FillChar(ctx, sizeof(TSHA1Context), 0);
  ctx.State[0] := $67452301;
  ctx.State[1] := $efcdab89;
  ctx.State[2] := $98badcfe;
  ctx.State[3] := $10325476;
  ctx.State[4] := $c3d2e1f0;
end;

const
  K20 = $5A827999;
  K40 = $6ED9EBA1;
  K60 = $8F1BBCDC;
  K80 = $CA62C1D6;

procedure SHA1Transform(var ctx: TSHA1Context; Buf: Pointer);
var
  A, B, C, D, E, T: cardinal;
  Data: array[0..15] of cardinal;
  i: integer;
begin
  A := ctx.State[0];
  B := ctx.State[1];
  C := ctx.State[2];
  D := ctx.State[3];
  E := ctx.State[4];
  Invert(Buf, @Data, 64);
{$push}
{$r-,q-}
  i := 0;
  repeat
    T := (B and C) or (not B and D) + K20 + E;
    E := D;
    D := C;
    C := RorDWord(B, 2);
    B := A;
    A := T + roldword(A, 5) + Data[i and 15];
    Data[i and 15] := roldword(Data[i and 15] xor Data[(i + 2) and 15] xor
      Data[(i + 8) and 15] xor Data[(i + 13) and 15], 1);
    Inc(i);
  until i > 19;

  repeat
    T := (B xor C xor D) + K40 + E;
    E := D;
    D := C;
    C := rordword(B, 2);
    B := A;
    A := T + roldword(A, 5) + Data[i and 15];
    Data[i and 15] := roldword(Data[i and 15] xor Data[(i + 2) and 15] xor
      Data[(i + 8) and 15] xor Data[(i + 13) and 15], 1);
    Inc(i);
  until i > 39;

  repeat
    T := (B and C) or (B and D) or (C and D) + K60 + E;
    E := D;
    D := C;
    C := rordword(B, 2);
    B := A;
    A := T + roldword(A, 5) + Data[i and 15];
    Data[i and 15] := roldword(Data[i and 15] xor Data[(i + 2) and 15] xor
      Data[(i + 8) and 15] xor Data[(i + 13) and 15], 1);
    Inc(i);
  until i > 59;

  repeat
    T := (B xor C xor D) + K80 + E;
    E := D;
    D := C;
    C := rordword(B, 2);
    B := A;
    A := T + roldword(A, 5) + Data[i and 15];
    Data[i and 15] := roldword(Data[i and 15] xor Data[(i + 2) and 15] xor
      Data[(i + 8) and 15] xor Data[(i + 13) and 15], 1);
    Inc(i);
  until i > 79;

  Inc(ctx.State[0], A);
  Inc(ctx.State[1], B);
  Inc(ctx.State[2], C);
  Inc(ctx.State[3], D);
  Inc(ctx.State[4], E);
{$pop}
  Inc(ctx.Length, 64);
end;

procedure SHA1Update(var ctx: TSHA1Context; const Buf; BufLen: PtrUInt);
var
  Src: PByte;
  Num: PtrUInt;
begin
  if BufLen = 0 then
    Exit;

  Src := @Buf;
  Num := 0;

  // 1. Transform existing data in buffer
  if ctx.BufCnt > 0 then
  begin
    // 1.1 Try to fill buffer up to block size
    Num := 64 - ctx.BufCnt;
    if Num > BufLen then
      Num := BufLen;

    Move(Src^, ctx.Buffer[ctx.BufCnt], Num);
    Inc(ctx.BufCnt, Num);
    Inc(Src, Num);

    // 1.2 If buffer is filled, transform it
    if ctx.BufCnt = 64 then
    begin
      SHA1Transform(ctx, @ctx.Buffer);
      ctx.BufCnt := 0;
    end;
  end;

  // 2. Transform input data in 64-byte blocks
  Num := BufLen - Num;
  while Num >= 64 do
  begin
    SHA1Transform(ctx, Src);
    Inc(Src, 64);
    Dec(Num, 64);
  end;

  // 3. If there's less than 64 bytes left, add it to buffer
  if Num > 0 then
  begin
    ctx.BufCnt := Num;
    Move(Src^, ctx.Buffer, Num);
  end;
end;

const
  PADDING: array[0..63] of byte =
    ($80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    );

procedure SHA1Final(var ctx: TSHA1Context; var Digest: TSHA1Digest);
var
  Length: QWord;
  Pads: cardinal;
begin
  // 1. Compute length of the whole stream in bits
  Length := 8 * (ctx.Length + ctx.BufCnt);

  // 2. Append padding bits
  if ctx.BufCnt >= 56 then
    Pads := 120 - ctx.BufCnt
  else
    Pads := 56 - ctx.BufCnt;
  SHA1Update(ctx, PADDING, Pads);

  // 3. Append length of the stream (8 bytes)
  Length := NtoBE(Length);
  SHA1Update(ctx, Length, 8);

  // 4. Invert state to digest
  Invert(@ctx.State, @Digest, 20);
  FillChar(ctx, sizeof(TSHA1Context), 0);
end;

function SHA1String(const S: string): TSHA1Digest;
var
  Context: TSHA1Context;
begin
  SHA1Init(Context);
  SHA1Update(Context, PChar(S)^, length(S));
  SHA1Final(Context, Result);
end;

function SHA1Buffer(const Buf; BufLen: PtrUInt): TSHA1Digest;
var
  Context: TSHA1Context;
begin
  SHA1Init(Context);
  SHA1Update(Context, buf, buflen);
  SHA1Final(Context, Result);
end;

function SHA1File(const Filename: string; const Bufsize: PtrUInt): TSHA1Digest;
var
  F: file;
  Buf: PChar;
  Context: TSHA1Context;
  Count: cardinal;
  ofm: longint;
begin
  SHA1Init(Context);

  Assign(F, Filename);
  {$i-}
  ofm := FileMode;
  FileMode := 0;
  Reset(F, 1);
  {$i+}

  if IOResult = 0 then
  begin
    GetMem(Buf, BufSize);
    repeat
      BlockRead(F, Buf^, Bufsize, Count);
      if Count > 0 then
        SHA1Update(Context, Buf^, Count);
    until Count < BufSize;
    FreeMem(Buf, BufSize);
    Close(F);
  end;

  SHA1Final(Context, Result);
  FileMode := ofm;
end;

const
  HexTbl: array[0..15] of char = '0123456789abcdef';     // lowercase

function SHA1Print(const Digest: TSHA1Digest): string;
var
  I: integer;
  P: PChar;
begin
  SetLength(Result, 40);
  P := Pointer(Result);
  for I := 0 to 19 do
  begin
    P[0] := HexTbl[(Digest[i] shr 4) and 15];
    P[1] := HexTbl[Digest[i] and 15];
    Inc(P, 2);
  end;
end;

function SHA1Match(const Digest1, Digest2: TSHA1Digest): boolean;
var
  A: array[0..4] of cardinal absolute Digest1;
  B: array[0..4] of cardinal absolute Digest2;
begin
  Result := (A[0] = B[0]) and (A[1] = B[1]) and (A[2] = B[2]) and
    (A[3] = B[3]) and (A[4] = B[4]);
end;

end.
And only modification on ooxtcoo's code is:
Code:
SHA1Update(ctx, @VAL, 1);
to
Code:
SHA1Update(ctx, VAL, 1);
before remove the address pointer i got this error:
sl3_nck.pas(51,27) Error: Can't assign values to an address

Now works fine, i will testing more but its calculated the same codes as ooxtcoo's php script, so i hope its ok.

http://ooxtcoo.dyndns.org/sl3code.ph...00030705050302


хостинг картинок

EDIT: OK OK OK code level numbers wrong on screenshot, ive corrected already
 
Old 07-30-2013, 19:41   #68 (permalink)
Moderator
 
Join Date: May 1999
Location: Blagoevgrad, Bulgaria
Age: 52
Posts: 1,056
Member: 73
Status: Offline
Thanks Meter: 537
Donate money to this user
@oOXTCOo

Sysutils.pas is verry verry fat unit. Lot of code.

Hex to bin and bin to hex conversions can replace with BINTOHEX and HEXTOBIN from Classes.pas this will speedup code and will reduce dramaticaly.

(if copy/paste from classses to your unit as local funcs will reduce classes include)

Also why need to use StrtoInt from Sysutils.pas better use function VAL from system. In fact StrtoInt use VAL...

With this small modifications i think not need fat sysutils.pas



Regards: Victor
 
The Following 2 Users Say Thank You to Victor For This Useful Post:
Old 07-30-2013, 20:08   #69 (permalink)
Freak Poster
 
Join Date: Dec 2011
Location: Brazil
Posts: 194
Member: 1705083
Status: Offline
Thanks Meter: 25
I'm newbie, how to get Master SP Code?
 
Old 07-30-2013, 20:20   #70 (permalink)
Product Manager
 
TestBox2's Avatar
 
Join Date: May 2008
Location: Ukraine
Age: 45
Posts: 3,234
Member: 772096
Status: Offline
Sonork: 100.69222
Thanks Meter: 8,277
Quote:
Originally Posted by Victor View Post
@oOXTCOo

Sysutils.pas is verry verry fat unit. Lot of code.

Hex to bin and bin to hex conversions can replace with BINTOHEX and HEXTOBIN from Classes.pas this will speedup code and will reduce dramaticaly.

(if copy/paste from classses to your unit as local funcs will reduce classes include)

Also why need to use StrtoInt from Sysutils.pas better use function VAL from system. In fact StrtoInt use VAL...

With this small modifications i think not need fat sysutils.pas



Regards: Victor


Function hex2chr(data: string) : string;
begin // 'AABBCCDD'-> #$AA#$BB#$CC#$DD
SetLength(result,length(data) div 2);
HexToBin(@data[1],@result[1],length(data));
end;


Function chr2hex(data: string) : string;
begin // #$AA#$BB#$CC#$DD -> 'AABBCCDD'
SetLength(result,length(data)*2);
BinToHex(@data[1],@result[1],length(data));
end;
 
The Following User Says Thank You to TestBox2 For This Useful Post:
Old 07-30-2013, 20:39   #71 (permalink)
No Life Poster
 
oOXTCOo's Avatar
 
Join Date: Dec 2000
Location: J.A.U - Just Another Unlocker
Age: 43
Posts: 3,498
Member: 2878
Status: Offline
Thanks Meter: 9,123
we dont programm a microcontroller.. so who cares about size?
when i reversed it, i just whanted it to get it working...

in my project sysutis are havy used.. so it dont make any difference in size if i already included it in another unit.

my project have so mutch units now, i thinks about 30 units or so

Last edited by oOXTCOo; 07-30-2013 at 20:46.
 
The Following 2 Users Say Thank You to oOXTCOo For This Useful Post:
Old 07-30-2013, 20:56   #72 (permalink)
No Life Poster
 
oOXTCOo's Avatar
 
Join Date: Dec 2000
Location: J.A.U - Just Another Unlocker
Age: 43
Posts: 3,498
Member: 2878
Status: Offline
Thanks Meter: 9,123
Quote:
Originally Posted by helpinterchange View Post
Hi oOXTCOo

I made some corrections in your code, for use it mor easy.

Code:
unit SL3_NCK;

interface

uses
    Windows, SysUtils, SHA1;

    function GetTokenCount(Cadena,Separador:string):integer;
    function GetToken(sCadena, sSeparador: String; iToken: Integer): String;
    function SL3_CALC_NCK(TARGET_HASH, MASTER_SP_CODE : string):string;

implementation

function StrToHex(s: string): string;
var
    i: Integer;
begin
    Result:='';
    If length(s)>0 then
      for i:=1 to length(s) do
        result:=result+IntToHex(Ord(s[i]),2);
end;


function HexToStr(s: string): string;
var
    i: Integer;
begin
    Result:=''; i:=1;
    while i<Length(s) do
    begin
        Result:=Result+Chr(StrToIntDef('$'+Copy(s,i,2),0));
        Inc(i,2);
    end;
end;


function HexToInt(HexNum: string): LongInt;
begin
   Result:=StrToInt('$' + HexNum) ;
end;

function My_SHA1(input : string) : string;
var
  i, VAL : integer;
  ctx    : TSHA1Context;
  digest : TSHA1Digest;
begin
  result:='';
  SHA1Init(ctx);
  for i:=1 to length(input) do
  if i mod 2 = 1 then
  begin
      VAL:=hextoint(input[i] + input[i+1]);
      SHA1Update(ctx, @VAL, 1);
  end;
  Sha1Final(ctx,digest);
  for i:=0 to sizeof(digest)-1 do result := result + strtohex(Chr(Ord(digest[i])));
end;


function GetTokenCount(Cadena,Separador:string):integer;
var
    Posicion:integer;
begin
    Posicion := Pos(Separador,Cadena);
    Result := 1;

    if Cadena <> '' then begin
        if Posicion <> 0 then
            while Posicion <> 0 do begin
                Delete(Cadena,1,Posicion);
                Posicion := Pos(Separador,Cadena);
                Inc (Result);
            end;
        end
        else
            Result := 0;
end;


function GetToken(sCadena, sSeparador: String; iToken: Integer): String;
var
    iPosicion: Integer;
begin
    while iToken > 1 do begin
        Delete(sCadena, 1, Pos(sSeparador,sCadena) + Length(sSeparador) - 1);
        Dec(iToken);
    end;
    iPosicion := Pos(sSeparador, sCadena);
    if iPosicion = 0 then
        Result:= sCadena
    else
        Result:= Copy(sCadena, 1, iPosicion - 1);
end;


function SimlFeistel(sh, precode:string) : string;
var
    i,prenck : integer;
    nck,nck2: string;
begin
          for i:=1 to length(precode) do
          if i mod 2 = 1 then
          begin
              nck:=sh[i]+sh[i+1];
              nck2:=precode[i]+precode[i+1];

              prenck:=( (hextoint(nck)+hextoint(nck2)) mod 10);
              result:=result+'0'+inttostr(prenck);
          end;
end;

function SL3_CALC_NCK(TARGET_HASH, MASTER_SP_CODE : string):string;
var
    Data, precode, levelhash : string;
    sh, precode7, precode8, final : string;
    i, j, magic : integer;
    TCod :String;
begin
    MASTER_SP_CODE:='000000'+Copy(MASTER_SP_CODE, 1, 24);

    for i:=1 to 7 do
    begin
        levelhash:=My_SHA1('0'+inttostr(i)+TARGET_HASH);
        precode8:=Copy(MASTER_SP_CODE, 0,16);
        precode7:=Copy(MASTER_SP_CODE, 17,30);

        for magic:=0 to 1 do
        begin
            sh:=My_SHA1('0'+inttostr(magic)+Copy(levelhash, 0,32)+precode8);
            precode:='';
            Precode:=SimlFeistel(sh, precode7);
            precode7:=precode;

            sh:=My_SHA1('0'+inttostr(magic)+Copy(levelhash, 0,32)+precode);
            precode:='';
            Precode:=SimlFeistel(sh, precode8);
            precode8:=precode;
        end;

        data:='';
        final:=precode8+precode7;
        for j:=1 to length(final) do if j mod 2 = 1 then data:=data+inttostr(hextoint(final[j]+final[j+1]));
        //ADDLine('#pw+'+data+'+'+inttostr(i)+'#');
        data := '#pw+' + data + '+' + inttostr(i)+'#';
        if (i = 1)
         then  Result := (data)
         else Result := Result+','+(data);
    end;
end;

end.
For use the tokens see this code

Code:
procedure TFNokiaSL3Hash2NCK.btnCalcClick(Sender: TObject);
var
 TCods :String;
 n:byte;
begin
 Self.Cursor := crHourGlass;
 MLogs.Lines.Clear;
 MLogs.Lines.Add('TARGET_HASH   : ');
 MLogs.Lines.Add('   '+ LabeledEdit1.Text);
 MLogs.Lines.Add('MASTER_SP_CODE: ');
 MLogs.Lines.Add('   '+ LabeledEdit2.Text);
 MLogs.Lines.Add('   ');

 TCods := SL3_CALC_NCK (LabeledEdit1.Text, LabeledEdit2.Text);
 for n := 1 to GetTokenCount(TCods,',')
   do begin
       MLogs.Lines.Add(GetToken(TCods,',',n)) ;
     end;
   Self.Cursor := crDefault;
end;
I Build my own demo with the options to check online from your site an Calc offline






Big thanks oOXTCOo

BR

Helpinterchange

i included nck1, nck2, nck3 ...... variables in function, so you can directly access it outside of the function in your main unit...

you just need to declare same variable names and you have the results from the calculation in nck1, nck2, nck3...

you dont need that extra mutch of code...

i think its more easy way...
 
The Following User Says Thank You to oOXTCOo For This Useful Post:
Old 07-30-2013, 21:02   #73 (permalink)
Moderator
 
Join Date: May 1999
Location: Blagoevgrad, Bulgaria
Age: 52
Posts: 1,056
Member: 73
Status: Offline
Thanks Meter: 537
Donate money to this user
Quote:
Originally Posted by oOXTCOo View Post
we dont programm a microcontroller.. so who cares about size?
when i reversed it, i just whanted it to get it working...

in my project sysutis are havy used.. so it dont make any difference in size if i already included it in another unit.

my project have so mutch units now, i thinks about 30 units or so
OK how prefer ... small fast code or sysutils...

This is aditional protection to soft. When are unpacked hacker will go deep in
....
call ebp+XXXX
.... etc
 
The Following User Says Thank You to Victor For This Useful Post:
Old 07-30-2013, 21:20   #74 (permalink)
No Life Poster
 
oOXTCOo's Avatar
 
Join Date: Dec 2000
Location: J.A.U - Just Another Unlocker
Age: 43
Posts: 3,498
Member: 2878
Status: Offline
Thanks Meter: 9,123
i had it now 2 years in jau standalone, only protected by themida macros.
(but i dont know if maybe someone got it or not, but for shure, there was more easy targets to get it from)

the code is already more then 2 years old, but in future projects, i will use your advices.
 
Old 07-30-2013, 21:54   #75 (permalink)
No Life Poster
 
Join Date: Oct 2010
Posts: 723
Member: 1422878
Status: Offline
Thanks Meter: 164
Others Changes

Code:
unit SL3_NCK;

interface

uses
    Windows, SysUtils, j2k_Sha1;

    function GetTokenCount(Cadena,Separador:string):integer;
    function GetToken(sCadena, sSeparador: String; iToken: Integer): String;
    function SL3_CALC_NCK(TARGET_HASH, MASTER_SP_CODE : string):string;

implementation

function HexToStr(s: string): string;
var
    i: Integer;
begin
    Result:=''; i:=1;

    while i< S.Length do
    begin
        Result:=Result+ Chr(StrToIntDef('$'+Copy(s,i,2),0) );
        Inc(i,2);
    end;
end;


function HexToInt(HexNum: string): LongInt;
begin
   Result:= Integer.Parse('$' + HexNum);
end;


function My_SHA1(input : string) : string;
var
  i, VAL : integer;
  ctx    : TSHA1Context;
  digest : TSHA1Digest;
begin
  result:='';
  SHA1Init(ctx);
  for i:=1 to input.Length do
  if i mod 2 = 1 then
  begin
      VAL:= HexToInt(input[i] + input[i+1]);
      SHA1Update(ctx, @VAL, 1);
  end;
  Sha1Final(ctx,digest);

  for i:=0 to sizeof(digest)-1 do
   result := result + Ord(digest[i]).ToHexString;

end;


function GetTokenCount(Cadena,Separador:string):integer;
var
    Posicion:integer;
begin
    Posicion := Pos(Separador,Cadena);
    Result := 1;

    if Cadena <> '' then begin
        if Posicion <> 0 then
            while Posicion <> 0 do begin
                Delete(Cadena,1,Posicion);
                Posicion := Pos(Separador,Cadena);
                Inc (Result);
            end;
        end
        else
            Result := 0;
end;


function GetToken(sCadena, sSeparador: String; iToken: Integer): String;
var
    iPosicion: Integer;
begin
    while iToken > 1 do begin
        Delete(sCadena, 1, Pos(sSeparador,sCadena) + Length(sSeparador) - 1);
        Dec(iToken);
    end;
    iPosicion := Pos(sSeparador, sCadena);
    if iPosicion = 0 then
        Result:= sCadena
    else
        Result:= Copy(sCadena, 1, iPosicion - 1);
end;


function SimlFeistel(sh, precode:string) : string;
var
    i,prenck : integer;
    nck,nck2: string;
begin
          for i:=1 to precode.Length do
          if i mod 2 = 1 then
          begin
              nck:=sh[i]+sh[i+1];
              nck2:=precode[i]+precode[i+1];
              prenck:= ( (HexToInt(nck)+ HexToInt(nck2)) mod 10);
              result:=result+'0'+ prenck.ToString;
          end;
end;

function SL3_CALC_NCK(TARGET_HASH, MASTER_SP_CODE : string):string;
var
    Data, precode, levelhash : string;
    sh, precode7, precode8, final : string;
    i, j, magic : integer;
    TCod :String;
begin
    MASTER_SP_CODE:='000000'+Copy(MASTER_SP_CODE, 1, 24);

    for i:=1 to 7 do
    begin
        levelhash:=My_SHA1('0'+ i.ToString +TARGET_HASH);

        precode8:=Copy(MASTER_SP_CODE, 0,16);
        precode7:=Copy(MASTER_SP_CODE, 17,30);

        for magic:=0 to 1 do
        begin
            sh:=My_SHA1('0'+ magic.ToString + Copy(levelhash, 0,32) + precode8);
            precode:='';
            Precode:=SimlFeistel(sh, precode7);
            precode7:=precode;

            sh:=My_SHA1('0'+ magic.ToString +Copy(levelhash, 0,32)+precode);
            precode:='';
            Precode:=SimlFeistel(sh, precode8);
            precode8:=precode;
        end;

        data:='';
        final:=precode8+precode7;
        for j:=1 to final.Length do
         if j mod 2 = 1 then data:=data+ (hextoint(final[j]+final[j+1])).ToString ;

        //ADDLine('#pw+'+data+'+'+inttostr(i)+'#');

        data := '#pw+' + data + '+' + i.ToString +'#';
        if (i = 1)
         then  Result := (data)
         else Result := Result+','+(data);
    end;
end;

end.

Last edited by helpinterchange; 07-30-2013 at 22:03. Reason: Changes in code
 
The Following User Says Thank You to helpinterchange For This Useful Post:
Closed Thread

Bookmarks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 



All times are GMT +1. The time now is 03:32.



Powered by Searchlight © 2024 Axivo Inc.
vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
- GSM Hosting Ltd. - 1999-2023 -
Page generated in 0.48857 seconds with 10 queries

SEO by vBSEO