sys(2007, "some text data") Java usage problems 
Author Message
 sys(2007, "some text data") Java usage problems

Hi!

    I am working in a Java project that has to query some data from an
application made in Visual Fox pro (*.dbf files). I am using JDBC with
SUN's bridge driver. The problem I have is that there is a table
containing a list of users and passwords and passwords are stored as:

SYS(2007, "some real password").

Till now everything is ok, but the problem is that I have to verify a
password and I see two possibilities:
1) (the most preferred, because I don't want to transfer plain-text
passwords over the network) is to compute from java (on the client
side) the value of SYS(2007, "password") but the problem is that I
don't know the checksum algorithm used by the SYS function to make a
Java implementation. I have searched for the algorithm and all the
things I found till now (basically it was a C implementation) didn't
work.

2) The next to do would be something like:

PreparedStatement stmt = conn.prepareStatement("select sys(?,?)
pass_column, name from employees where name='Supervisor'");

stmt.setInt(1, 2007);

stmt.setString(2, "'crocodille'");
ResultSet rs = stmt.executeQuery();
while(rs.next()){
        System.out.println("->"+rs.getString("pass_column"));
        System.out.println("->"+rs.getString("name"));

Quote:
}

I prepare a statement that also calls the SYS function. The result for
pass_column is 0 (obvious wrong).

At this moment I am out of ideas :(.

Thanks for help,
  cristi



Mon, 05 Sep 2005 21:11:23 GMT  
 sys(2007, "some text data") Java usage problems
cristi,
I got this from an old MS TechNet CD - it's no longer on the MS Knowledge Base website:

PSS ID Number: Q101289
Article last modified on 06-27-1995

2.50 2.50a 2.50b | 2.00 2.50 2.50a 2.50b | 2.50b

WINDOWS          | MS-DOS                | MACINTOSH

--------------------------------------------------------------------
The information in this article applies to:

 - Microsoft FoxPro for Windows, versions 2.5, 2.5a, and 2.5b
 - Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a, and 2.5b
 - Microsoft FoxPro for Macintosh, version 2.5b
--------------------------------------------------------------------

The SYS(2007) function returns the checksum value of the character
expression <expC>. The correct syntax is SYS(2007,<expC>). A checksum
can be used to test the validity of data or to compare two character
expressions.

NOTE: Checksum is a "byte-oriented CRC-16" algorithm. The exact logic
was last published in the February 1986 edition of "Dr. Dobbs
Journal."

Additional reference words: FoxMac FoxDos FoxWin 2.00 2.50 2.50a 2.50b
check sum
KBCategory: kbprg
KBSubcategory: FxprgGeneral
============================================================================
=
Copyright Microsoft Corporation 1995.

Rick


Quote:
> Hi!

>     I am working in a Java project that has to query some data from an
> application made in Visual Fox pro (*.dbf files). I am using JDBC with
> SUN's bridge driver. The problem I have is that there is a table
> containing a list of users and passwords and passwords are stored as:

> SYS(2007, "some real password").

> Till now everything is ok, but the problem is that I have to verify a
> password and I see two possibilities:
> 1) (the most preferred, because I don't want to transfer plain-text
> passwords over the network) is to compute from java (on the client
> side) the value of SYS(2007, "password") but the problem is that I
> don't know the checksum algorithm used by the SYS function to make a
> Java implementation. I have searched for the algorithm and all the
> things I found till now (basically it was a C implementation) didn't
> work.

> 2) The next to do would be something like:

> PreparedStatement stmt = conn.prepareStatement("select sys(?,?)
> pass_column, name from employees where name='Supervisor'");

> stmt.setInt(1, 2007);

> stmt.setString(2, "'crocodille'");
> ResultSet rs = stmt.executeQuery();
> while(rs.next()){
>         System.out.println("->"+rs.getString("pass_column"));
>         System.out.println("->"+rs.getString("name"));
> }

> I prepare a statement that also calls the SYS function. The result for
> pass_column is 0 (obvious wrong).

> At this moment I am out of ideas :(.

> Thanks for help,
>   cristi



Mon, 05 Sep 2005 22:39:29 GMT  
 sys(2007, "some text data") Java usage problems
It's a 16-bit value if that helps.
-Anders


Quote:
> Hi!

>     I am working in a Java project that has to query some data from an
> application made in Visual Fox pro (*.dbf files). I am using JDBC with
> SUN's bridge driver. The problem I have is that there is a table
> containing a list of users and passwords and passwords are stored as:

> SYS(2007, "some real password").

> Till now everything is ok, but the problem is that I have to verify a
> password and I see two possibilities:
> 1) (the most preferred, because I don't want to transfer plain-text
> passwords over the network) is to compute from java (on the client
> side) the value of SYS(2007, "password") but the problem is that I
> don't know the checksum algorithm used by the SYS function to make a
> Java implementation. I have searched for the algorithm and all the
> things I found till now (basically it was a C implementation) didn't
> work.

> 2) The next to do would be something like:

