.ad 8
.bm 8
.fm 4
.bt $Copyright (c) 2000-2005 SAP AG$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $SQL$Project Distributed Database System$VGG02$
.tt 2 $$$
.tt 3 $ElkeZ$Codetransformation_and_Coding$1999-05-21$
***********************************************************
.nf
 
 .nf

    ========== licence begin  GPL
    Copyright (c) 2000-2005 SAP AG

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    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.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    ========== licence end
.fo

 
.fo
.nf
.sp
Module  : Codetransformation_and_Coding
=========
.sp
Purpose : Codetransformation and encryption and decryption of passwords.
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :
 
        VAR
              g02codetables : tgg04_CodeTables;
 
        PROCEDURE
              g02hex (
                    VAR source : tsp00_MoveObj;
                    source_pos : tsp00_Int4;
                    VAR dest   : tsp00_MoveObj;
                    dest_pos   : tsp00_Int4;
                    source_len : tsp00_Int4);
 
        PROCEDURE
              g02date_time_to_int (
                    date_str     : tsp00_Date;
                    time_str     : tsp00_Time;
                    VAR date_int : tsp00_Int4;
                    VAR time_int : tsp00_Int4);
 
        PROCEDURE
              g02datechange (
                    VAR sbuf : tsp00_Timestamp;
                    VAR dbuf : tsp00_MoveObj;
                    spos     : integer;
                    dpos     : tsp00_Int4;
                    format   : tgg00_DateTimeFormat;
                    VAR e    : tgg00_BasisError);
 
        PROCEDURE
              g02decrypt (
                    VAR clearname : tsp00_Name;
                    VAR crypt : tsp00_CryptPw);
&       ifndef AUDIT
 
        PROCEDURE
              g02dump (
                    VAR hostfile    : tgg00_VfFileref;
                    VAR buf         : tsp00_Page;
                    VAR out_pno     : tsp00_Int4;
                    VAR out_pos     : integer;
                    VAR host_err    : tsp00_VfReturn;
                    VAR errtext     : tsp00_ErrText);
&       endif
 
        PROCEDURE
              g02inittranslate_tables;
 
        PROCEDURE
              g02upstring (
                    VAR source : tsp00_MoveObj;
                    srcind   : tsp00_Int4;
                    VAR dest : tsp00_MoveObj;
                    destind  : tsp00_Int4;
                    length   : tsp00_Int4;
                    code_type : tsp00_CodeType );
 
        PROCEDURE
              g02lowstring (
                    VAR source : tsp00_MoveObj;
                    srcind   : tsp00_Int4;
                    VAR dest : tsp00_MoveObj;
                    destind  : tsp00_Int4;
                    length   : tsp00_Int4;
                    code_type : tsp00_CodeType );
 
        PROCEDURE
              g02timechange (
                    VAR sbuf : tsp00_Timestamp;
                    VAR dbuf : tsp00_MoveObj;
                    spos     : integer;
                    dpos     : tsp00_Int4;
                    format   : tgg00_DateTimeFormat;
                    VAR e    : tgg00_BasisError);
 