> PreparedStatement stmt = conn.prepareStatement("select sys(?,?)
> pass_column, name from employees where name='Supervisor'");

> stmt.setInt(1, 2007);

> stmt.setString(2, "'crocodille'");
> ResultSet rs = stmt.executeQuery();
> while(rs.next()){
>         System.out.println("->"+rs.getString("pass_column"));
>         System.out.println("->"+rs.getString("name"));
> }

> I prepare a statement that also calls the SYS function. The result for
> pass_column is 0 (obvious wrong).

> At this moment I am out of ideas :(.

> Thanks for help,
>   cristi



Mon, 05 Sep 2005 22:43:26 GMT  
 sys(2007, "some text data") Java usage problems
Hi,

This could be the one you are looking for. It's from
http://www.umich.edu/~archive/msdos/info/dr.dobbs/ddj8602.arc. The site
contains all the source files from the journal between 1986 and 1990. The
ones since 1991 are available from the magazine site itself.

      { file crctime.pas, 85/9/18/tfr (from 9/15, 7/13, 6/27-26,
                          showtime.pas 3/23, 1/4, 84/12/25
                          and showkeys 12/12-11, 11/17
                          and strinkey.pas, 11/17) }
      { compute crc execution times }

      { Copyright (c) 1984, 1985, T.F. Ritter; All Rights Reserved }

      { Please feel free to copy and use the CRC routines, but . . . }
      {    do include the name of the CRC programmer when you do. }
      { The CRC programmer is Terry Ritter. }

      { AIMS: }
      { 1. Display a number of different CRC-CCITT implementations. }
      { 2. Verify identical results. }
      { 3. Collect and display time statistics on each routine. }

      PROGRAM showtime;

      { minimum overhead for speed tests }
      {$R-}  { Range Checks OFF }
      {$C-}  { Ctrl-C Checking OFF }

      PROCEDURE ownership;
         BEGIN
         WRITE( con,
^M^J, 'CRCTIME, 85/9/18',
^M^J, 'Execution times for various CRC implementations.',
^M^J, 'Copyright (c) 1985, T.F. Ritter; All Rights Reserved.',
^M^J     );
         END;

      TYPE
         regs = RECORD
                ax,bx,cx,dx,bp,si,di,ds,es,flags: INTEGER;
                END;

      PROCEDURE bdosch( ch: CHAR );
         { direct console output through MSDOS }
         { allows Ctrl-P printer toggle }
         { also skips Ctrl-C break test }
         VAR
            r: regs;
         BEGIN
         r.ax := $0200;
         r.dx := ORD(ch);
         MsDos( r );
         END;

      { start of time operations }

      TYPE
         timearty = ARRAY[0..3] of INTEGER; {originally had yr, dy}

      PROCEDURE readhms( VAR dt: timearty );
         { Hi(dt[2]) = hrs (0 - 23), Lo(dt[2]) = mins (0 - 59) }
         { Hi(dt[3]) = secs (0 - 59), Lo(dt[3]) = msecs (0 - 99) }
         VAR
            r: regs;
         BEGIN
         r.ax := $2c00;
         MsDos( r );
         dt[2] := r.cx;
         dt[3] := r.dx;
         END; { rddtti }

      FUNCTION timetorealsecs( x: timearty ): REAL;
         BEGIN
         timetorealsecs := (Hi(x[2]) * 3600.0)  +  (Lo(x[2]) * 60.0)  +
                            Hi(x[3])  +  (Lo(x[3]) / 100.0);
         END;

      FUNCTION timedif( a, b: timearty ): REAL;
         BEGIN
         timedif := timetorealsecs( b ) - timetorealsecs( a );
         END;

      { start of CRC stuff }
      { byte crc in Turbo Pascal }
      { for MSDOS }

      { METHOD 1:  Pascal Bit-By-Bit }
      { bit manipulation in a high-level-language }
      { simulation of "longhand" division }
      { mostly for verification of other methods }

      PROCEDURE crcittb( VAR a: INTEGER; databit: BOOLEAN);
         { single bit computation; simulate polydiv hardware }
         { other Pascals can replace "a SHL 1" with "a + a" }
         BEGIN
         IF databit = (a < 0) THEN
            a := a Shl 1
         ELSE
            a := (a Shl 1) XOR $1021;  { CRC-CCITT }
         END; { crcittb }

      PROCEDURE crcittby( VAR aa: INTEGER; d: INTEGER );
         { whole byte computation }
         VAR
            i: INTEGER;
         BEGIN
         d := d Shl 7;
         FOR i := 7 DOWNTO 0 DO
            BEGIN
            d := d Shl 1;
            crcittb( aa, (d < 0) );
            END;
         END; { crcittby }

      { METHOD 2: Pascal Fast Bit-By-Bit }
      { eliminates procedure-call overhead in the loop }
      { similar to most XMODEM crc implementations}

      PROCEDURE crcfbbb( VAR aa: INTEGER; d: INTEGER );
         { fast bit-by-bit whole byte computation }
         VAR
            i: INTEGER;
         BEGIN
         d := d Shl 7;
         FOR i := 7 DOWNTO 0 DO
            BEGIN
            d := d Shl 1;
            IF ((d  XOR aa) < 0) THEN
               aa := (aa Shl 1) XOR $1021
            ELSE
               aa := aa Shl 1;
            END;
         END; { crcfbbb }

      { METHOD 3: Pascal Byte }
      { process the data byte without loops }
      { transportable within Turbo Pascal, and fairly fast }
      { may be slower in Pascals without bit-shifting operations }

      PROCEDURE crcitta( VAR dx: INTEGER; data: INTEGER);
         { dx := crcTransform( dx; data ) }
         { polynomial = $11021 }

         { FOR OTHER PASCALS: }
         {      Generate a Swap function "swap( x: INTEGER ): INTEGER" }
         { probably "swap := (x * 256) + (x DIV 256) would work" }
         { Lo(x) = x AND $00ff = x AND 255 }
         { x Shr 4 = x DIV 16 }
         { x Shl 4 = x * 16 }
         { x Shl 5 = x * 32 }

         BEGIN { crcitta }

         dx := Swap( dx ) XOR data;

         dx := dx XOR ( Lo(dx) Shr 4 );

         dx := dx XOR (Swap(Lo(dx)) Shl 4) XOR (Lo(dx) Shl 5);

         END; { crcitta }

      { METHOD 4: Pascal Table }
      { pull changes from table, indexed by composite value }
      { still faster, but requires the table, and filling the table }
      { may be even faster, relatively, in another Pascal }
      { a slower routine is fine to fill the table }

      VAR
         crctab:  ARRAY[0..255] of INTEGER;

      PROCEDURE crctablu( VAR crcreg: INTEGER; data: INTEGER);
         BEGIN
         crcreg := Swap(crcreg) XOR data;
         crcreg := (crcreg AND $ff00) XOR crctab[ Lo(crcreg) ];
         END;

      PROCEDURE initctab;
         { use method 3 to init the table }
         VAR
            i: INTEGER;
         BEGIN
         FOR i := 0 TO 255 DO
            BEGIN
            crctab[i] := 0;
            crcitta( crctab[i], i );
            END;
         END; {initctab}

      { METHOD 5: Machine Code Byte }
      { method 3 in "Inline" machine code (MSDOS) }
      { typically hidden away in an "Include" file }
      { other Pascals may need to modify the stack interface }

      PROCEDURE mcrcitt1( VAR dx: INTEGER; data: INTEGER );
         { a := crcTransform( dx; data ) }
         { for MSDOS }
         { polynomial = $11021 }

         BEGIN { mcrcitt1 }
         INLINE (
                   $c4/$7e/<dx/   {  es:di := [bp +"dx"]   }
                   $26/$8b/$05/   {  ax := [es:di]         }

         { dx := SWAP(dx) XOR data; }
                   $86/$e0/       {  ah <=> al             }
                   $33/$46/<data/ {  ax := ax XOR [bp + "data"] }
                   $89/$c2/       {  dx := ax              }

         { dx := dx XOR ( LO(dx) SHR 4 ); }
                   $d0/$e8/       {  al := al SHR 1        }
                   $d0/$e8/       {  al := al SHR 1        }
                   $d0/$e8/       {  al := al SHR 1        }
                   $d0/$e8/       {  al := al SHR 1        }
                   $32/$d0/       {  dl := dl XOR al       }

         { dx := dx XOR ( (SWAP( LO(dx) ) SHL 4 ); }
                   $88/$d4/       {  ah := dl              }
                   $d0/$e4/       {  ah := ah SHL 1        }
                   $d0/$e4/       {  ah := ah SHL 1        }
                   $d0/$e4/       {  ah := ah SHL 1        }
                   $d0/$e4/       {  ah := ah SHL 1        }
                   $32/$f4/       {  dh := dh XOR ah       }

         { dx := dx XOR ( ( LO(dx) ) SHL 5 ); }
                   $88/$d0/       {  al := dl              }
                   $b4/$00/       {  ah := 0               }
                   $d1/$e0/       {  ax := ax SHL 1        }
                   $d1/$e0/       {  ax := ax SHL 1        }
                   $d1/$e0/       {  ax := ax SHL 1        }
                   $d1/$e0/       {  ax := ax SHL 1        }
                   $d1/$e0/       {  ax := ax SHL 1        }
                   $33/$d0/       {  dx := dx XOR ax       }

                   $26/$89/$15    {  es:[di] := dx         } );

         END; { mcrcitt1 }

      { METHOD 6: Machine Code Table }
      { here the stack parameter interface becomes significant }
      { note the exchange notation "x :=: y" in the comments }

      PROCEDURE mcrcitt3( VAR dx: INTEGER; data: INTEGER );
         { a := crcTransform( dx; data ) }
         { for MSDOS }
         { polynomial = $11021 }

         BEGIN { mcrcitt3 }
         INLINE (
                   $c4/$7e/<dx/   {  es:di := [bp +"dx"]   }
                   $26/$8b/$15/   {  dx := [es:di]         }

         { dx := Swap(dx) XOR data; }
                   $86/$d6/       {  dh :=: dl             }
                   $33/$56/<data/ {  dx := dx XOR [bp + "data"] }

         { bx := Lo(dx) SHL 1;  dl := 0; }
                   $31/$db/       {  bx := bx XOR bx       }
                   $86/$d3/       {  bl :=: dl             }
                   $d1/$e3/       {  bx := bx SHL 1        }

         { dx := dx XOR crctab[ bx ]; }
                   $33/$97/>crctab/  {  dx := dx XOR [bx + "crctab"] }

                   $26/$89/$15    {  [es:di] := dx         } );

         END; { mcrcitt3 }

      { start of validation testing }

      PROCEDURE fultest( beg: INTEGER );
         CONST
            maxpass = 5;
         TYPE
            st40 = STRING[40];
            passtype = ARRAY[ 1..maxpass ] of INTEGER;
         VAR
            adi, pass: INTEGER;
            adr, adt: passtype;

         PROCEDURE overall( VAR a: passtype; t: INTEGER );
            VAR
               x, en, loc: INTEGER;
               data: BYTE;
            BEGIN
            FOR pass := 1 to maxpass DO
               BEGIN
               x := adi;
                  CASE pass OF
                  1: en := beg;
                  2: en := beg + 1;
                  3: en := beg + 127;
                  4: en := beg + 511;
                  5: en := beg + 81;
                  END;
               FOR loc := beg TO en DO
                  BEGIN
                  { a source of data "random" enough for our
...

read more »



Tue, 06 Sep 2005 03:00:06 GMT  
 sys(2007, "some text data") Java usage problems
Christof,
Gee, I'd of thought you'd have converted this to native VFP code already. :-) VFP to Java might be
easier to pull off than Pascal to Java.

I'll see if my "ancient" Pascal knowledge can do a translation.

Rick


Quote:
> Hi,

> This could be the one you are looking for. It's from
> http://www.umich.edu/~archive/msdos/info/dr.dobbs/ddj8602.arc. The site
> contains all the source files from the journal between 1986 and 1990. The
> ones since 1991 are available from the magazine site itself.

>       { file crctime.pas, 85/9/18/tfr (from 9/15, 7/13, 6/27-26,
>                           showtime.pas 3/23, 1/4, 84/12/25
>                           and showkeys 12/12-11, 11/17
>                           and strinkey.pas, 11/17) }
>       { compute crc execution times }

>       { Copyright (c) 1984, 1985, T.F. Ritter; All Rights Reserved }

>       { Please feel free to copy and use the CRC routines, but . . . }
>       {    do include the name of the CRC programmer when you do. }
>       { The CRC programmer is Terry Ritter. }

>       { AIMS: }
>       { 1. Display a number of different CRC-CCITT implementations. }
>       { 2. Verify identical results. }
>       { 3. Collect and display time statistics on each routine. }

>       PROGRAM showtime;

>       { minimum overhead for speed tests }
>       {$R-}  { Range Checks OFF }
>       {$C-}  { Ctrl-C Checking OFF }

>       PROCEDURE ownership;
>          BEGIN
>          WRITE( con,
> ^M^J, 'CRCTIME, 85/9/18',
> ^M^J, 'Execution times for various CRC implementations.',
> ^M^J, 'Copyright (c) 1985, T.F. Ritter; All Rights Reserved.',
> ^M^J     );
>          END;

>       TYPE
>          regs = RECORD
>                 ax,bx,cx,dx,bp,si,di,ds,es,flags: INTEGER;
>                 END;

>       PROCEDURE bdosch( ch: CHAR );
>          { direct console output through MSDOS }
>          { allows Ctrl-P printer toggle }
>          { also skips Ctrl-C break test }
>          VAR
>             r: regs;
>          BEGIN
>          r.ax := $0200;
>          r.dx := ORD(ch);
>          MsDos( r );
>          END;

>       { start of time operations }

>       TYPE
>          timearty = ARRAY[0..3] of INTEGER; {originally had yr, dy}

>       PROCEDURE readhms( VAR dt: timearty );
>          { Hi(dt[2]) = hrs (0 - 23), Lo(dt[2]) = mins (0 - 59) }
>          { Hi(dt[3]) = secs (0 - 59), Lo(dt[3]) = msecs (0 - 99) }
>          VAR
>             r: regs;
>          BEGIN
>          r.ax := $2c00;
>          MsDos( r );
>          dt[2] := r.cx;
>          dt[3] := r.dx;
>          END; { rddtti }

>       FUNCTION timetorealsecs( x: timearty ): REAL;
>          BEGIN
>          timetorealsecs := (Hi(x[2]) * 3600.0)  +  (Lo(x[2]) * 60.0)  +
>                             Hi(x[3])  +  (Lo(x[3]) / 100.0);
>          END;

>       FUNCTION timedif( a, b: timearty ): REAL;
>          BEGIN
>          timedif := timetorealsecs( b ) - timetorealsecs( a );
>          END;

>       { start of CRC stuff }
>       { byte crc in Turbo Pascal }
>       { for MSDOS }

>       { METHOD 1:  Pascal Bit-By-Bit }
>       { bit manipulation in a high-level-language }
>       { simulation of "longhand" division }
>       { mostly for verification of other methods }

>       PROCEDURE crcittb( VAR a: INTEGER; databit: BOOLEAN);
>          { single bit computation; simulate polydiv hardware }
>          { other Pascals can replace "a SHL 1" with "a + a" }
>          BEGIN
>          IF databit = (a < 0) THEN
>             a := a Shl 1
>          ELSE
>             a := (a Shl 1) XOR $1021;  { CRC-CCITT }
>          END; { crcittb }

>       PROCEDURE crcittby( VAR aa: INTEGER; d: INTEGER );
>          { whole byte computation }
>          VAR
>             i: INTEGER;
>          BEGIN
>          d := d Shl 7;
>          FOR i := 7 DOWNTO 0 DO
>             BEGIN
>             d := d Shl 1;
>             crcittb( aa, (d < 0) );
>             END;
>          END; { crcittby }

>       { METHOD 2: Pascal Fast Bit-By-Bit }
>       { eliminates procedure-call overhead in the loop }
>       { similar to most XMODEM crc implementations}

>       PROCEDURE crcfbbb( VAR aa: INTEGER; d: INTEGER );
>          { fast bit-by-bit whole byte computation }
>          VAR
>             i: INTEGER;
>          BEGIN
>          d := d Shl 7;
>          FOR i := 7 DOWNTO 0 DO
>             BEGIN
>             d := d Shl 1;
>             IF ((d  XOR aa) < 0) THEN
>                aa := (aa Shl 1) XOR $1021
>             ELSE
>                aa := aa Shl 1;
>             END;
>          END; { crcfbbb }

>       { METHOD 3: Pascal Byte }
>       { process the data byte without loops }
>       { transportable within Turbo Pascal, and fairly fast }
>       { may be slower in Pascals without bit-shifting operations }

>       PROCEDURE crcitta( VAR dx: INTEGER; data: INTEGER);
>          { dx := crcTransform( dx; data ) }
>          { polynomial = $11021 }

>          { FOR OTHER PASCALS: }
>          {      Generate a Swap function "swap( x: INTEGER ): INTEGER" }
>          { probably "swap := (x * 256) + (x DIV 256) would work" }
>          { Lo(x) = x AND $00ff = x AND 255 }
>          { x Shr 4 = x DIV 16 }
>          { x Shl 4 = x * 16 }
>          { x Shl 5 = x * 32 }

>          BEGIN { crcitta }

>          dx := Swap( dx ) XOR data;

>          dx := dx XOR ( Lo(dx) Shr 4 );

>          dx := dx XOR (Swap(Lo(dx)) Shl 4) XOR (Lo(dx) Shl 5);

>          END; { crcitta }

>       { METHOD 4: Pascal Table }
>       { pull changes from table, indexed by composite value }
>       { still faster, but requires the table, and filling the table }
>       { may be even faster, relatively, in another Pascal }
>       { a slower routine is fine to fill the table }

>       VAR
>          crctab:  ARRAY[0..255] of INTEGER;

>       PROCEDURE crctablu( VAR crcreg: INTEGER; data: INTEGER);
>          BEGIN
>          crcreg := Swap(crcreg) XOR data;
>          crcreg := (crcreg AND $ff00) XOR crctab[ Lo(crcreg) ];
>          END;

>       PROCEDURE initctab;
>          { use method 3 to init the table }
>          VAR
>             i: INTEGER;
>          BEGIN
>          FOR i := 0 TO 255 DO
>             BEGIN
>             crctab[i] := 0;
>             crcitta( crctab[i], i );
>             END;
>          END; {initctab}

>       { METHOD 5: Machine Code Byte }
>       { method 3 in "Inline" machine code (MSDOS) }
>       { typically hidden away in an "Include" file }
>       { other Pascals may need to modify the stack interface }

>       PROCEDURE mcrcitt1( VAR dx: INTEGER; data: INTEGER );
>          { a := crcTransform( dx; data ) }
>          { for MSDOS }
>          { polynomial = $11021 }

>          BEGIN { mcrcitt1 }
>          INLINE (
>                    $c4/$7e/<dx/   {  es:di := [bp +"dx"]   }
>                    $26/$8b/$05/   {  ax := [es:di]         }

>          { dx := SWAP(dx) XOR data; }
>                    $86/$e0/       {  ah <=> al             }
>                    $33/$46/<data/ {  ax := ax XOR [bp + "data"] }
>                    $89/$c2/       {  dx := ax              }

>          { dx := dx XOR ( LO(dx) SHR 4 ); }
>                    $d0/$e8/       {  al := al SHR 1        }
>                    $d0/$e8/       {  al := al SHR 1        }
>                    $d0/$e8/       {  al := al SHR 1        }
>                    $d0/$e8/       {  al := al SHR 1        }
>                    $32/$d0/       {  dl := dl XOR al       }

>          { dx := dx XOR ( (SWAP( LO(dx) ) SHL 4 ); }
>                    $88/$d4/       {  ah := dl              }
>                    $d0/$e4/       {  ah := ah SHL 1        }
>                    $d0/$e4/       {  ah := ah SHL 1        }
>                    $d0/$e4/       {  ah := ah SHL 1        }
>                    $d0/$e4/       {  ah := ah SHL 1        }
>                    $32/$f4/       {  dh := dh XOR ah       }

>          { dx := dx XOR ( ( LO(dx) ) SHL 5 ); }
>                    $88/$d0/       {  al := dl              }
>                    $b4/$00/       {  ah := 0               }
>                    $d1/$e0/       {  ax := ax SHL 1        }
>                    $d1/$e0/       {  ax := ax SHL 1        }
>                    $d1/$e0/       {  ax := ax SHL 1        }
>                    $d1/$e0/       {  ax := ax SHL 1        }
>                    $d1/$e0/       {  ax := ax SHL 1        }
>                    $33/$d0/       {  dx := dx XOR ax       }

>                    $26/$89/$15    {  es:[di] := dx         } );

>          END; { mcrcitt1 }

>       { METHOD 6: Machine Code Table }
>       { here the stack parameter interface becomes significant }
>       { note the exchange notation "x :=: y" in the comments }

>       PROCEDURE mcrcitt3( VAR dx: INTEGER; data: INTEGER );
>          { a := crcTransform( dx; data ) }
>          { for MSDOS }
>          { polynomial = $11021 }

>          BEGIN { mcrcitt3 }
>          INLINE (
>                    $c4/$7e/<dx/   {  es:di := [bp +"dx"]   }
>                    $26/$8b/$15/   {  dx := [es:di]         }

>          { dx := Swap(dx) XOR data; }
>                    $86/$d6/       {  dh :=: dl             }
>                    $33/$56/<data/ {  dx := dx XOR [bp + "data"] }

>          { bx := Lo(dx) SHL 1;  dl := 0; }
>                    $31/$db/       {  bx := bx XOR bx       }
>                    $86/$d3/       {  bl :=: dl             }
>                    $d1/$e3/       {  bx := bx SHL 1        }

>          { dx := dx XOR crctab[ bx ]; }
>                    $33/$97/>crctab/  {  dx := dx XOR [bx + "crctab"] }

>                    $26/$89/$15    {  [es:di] := dx         } );

>          END; { mcrcitt3 }

>       { start of validation testing }

...

read more »



Tue, 06 Sep 2005 06:00:58 GMT  
 sys(2007, "some text data") Java usage problems
Actually, I dug up some old FPW code I'd saved off and forgotten. While it looks different, it does
give the "right" results. If you call the program with -1 as the StartVal, and 16 as the BitLen,
then it seems to give the same results as sys(2007). i.e.
?sys(2007,"Now is the time for all good men")
?str(bobcrc(-1,"Now is the time for all good men","16"))

Both return "33312" (I tried a bunch of other stings just to test it!)

I know it could be optimized using some VFP specific techniques, but why mess with code that works!

Rick

* Program....: BOBCRC.PRG
* Version....: 1.0
* Author.....: Bob Herguth, Based upon powerbasic Code by Coridon Henshaw
* Date.......: June 9, 1997
* Compiler...: FoxPro 2.6a
* Abstract...: 16 and 32 bit CRC calaculator routine for data blocks.
*       lcBlockTxt: The text block to calculate a CRC for.
*    lcBitLen: A text value ("16" or "32")indicating whether
*       to return a 16 or 32 bit CRC.
* Changes....:

PARAMETERS lnStartVal, lcBlockTxt, lcBitLen
DO CASE
 CASE PCOUNT() < 2
  WAIT WINDOW "Not enough paramters passed to CRC(lnStartVal, lcBlockTxt, lcBitLen) function."
  RETURN
 CASE PCOUNT() < 3
  lcBitLen = "16"
ENDCASE
DIMENSION laPower[8]     && For the 8 laPowers of 2
PRIVATE lnCRC, lnPower, TestBit
lnBitLen = IIF(lcBitLen="32",32773,4129) && 1021 hex (16bit), 8005 hex (32bit)

* Precalculated values will improve performance in FOR J Code
FOR lnPower = 1 TO 8
 laPower[lnPower] = 2^(lnPower-1)
NEXT lnPower

lnCRC = lnStartVal       && Reset for Each Text Block
FOR OutLoop = 1 TO LEN(lcBlockTxt)  && Calculate for Length of Block
 ByteVal = ASC(SUBSTR(lcBlockTxt, OutLoop, 1))
 FOR InLoop = 8 TO 1 STEP -1
  TestBit = ((BITAND(lnCRC,32768) = 32768) AND NOT (BITAND(ByteVal, laPower(InLoop)) =
laPower(InLoop))) OR;
   (!(BITAND(lnCRC,32768) = 32768) AND (BITAND(ByteVal, laPower(InLoop)) = laPower(InLoop)))
  lnCRC = BITAND(lnCRC,32767)*2
  IF TestBit
   lnCRC = BITXOR(lnCRC,lnBitLen)
  ENDIF
 NEXT InLoop
NEXT OutLoop
RETURN lnCRC      && Return the Word Value


Quote:
> Christof,
> Gee, I'd of thought you'd have converted this to native VFP code already. :-) VFP to Java might be
> easier to pull off than Pascal to Java.

> I'll see if my "ancient" Pascal knowledge can do a translation.

> Rick



> > Hi,

> > This could be the one you are looking for. It's from
> > http://www.umich.edu/~archive/msdos/info/dr.dobbs/ddj8602.arc. The site
> > contains all the source files from the journal between 1986 and 1990. The
> > ones since 1991 are available from the magazine site itself.

> >       { file crctime.pas, 85/9/18/tfr (from 9/15, 7/13, 6/27-26,
> >                           showtime.pas 3/23, 1/4, 84/12/25
> >                           and showkeys 12/12-11, 11/17
> >                           and strinkey.pas, 11/17) }
> >       { compute crc execution times }

> >       { Copyright (c) 1984, 1985, T.F. Ritter; All Rights Reserved }

> >       { Please feel free to copy and use the CRC routines, but . . . }
> >       {    do include the name of the CRC programmer when you do. }
> >       { The CRC programmer is Terry Ritter. }

> >       { AIMS: }
> >       { 1. Display a number of different CRC-CCITT implementations. }
> >       { 2. Verify identical results. }
> >       { 3. Collect and display time statistics on each routine. }

> >       PROGRAM showtime;

> >       { minimum overhead for speed tests }
> >       {$R-}  { Range Checks OFF }
> >       {$C-}  { Ctrl-C Checking OFF }

> >       PROCEDURE ownership;
> >          BEGIN
> >          WRITE( con,
> > ^M^J, 'CRCTIME, 85/9/18',
> > ^M^J, 'Execution times for various CRC implementations.',
> > ^M^J, 'Copyright (c) 1985, T.F. Ritter; All Rights Reserved.',
> > ^M^J     );
> >          END;

> >       TYPE
> >          regs = RECORD
> >                 ax,bx,cx,dx,bp,si,di,ds,es,flags: INTEGER;
> >                 END;

> >       PROCEDURE bdosch( ch: CHAR );
> >          { direct console output through MSDOS }
> >          { allows Ctrl-P printer toggle }
> >          { also skips Ctrl-C break test }
> >          VAR
> >             r: regs;
> >          BEGIN
> >          r.ax := $0200;
> >          r.dx := ORD(ch);
> >          MsDos( r );
> >          END;

> >       { start of time operations }

> >       TYPE
> >          timearty = ARRAY[0..3] of INTEGER; {originally had yr, dy}

> >       PROCEDURE readhms( VAR dt: timearty );
> >          { Hi(dt[2]) = hrs (0 - 23), Lo(dt[2]) = mins (0 - 59) }
> >          { Hi(dt[3]) = secs (0 - 59), Lo(dt[3]) = msecs (0 - 99) }
> >          VAR
> >             r: regs;
> >          BEGIN
> >          r.ax := $2c00;
> >          MsDos( r );
> >          dt[2] := r.cx;
> >          dt[3] := r.dx;
> >          END; { rddtti }

> >       FUNCTION timetorealsecs( x: timearty ): REAL;
> >          BEGIN
> >          timetorealsecs := (Hi(x[2]) * 3600.0)  +  (Lo(x[2]) * 60.0)  +
> >                             Hi(x[3])  +  (Lo(x[3]) / 100.0);
> >          END;

> >       FUNCTION timedif( a, b: timearty ): REAL;
> >          BEGIN
> >          timedif := timetorealsecs( b ) - timetorealsecs( a );
> >          END;

> >       { start of CRC stuff }
> >       { byte crc in Turbo Pascal }
> >       { for MSDOS }

> >       { METHOD 1:  Pascal Bit-By-Bit }
> >       { bit manipulation in a high-level-language }
> >       { simulation of "longhand" division }
> >       { mostly for verification of other methods }

> >       PROCEDURE crcittb( VAR a: INTEGER; databit: BOOLEAN);
> >          { single bit computation; simulate polydiv hardware }
> >          { other Pascals can replace "a SHL 1" with "a + a" }
> >          BEGIN
> >          IF databit = (a < 0) THEN
> >             a := a Shl 1
> >          ELSE
> >             a := (a Shl 1) XOR $1021;  { CRC-CCITT }
> >          END; { crcittb }

> >       PROCEDURE crcittby( VAR aa: INTEGER; d: INTEGER );
> >          { whole byte computation }
> >          VAR
> >             i: INTEGER;
> >          BEGIN
> >          d := d Shl 7;
> >          FOR i := 7 DOWNTO 0 DO
> >             BEGIN
> >             d := d Shl 1;
> >             crcittb( aa, (d < 0) );
> >             END;
> >          END; { crcittby }

> >       { METHOD 2: Pascal Fast Bit-By-Bit }
> >       { eliminates procedure-call overhead in the loop }
> >       { similar to most XMODEM crc implementations}

> >       PROCEDURE crcfbbb( VAR aa: INTEGER; d: INTEGER );
> >          { fast bit-by-bit whole byte computation }
> >          VAR
> >             i: INTEGER;
> >          BEGIN
> >          d := d Shl 7;
> >          FOR i := 7 DOWNTO 0 DO
> >             BEGIN
> >             d := d Shl 1;
> >             IF ((d  XOR aa) < 0) THEN
> >                aa := (aa Shl 1) XOR $1021
> >             ELSE
> >                aa := aa Shl 1;
> >             END;
> >          END; { crcfbbb }

> >       { METHOD 3: Pascal Byte }
> >       { process the data byte without loops }
> >       { transportable within Turbo Pascal, and fairly fast }
> >       { may be slower in Pascals without bit-shifting operations }

> >       PROCEDURE crcitta( VAR dx: INTEGER; data: INTEGER);
> >          { dx := crcTransform( dx; data ) }
> >          { polynomial = $11021 }

> >          { FOR OTHER PASCALS: }
> >          {      Generate a Swap function "swap( x: INTEGER ): INTEGER" }
> >          { probably "swap := (x * 256) + (x DIV 256) would work" }
> >          { Lo(x) = x AND $00ff = x AND 255 }
> >          { x Shr 4 = x DIV 16 }
> >          { x Shl 4 = x * 16 }
> >          { x Shl 5 = x * 32 }

> >          BEGIN { crcitta }

> >          dx := Swap( dx ) XOR data;

> >          dx := dx XOR ( Lo(dx) Shr 4 );

> >          dx := dx XOR (Swap(Lo(dx)) Shl 4) XOR (Lo(dx) Shl 5);

> >          END; { crcitta }

> >       { METHOD 4: Pascal Table }
> >       { pull changes from table, indexed by composite value }
> >       { still faster, but requires the table, and filling the table }
> >       { may be even faster, relatively, in another Pascal }
> >       { a slower routine is fine to fill the table }

> >       VAR
> >          crctab:  ARRAY[0..255] of INTEGER;

> >       PROCEDURE crctablu( VAR crcreg: INTEGER; data: INTEGER);
> >          BEGIN
> >          crcreg := Swap(crcreg) XOR data;
> >          crcreg := (crcreg AND $ff00) XOR crctab[ Lo(crcreg) ];
> >          END;

> >       PROCEDURE initctab;
> >          { use method 3 to init the table }
> >          VAR
> >             i: INTEGER;
> >          BEGIN
> >          FOR i := 0 TO 255 DO
> >             BEGIN
> >             crctab[i] := 0;
> >             crcitta( crctab[i], i );
> >             END;
> >          END; {initctab}

> >       { METHOD 5: Machine Code Byte }
> >       { method 3 in "Inline" machine code (MSDOS) }
> >       { typically hidden away in an "Include" file }
> >       { other Pascals may need to modify the stack interface }

> >       PROCEDURE mcrcitt1( VAR dx: INTEGER; data: INTEGER );
> >          { a := crcTransform( dx; data ) }
> >          { for MSDOS }
> >          { polynomial = $11021 }

> >          BEGIN { mcrcitt1 }
> >          INLINE (
> >                    $c4/$7e/<dx/   {  es:di := [bp +"dx"]   }
> >                    $26/$8b/$05/   {  ax := [es:di]         }

> >          { dx := SWAP(dx) XOR data; }
> >                    $86/$e0/       {  ah <=> al             }
> >                    $33/$46/<data/ {  ax := ax XOR [bp + "data"] }
> >                    $89/$c2/       {  dx := ax              }

> >          {

...

read more »



Tue, 06 Sep 2005 07:41:54 GMT  
 sys(2007, "some text data") Java usage problems
Hi Rick,

Quote:
> Actually, I dug up some old FPW code I'd saved off and forgotten.
> While it looks different, it does give the "right" results.

Cool! I added it to my knowledge base. That's much better than having to
translate some old pascal code. And it's much shorter, too. :)

--
Christof



Tue, 06 Sep 2005 18:12:01 GMT  
 sys(2007, "some text data") Java usage problems
Hi!

  First of all I would like to send greetings to all the people that
tried to help me with the presented problem.
  I will try to implement the presented code in Java as soon as I will
have time.

Thanks again,
  cristi



Tue, 06 Sep 2005 22:42:56 GMT  
 sys(2007, "some text data") Java usage problems
Hi all!

Quote:
> Actually, I dug up some old FPW code I'd saved off and forgotten. While it looks different, it does
> give the "right" results. If you call the program with -1 as the StartVal, and 16 as the BitLen,
> then it seems to give the same results as sys(2007). i.e.
> ?sys(2007,"Now is the time for all good men")
> ?str(bobcrc(-1,"Now is the time for all good men","16"))

> Both return "33312" (I tried a bunch of other stings just to test it!)

> I know it could be optimized using some VFP specific techniques, but why mess with code that works!

This is the Java implementation:
/* begin sys2007 code*/
  public static long sys2007(int lnStartVal, byte[] array, String
lcBitLen){
    int lnBitLen = (lcBitLen.equals("16")) ? 4129 : 32773;

    int lnCRC = lnStartVal;

    // establish the 2-powers
    int[] laPower = new int[8];
    int value = 1;
    for (int i = 0; i < laPower.length; i++) {
      laPower[i] = value;
      value <<= 1;
    }

    // traverse the byte array
    for (int i = 0; i < array.length; i++) {
      byte byteVal = array[i];

      // implement the algorithm's logic
      for (int j = 7; j >= 0; j--) {
        boolean testVal = (((lnCRC&32768) == 32768) &&
!((byteVal&laPower[j]) == laPower[j])) || (!((lnCRC&32768) == 32768)
&& ((byteVal&laPower[j]) == laPower[j]));
        lnCRC = (lnCRC&32767)*2;
        if(testVal) lnCRC ^= lnBitLen;
      }
    }

    return lnCRC;
  }

/* end sys2007 code*/

... and this is the way I use the method:

System.out.println("-->"+sys2007(-1, "Now is the time for all good
men".getBytes("US-ASCII"), "16"));

It produces the same result (33312) and I have tested it with other
strings as well. I didn't test it for "32" instead of "16".

I hope this will help some other people that had the same problem as
me.

Regards and thanks again for the code,
  cristi



Wed, 07 Sep 2005 22:13:38 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Data issue: Active versus "Archived" data

2. sys(2007)

3. Sys(2007) unchanged in VFP?

4. SYS(2007) - Check Sum Value

5. sys(2007) functionality

6. FOXPRO CHECKSUM SYS(2007) QUESTION PLEASE HELP

7. about function SYS(2007, '')

8. SYS(2007) algorithm? (C#)

9. about function SYS(2007, '')

10. sys(2007)

11. Sys 2007 Question

12. CheckSum Sys(2007) Question...

 

 
Powered by phpBB® Forum Software