.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :
 
        FROM
              Configuration_Parameter : VGG01;
 
        PROCEDURE
              g01new_dump_page (
                    VAR hostfile : tgg00_VfFileref;
                    VAR buf      : tsp00_Page;
                    VAR out_pno  : tsp00_Int4;
                    VAR out_pos  : integer;
                    VAR host_err : tsp00_VfReturn;
                    VAR errtext  : tsp00_ErrText);
 
      ------------------------------ 
 
        FROM
              Check-Date-Time : VGG03;
 
        PROCEDURE
              g03dchange_format_date (
                    VAR sbuf : tsp00_Timestamp;
                    VAR dbuf : tsp00_MoveObj;
                    spos     : tsp00_Int4;
                    dpos     : tsp00_Int4;
                    format   : tgg00_DateTimeFormat;
                    VAR e    : tgg00_BasisError);
 
        PROCEDURE
              g03tchange_format_time (
                    VAR sbuf : tsp00_Timestamp;
                    VAR dbuf : tsp00_MoveObj;
                    spos     : tsp00_Int4;
                    dpos     : tsp00_Int4;
                    format   : tgg00_DateTimeFormat;
                    VAR e    : tgg00_BasisError);
 
      ------------------------------ 
 
        FROM
              Kernel_move_and_fill : VGG101;
 
        PROCEDURE
              SAPDB_PascalForcedMove (
                    source_upb  : tsp00_Int4;
                    destin_upb  : tsp00_Int4;
                    source      : tsp00_MoveObjPtr;
                    source_pos  : tsp00_Int4;
                    destin      : tsp00_MoveObjPtr;
                    destin_pos  : tsp00_Int4;
                    length      : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              RTE-Extension-30 : VSP30;
 
        FUNCTION
              s30gad1 (VAR b : tsp00_Ctable): tsp00_ObjAddr;
 
        PROCEDURE
              s30map (
                    VAR code_t   : tsp00_Ctable;
                    VAR source   : tsp00_MoveObj;
                    source_pos   : tsp00_Int4;
                    VAR destin   : tsp00_MoveObj;
                    destin_pos   : tsp00_Int4;
                    length       : tsp00_Int4);
 
.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :
 
        PROCEDURE
              g03dchange_format_date;
 
              tsp00_MoveObj tsp00_Timestamp
 
        PROCEDURE
              g03tchange_format_time;
 
              tsp00_MoveObj tsp00_Timestamp
 
        FUNCTION
              s30gad;
 
              tsp00_MoveObj tsp00_Buf
              tsp00_Addr tsp_vf_bufaddr
 
        FUNCTION
              s30gad1;
 
              tsp00_MoveObj tsp00_Ctable
              tsp00_Addr tsp00_ObjAddr
 
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : ElkeZ
.sp
.cp 3
Created : 1979-03-01
.sp
.cp 3
.sp
.cp 3
Release :      Date : 1999-05-21
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:
.sp 2;.cp 7
Procedure G02DUMP
.sp
This procedure writes the following G02 variables
to the specified host file:
.nf;.sp
G02TABS:   Dump_code = 1051
           G02CODETABLES.TABLES     8 * 256 bytes (total:2048 bytes)
 
.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:
 
.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:
 
.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.oc _/1
.CM -lll-
Code    :
 
 
CONST
      p4 = 2;
      p5 = 523;
      p6 = 133387;
 
 
(*------------------------------*) 
 
PROCEDURE
      g02hex (
            VAR source : tsp00_MoveObj;
            source_pos : tsp00_Int4;
            VAR dest   : tsp00_MoveObj;
            dest_pos   : tsp00_Int4;
            source_len : tsp00_Int4);
 
VAR
      pos      : tsp00_Int4;
      dec      : integer;
      i        : integer;
      hex_byte : ARRAY [ 1..2 ] OF integer;
 
BEGIN
FOR pos := source_pos TO source_pos + source_len - 1 DO
    BEGIN
    dec           := ord (source[ pos ]);
    hex_byte[ 1 ] := dec DIV 16;
    hex_byte[ 2 ] := dec MOD 16;
    FOR i := 1 TO 2 DO
        BEGIN
        IF  hex_byte[ i ] > 9
        THEN
            dest [ dest_pos ] := chr(ord('A')-10+ hex_byte[ i ])
        ELSE
            dest [ dest_pos ] := chr (ord('0') + hex_byte[ i ]);
        (*ENDIF*) 
        dest_pos := succ(dest_pos)
        END
    (*ENDFOR*) 
    END
(*ENDFOR*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      g02date_time_to_int (
            date_str     : tsp00_Date;
            time_str     : tsp00_Time;
            VAR date_int : tsp00_Int4;
            VAR time_int : tsp00_Int4);
 
VAR
      i      : integer;
      factor : tsp00_Int4;
 
BEGIN
date_int := 0;
time_int := 0;
IF  date_str <> bsp_date
THEN
    BEGIN
    factor := 1;
    FOR i := sizeof (date_str) DOWNTO 1 DO
        BEGIN
        date_int := date_int + factor * (ord (date_str[i]) - ord ('0'));
        factor := factor * 10
        END
    (*ENDFOR*) 
    END;
(*ENDIF*) 
IF  time_str <> bsp_time
THEN
    BEGIN
    factor := 1;
    FOR i := sizeof (time_str) DOWNTO 1 DO
        BEGIN
        time_int := time_int + factor * (ord (time_str[i]) - ord ('0'));
        factor := factor * 10
        END
    (*ENDFOR*) 
    END
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      g02datechange (
            VAR sbuf : tsp00_Timestamp;
            VAR dbuf : tsp00_MoveObj;
            spos     : integer;
            dpos     : tsp00_Int4;
            format   : tgg00_DateTimeFormat;
            VAR e    : tgg00_BasisError);
 
BEGIN
g03dchange_format_date(sbuf, dbuf, spos, dpos, format, e);
END;
 
(*------------------------------*) 
 
PROCEDURE
      g02decrypt (
            VAR clearname : tsp00_Name;
            VAR crypt : tsp00_CryptPw);
 
VAR
      i     : integer;
      left  : tsp00_Int4;
      right : tsp00_Int4;
      exp1  : tsp00_Int4;
      exp2  : tsp00_Int4;
      exp3  : tsp00_Int4;
      aux   : tsp00_CryptName;
 
BEGIN
SAPDB_PascalForcedMove (sizeof (crypt), sizeof (aux), @crypt, 1, @aux, 1, sizeof (crypt));
FOR i := 1 TO csp_cryptname DO
    IF  odd(aux[ i ])
    THEN
        aux[ i ] := - aux[ i ];
    (*ENDIF*) 
(*ENDFOR*) 
FOR i := 1 TO csp_cryptname DO
    BEGIN
    IF  i < csp_cryptname - 1
    THEN
        right := aux[ i + 1 ]
    ELSE
        right := p5;
    (*ENDIF*) 
    aux[ i ] := aux[ i ] - ((right MOD 61) * (p6 * 128 - 1));
    END;
(*ENDFOR*) 
FOR i := csp_cryptname DOWNTO 1 DO
    BEGIN
    IF  i > 1
    THEN
        left := aux[ i - 1 ]
    ELSE
        left := p6;
    (*ENDIF*) 
    aux[ i ] := aux[ i ] - ((left MOD 61) * (p6 * 126 - 1));
    END;
(*ENDFOR*) 
FOR i := 1 TO csp_cryptname DO
    BEGIN
    exp3 := aux[ i ];
    exp1 := exp3 DIV p6;
    exp2 := exp3 MOD p6;
    clearname[ 3*i - 2 ] := chr(exp1);
    exp3 := exp2;
    exp1 := exp3 DIV p5;
    exp2 := exp3 MOD p5;
    clearname[ 3*i - 1 ] := chr(exp1);
    exp3 := exp2;
    exp1 := exp3 DIV p4;
    exp2 := exp3 MOD p4;
    clearname[ 3*i ] := chr(exp1);
    END;
(*ENDFOR*) 
END;
 
&ifndef AUDIT
(*------------------------------*) 
 
PROCEDURE
      g02dump (
            VAR hostfile    : tgg00_VfFileref;
            VAR buf         : tsp00_Page;
            VAR out_pno     : tsp00_Int4;
            VAR out_pos     : integer;
            VAR host_err    : tsp00_VfReturn;
            VAR errtext     : tsp00_ErrText);
 
CONST
      mark1_g02tabs   = 'G02TABS ';
      code1_g02tabs   = 1051;
      mark2_g02term   = 'G02CSET ';
      code2_g02term   = 1052;
      fill_code       = 254;
 
VAR
      i2        : tsp_int_map_c2;
      i         : integer;
      dump_mark : tsp00_C8;
      buf_ptr   : tsp_vf_bufaddr;
 
BEGIN
host_err := vf_ok;
buf_ptr  := @buf;
g01new_dump_page (hostfile, buf, out_pno, out_pos, host_err, errtext);
IF  host_err = vf_ok
THEN
    BEGIN
    (* ---  G 0 2 T A B S  --- *)
    dump_mark := mark1_g02tabs;
    SAPDB_PascalForcedMove (sizeof (dump_mark), sizeof (buf), @dump_mark, 1,
          @buf, out_pos, sizeof (dump_mark));
    out_pos := out_pos + sizeof (dump_mark);
    i2.map_int        := code1_g02tabs;
    buf [ out_pos ]   := i2.map_c2[ 1 ];
    buf [ out_pos+1 ] := i2.map_c2[ 2 ];
    out_pos := out_pos + 2;
    WITH g02codetables DO
        FOR i := 1 TO MAX_CODE_TABLES_GG00 DO
            BEGIN
            SAPDB_PascalForcedMove (sizeof (tables [i]), sizeof (buf), @tables [i], 1,
                  @buf, out_pos, sizeof (tables [i]));
            out_pos := out_pos + sizeof (tables [i])
            END
        (*ENDFOR*) 
    (*ENDWITH*) 
    END;
(*ENDIF*) 
IF  (out_pos <> 1) AND (host_err = vf_ok)
THEN
    g01new_dump_page (hostfile, buf, out_pno, out_pos, host_err, errtext)
(*ENDIF*) 
END;
 
&endif
(*------------------------------*) 
 
PROCEDURE
      g02inittranslate_tables;
 
BEGIN
gg02it_rest_part (g02codetables);
END;
 
(*------------------------------*) 
 
PROCEDURE
      g02upstring (
            VAR source : tsp00_MoveObj;
            srcind   : tsp00_Int4;
            VAR dest : tsp00_MoveObj;
            destind  : tsp00_Int4;
            length   : tsp00_Int4;
            code_type : tsp00_CodeType );
 
BEGIN
s30map (g02codetables.tables[ cgg04_up_ascii ],
      source, srcind, dest, destind, length)
END;
 
(*------------------------------*) 
 
PROCEDURE
      g02lowstring (
            VAR source : tsp00_MoveObj;
            srcind   : tsp00_Int4;
            VAR dest : tsp00_MoveObj;
            destind  : tsp00_Int4;
            length   : tsp00_Int4;
            code_type : tsp00_CodeType );
 
BEGIN
s30map (g02codetables.tables[ cgg04_low_ascii ],
      source, srcind, dest, destind, length)
END;
 
(*------------------------------*) 
 
PROCEDURE
      g02timechange (
            VAR sbuf : tsp00_Timestamp;
            VAR dbuf : tsp00_MoveObj;
            spos     : integer;
            dpos     : tsp00_Int4;
            format   : tgg00_DateTimeFormat;
            VAR e    : tgg00_BasisError);
 
BEGIN
g03tchange_format_time (sbuf, dbuf, spos, dpos, format, e);
END;
 
(*------------------------------*) 
 
PROCEDURE
      gg02it_rest_part (VAR codetabs : tgg04_CodeTables);
 
VAR
      i : integer;
 
BEGIN
WITH codetabs DO
    BEGIN
    (* tables[ 4 ] ::= small_ascii_to_capital_ascii *)
    FOR i := 0 TO 255 DO
        tables[ cgg04_up_ascii, i+1 ] := chr (i);
    (*ENDFOR*) 
    FOR i := 97 TO 122 DO
        tables[ cgg04_up_ascii, i+1 ] := chr (i-32);
    (*ENDFOR*) 
    FOR i := 224 TO 246 DO
        tables[ cgg04_up_ascii, i+1 ] := chr (i-32);
    (*ENDFOR*) 
    FOR i := 248 TO 254 DO
        tables[ cgg04_up_ascii, i+1 ] := chr (i-32);
    (*ENDFOR*) 
    (* tables[ 8 ] ::= capital_ascii_to_small_ascii *)
    FOR i := 0 TO 255 DO
        tables[ cgg04_low_ascii, i+1 ] := chr (i);
    (*ENDFOR*) 
    FOR i := 65 TO 90 DO (* 'A' to 'Z' *)
        tables[ cgg04_low_ascii, i+1 ] := chr (i+32);
    (*ENDFOR*) 
    FOR i := 192 TO 214 DO
        tables[ cgg04_low_ascii, i+1 ] := chr (i+32);
    (*ENDFOR*) 
    FOR i := 216 TO 222 DO
        tables[ cgg04_low_ascii, i+1 ] := chr (i+32);
    (*ENDFOR*) 
    END;
(*ENDWITH*) 
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
.PA 
