3DES对称加密算法(ABAP 语言实现版)

公司人事数据要求在系统间加密传输,而对接系统大部分是Java系统,要在不同的异构系统间能很好的加解密码,想到了标准的对称加密算法DES,因为是标准的算法,网络上存在大量公开用Java的DES算法,JAVA系统无需再写。但SAP里面没有找到DES加密的算法,所以只能在SAP里使用ABAP语言自己实现。在写的过程中要用到Bit位操作,ABAP里也是没有位移的原生操作,所以自己也只能像其他语言那样模拟的位操作,具体实现可以参考这里:ABAP语言实现 左移 <<、无符号右移 >>> 位移操作

本加密算法采用ABAP语言实现,加密出来的内容,能够传输到Java系统进行解密,反之亦然;另外本函数还实现了加密指纹验证,可以用来验证传输过来的内容是否被篡改过。

 

函数输入输出参数:

cf49e576-b5ad-4561-a9bb-a76e49794bec

5614e9be-debd-427e-b95b-56be6ae56b3a

加密:

1c72e67f-b4b4-4ad5-964e-238b9be25248

解密:

ec9e6952-4f69-41f5-8c7a-4318429e8061

 

==========================ZHR_3DESENCRYPT==========================

 

FUNCTION zhr_3desencrypt.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     REFERENCE(INPUT) TYPE  ANY
*"     REFERENCE(DES_KEY) TYPE  ALK_STRING OPTIONAL
*"     REFERENCE(MD5_SIGNATURE) TYPE  ALK_STRING OPTIONAL
*"     REFERENCE(MD5_KEY) TYPE  ALK_STRING OPTIONAL
*"     REFERENCE(MODE) TYPE  I
*"  EXPORTING
*"     REFERENCE(OUTPUT) TYPE  ANY
*"     REFERENCE(TARGET_MD5_SING) TYPE  STRING
*"     REFERENCE(VERIFICATION) TYPE  STRING
*"     REFERENCE(ERR) TYPE  STRING
*"----------------------------------------------------------------------
DATA: src TYPE string.
DATA: target_str TYPE string.
DATA: data TYPE string.
DATA: keyxstr TYPE xstring,keystr TYPE string,datastr TYPE string,dataxstr TYPE xstring.
DATA: l_codepage(4) TYPE n .
DATA: l_encoding(20).
DATA: convout TYPE REF TO cl_abap_conv_out_ce.
DATA: convin TYPE REF TO cl_abap_conv_in_ce.
DATA: encxstr TYPE xstring,encstr TYPE string,decxstr TYPE xstring,decstr TYPE string.
DATA: data_md5_keyx TYPE xstring,data_md5_key TYPE string.
DATA: hash160 TYPE hash160.
DATA oref TYPE REF TO cx_root.
DATA: iv TYPE string VALUE '12345678'.
data = input.
PERFORM init.
CALL FUNCTION 'SCP_CODEPAGE_BY_EXTERNAL_NAME'
EXPORTING
      external_name = 'UTF-8'
IMPORTING
      sap_codepage  = l_codepage.
  l_encoding = l_codepage.
IF des_key IS NOT INITIAL.
CALL FUNCTION 'SCMS_BASE64_DECODE_STR'
EXPORTING
input  = des_key
IMPORTING
output = keyxstr.
    keystr = keyxstr.
PERFORM get_keys USING keystr.
ENDIF.
IF mode = 0."加密
    convout = cl_abap_conv_out_ce=>create( encoding = l_encoding ).
    convout->write( data = data ).
    dataxstr =  convout->get_buffer( ).
    datastr = dataxstr.
IF input IS NOT INITIAL AND des_key IS NOT INITIAL.
"CBC/PKCS5Padding
PERFORM 3des USING datastr 1 1 iv 1 CHANGING encstr.
      encxstr = encstr.
CALL FUNCTION 'SCMS_BASE64_ENCODE_STR'
EXPORTING
input  = encxstr
IMPORTING
output = target_str.
output = target_str.
ENDIF.
IF input IS NOT INITIAL AND md5_key IS NOT INITIAL.
CALL FUNCTION 'SCMS_BASE64_DECODE_STR'
EXPORTING
input  = md5_key
IMPORTING
output = keyxstr.
      keystr = keyxstr.
CONCATENATE datastr keystr INTO data_md5_key SEPARATED BY `` RESPECTING BLANKS.
      data_md5_keyx = data_md5_key.
CALL FUNCTION 'CALCULATE_HASH_FOR_RAW'
EXPORTING
          alg  = 'MD5'
data = data_md5_keyx
IMPORTING
          hash = hash160.
      target_md5_sing = hash160.
ENDIF.
ELSE."解密
IF des_key IS NOT INITIAL.
CALL FUNCTION 'SCMS_BASE64_DECODE_STR'
EXPORTING
input  = data
IMPORTING
output = dataxstr.
      datastr = dataxstr.
PERFORM 3des USING datastr 0 1 iv 1 CHANGING decstr.
      decxstr = decstr.
TRY .
          convin = cl_abap_conv_in_ce=>create( encoding = l_encoding input = decxstr ).
CALL METHOD convin->read
IMPORTING
data = target_str.
output = target_str.
CATCH cx_root INTO oref.
CLEAR: target_str,output.
          err = 'UTF-8解码出错!(密钥错误?码流被篡改过?)'.
EXIT.
ENDTRY.
ENDIF.
IF md5_signature IS NOT INITIAL AND md5_key IS NOT INITIAL.
CALL FUNCTION 'SCMS_BASE64_DECODE_STR'
EXPORTING
input  = md5_key
IMPORTING
output = keyxstr.
      keystr = keyxstr.
IF des_key IS NOT INITIAL.
CONCATENATE decstr keystr INTO data_md5_key SEPARATED BY ``.
ELSE.
        convout = cl_abap_conv_out_ce=>create( encoding = l_encoding ).
        convout->write( data = data ).
        dataxstr =  convout->get_buffer( ).
        datastr = dataxstr.
CONCATENATE datastr keystr INTO data_md5_key SEPARATED BY ``.
ENDIF.
      data_md5_keyx = data_md5_key.
CALL FUNCTION 'CALCULATE_HASH_FOR_RAW'
EXPORTING
          alg  = 'MD5'
data = data_md5_keyx
IMPORTING
          hash = hash160.
IF hash160 = md5_signature .
        verification = 'T'.
ELSE.
        verification = 'F'.
ENDIF.
ENDIF.
ENDIF.
ENDFUNCTION.

 

==========================ZHR_3DESENCRYPT==========================

 

==========================LZHR3DESTOP==========================

FUNCTION-POOL zhr3des.                      "MESSAGE-ID ..
DATA: keys TYPE TABLE OF i WITH HEADER LINE.
DATA: BEGIN OF index_map OCCURS 0,
  index_inner TYPE i,
index TYPE i,
END OF  index_map .
DATA: BEGIN OF exp_map OCCURS 0,
  power TYPE i,
  multiplier TYPE i,
END OF  exp_map.

==========================LZHR3DESTOP==========================

==========================LZHR3DESF00==========================

*&---------------------------------------------------------------------*
*&  包括                LZHR3DESF00
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*

*&      Form  int2binary
*&---------------------------------------------------------------------*
*       整型转二进制
*----------------------------------------------------------------------*
*      -->I          text
*      -->C32        text
*----------------------------------------------------------------------*
FORM int2binary USING i TYPE i c32 TYPE c.
DATA: i2 TYPE i.
  i2 = i.
FIELD-SYMBOLS <x> TYPE x.
ASSIGN i2 TO <x> CASTING.
PERFORM x4reverse USING <x>.
DATA: hex(8).
  hex = <x>.
DATA: c4(4),index TYPE i VALUE 0.
DO 8 TIMES.
PERFORM hex2binary USING hex+index(1) c4.
CONCATENATE c32 c4 INTO c32 SEPARATED BY ``.
index = index + 1.
ENDDO.
ENDFORM.                                                    "hex2binary
*&---------------------------------------------------------------------*
*&      Form  c2int
*&---------------------------------------------------------------------*
*       字符转整型
*----------------------------------------------------------------------*
*      -->C1         text
*      -->I          text
*----------------------------------------------------------------------*
FORM c2int USING c1 TYPE c i TYPE i.
FIELD-SYMBOLS <c1> TYPE x.
FIELD-SYMBOLS: <i> TYPE x.
ASSIGN c1 TO <c1> CASTING.
ASSIGN i TO <i> CASTING.
  <i> = <c1>.
ENDFORM.                                                    "c2int
*&---------------------------------------------------------------------*
*&      Form  int2c
*&---------------------------------------------------------------------*
*       整型转字符
*----------------------------------------------------------------------*
*      -->I          text
*      -->C1         text
*----------------------------------------------------------------------*
FORM int2c USING i TYPE i c1 TYPE c.
FIELD-SYMBOLS: <c1> TYPE x.
FIELD-SYMBOLS: <i> TYPE x.
ASSIGN c1 TO <c1> CASTING.
ASSIGN i TO <i> CASTING.
  <c1> = <i>.
ENDFORM.                                                    "c2binary
*&---------------------------------------------------------------------*
*&      Form  x4reverse
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->X4         text
*----------------------------------------------------------------------*
FORM x4reverse USING x4 TYPE x.
DATA: x TYPE x.
x = x4+3(1).
  x4+3(1) = x4+0(1).
  x4+0(1) = x.
x = x4+2(1).
  x4+2(1) = x4+1(1).
  x4+1(1) = x.
ENDFORM.                                                    "x4reverse
*&---------------------------------------------------------------------*
*&      Form  hex2binary
*&---------------------------------------------------------------------*
*       十六进转二进制
*----------------------------------------------------------------------*
*      -->C1         text
*      -->C4         text
*----------------------------------------------------------------------*
FORM hex2binary USING c1 TYPE c c4 TYPE c.
CASE c1.
WHEN '0'.
      c4 = '0000'.
WHEN '1'.
      c4 = '0001'.
WHEN '2'.
      c4 = '0010'.
WHEN '3'.
      c4 = '0011'.
WHEN '4'.
      c4 = '0100'.
WHEN '5'.
      c4 = '0101'.
WHEN '6'.
      c4 = '0110'.
WHEN '7'.
      c4 = '0111'.
WHEN '8'.
      c4 = '1000'.
WHEN '9'.
      c4 = '1001'.
WHEN 'A'.
      c4 = '1010'.
WHEN 'B'.
      c4 = '1011'.
WHEN 'C'.
      c4 = '1100'.
WHEN 'D'.
      c4 = '1101'.
WHEN 'E'.
      c4 = '1110'.
WHEN 'F'.
      c4 = '1111'.
ENDCASE.
ENDFORM.                                                    "hex2binary
*&---------------------------------------------------------------------*
*&      Form  lshfit_c
*&---------------------------------------------------------------------*
*       字符左移
*----------------------------------------------------------------------*
*      -->C1         待位移的字符
*      -->PLACES     移几位
*      -->I          位移后的结果
*----------------------------------------------------------------------*
FORM lshfit_c USING c1 TYPE c places TYPE i i TYPE i.
PERFORM c2int USING c1 i.
PERFORM lshfit_i USING i places i.
ENDFORM.                    "lshfit
*&---------------------------------------------------------------------*
*&      Form  rshfit_c
*&---------------------------------------------------------------------*
*       字符右移
*----------------------------------------------------------------------*
*      -->C1         待位移的字符
*      -->PLACES     移几位
*      -->I          位移后的结果
*----------------------------------------------------------------------*
FORM rshfit_c USING c1 TYPE c places TYPE i i TYPE i.
PERFORM c2int USING c1 i.
PERFORM rshfit_i USING i places i.
ENDFORM.                    "rshfit_c

*&---------------------------------------------------------------------*
*&      Form  lshfit_i
*&---------------------------------------------------------------------*
*       整型左移
*----------------------------------------------------------------------*
*      -->I          待位移的数
*      -->PLACES     移几位
*      -->I2         位移后的数
*----------------------------------------------------------------------*
FORM lshfit_i USING i TYPE i places TYPE i i2 TYPE i.
DATA: start1 TYPE i ,start2 TYPE i.
DATA: b TYPE n.
DATA: i3 TYPE i.
FIELD-SYMBOLS: <i3> TYPE x.
FIELD-SYMBOLS: <i> TYPE x.
FIELD-SYMBOLS: <p> TYPE x.
DATA: _31(4) TYPE x,p TYPE i.
  p = places.
IF places < 0.
    _31 = '1F000000'.
ASSIGN p TO <p> CASTING.
    <p> = <p> BIT-AND _31.
ENDIF.
  i2 = i.
ASSIGN i2 TO <i> CASTING.
IF p = 24 OR p = 16 OR p = 8.
    p = p / 8.
SHIFT <i> BY p PLACES RIGHT IN BYTE MODE.
ELSE.
ASSIGN i3 TO <i3> CASTING.
    start1 = 32 - p.
WHILE  start1 >= 1.
READ TABLE index_map INDEX start1.
GET BIT index_map-index OF <i> INTO b.
IF b = 1.
        start2 = start1 + p.
READ TABLE index_map INDEX start2.
SET BIT index_map-index OF <i3> TO b.
ENDIF.
      start1 = start1 - 1.
ENDWHILE.
    <i> = <i3>.
ENDIF.
ENDFORM.                    "lshfit_i
*&---------------------------------------------------------------------*
*&      Form  rshfit_i
*&---------------------------------------------------------------------*
*       整型右移
*----------------------------------------------------------------------*
*      -->I          待位移的数
*      -->PLACES     移几位
*      -->I2         位移后的数
*----------------------------------------------------------------------*
FORM rshfit_i USING i TYPE i places TYPE i i2 TYPE i.
DATA: start1 TYPE i ,start2 TYPE i.
DATA: b TYPE n.
DATA: i3 TYPE i.
FIELD-SYMBOLS: <i3> TYPE x.
FIELD-SYMBOLS: <i> TYPE x.
FIELD-SYMBOLS: <p> TYPE x.
DATA: _31(4) TYPE x,p TYPE i.
DATA multiplier TYPE i.
  p = places.
IF p < 0.
    _31 = '1F000000'.
ASSIGN p TO <p> CASTING.
    <p> = <p> BIT-AND _31.
ENDIF.
  i2 = i.
ASSIGN i2 TO <i> CASTING.
IF p = 24 OR p = 16 OR p = 8.
    p = p / 8.
SHIFT <i> BY p PLACES LEFT IN BYTE MODE.
ELSE.
IF i >= 0 AND p < 31 .
      multiplier = 2 ** p.
      i2 = i DIV multiplier.
ELSE.
ASSIGN i3 TO <i3> CASTING.
      start1 = p + 1.
WHILE  start1 <= 32.
READ TABLE index_map INDEX start1.
GET BIT index_map-index OF <i> INTO b.
IF b = 1.
          start2 = start1 - p.
READ TABLE index_map INDEX start2.
SET BIT index_map-index OF <i3> TO b.
ENDIF.
        start1 = start1 + 1.
ENDWHILE.
      <i> = <i3>.
ENDIF.
ENDIF.
ENDFORM.                    "rshfit_i
*&---------------------------------------------------------------------*
*&      Form  init
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM init .
CLEAR: index_map[].
  index_map-index_inner = 1.
  index_map-INDEX = 8.
APPEND index_map.
  index_map-index_inner = 2.
  index_map-INDEX = 7.
APPEND index_map.
  index_map-index_inner = 3.
  index_map-INDEX = 6.
APPEND index_map.
  index_map-index_inner = 4.
  index_map-INDEX = 5.
APPEND index_map.
  index_map-index_inner = 5.
  index_map-INDEX = 4.
APPEND index_map.
  index_map-index_inner = 6.
  index_map-INDEX = 3.
APPEND index_map.
  index_map-index_inner = 7.
  index_map-INDEX = 2.
APPEND index_map.
  index_map-index_inner = 8.
  index_map-INDEX = 1.
APPEND index_map.
  index_map-index_inner = 9.
  index_map-INDEX = 16.
APPEND index_map.
  index_map-index_inner = 10.
  index_map-INDEX = 15.
APPEND index_map.
  index_map-index_inner = 11.
  index_map-INDEX = 14.
APPEND index_map.
  index_map-index_inner = 12.
  index_map-INDEX = 13.
APPEND index_map.
  index_map-index_inner = 13.
  index_map-INDEX = 12.
APPEND index_map.
  index_map-index_inner = 14.
  index_map-INDEX = 11.
APPEND index_map.
  index_map-index_inner = 15.
  index_map-INDEX = 10.
APPEND index_map.
  index_map-index_inner = 16.
  index_map-INDEX = 9.
APPEND index_map.
  index_map-index_inner = 17.
  index_map-INDEX = 24.
APPEND index_map.
  index_map-index_inner = 18.
  index_map-INDEX = 23.
APPEND index_map.
  index_map-index_inner = 19.
  index_map-INDEX = 22.
APPEND index_map.
  index_map-index_inner = 20.
  index_map-INDEX = 21.
APPEND index_map.
  index_map-index_inner = 21.
  index_map-INDEX = 20.
APPEND index_map.
  index_map-index_inner = 22.
  index_map-INDEX = 19.
APPEND index_map.
  index_map-index_inner = 23.
  index_map-INDEX = 18.
APPEND index_map.
  index_map-index_inner = 24.
  index_map-INDEX = 17.
APPEND index_map.
  index_map-index_inner = 25.
  index_map-INDEX = 32.
APPEND index_map.
  index_map-index_inner = 26.
  index_map-INDEX = 31.
APPEND index_map.
  index_map-index_inner = 27.
  index_map-INDEX = 30.
APPEND index_map.
  index_map-index_inner = 28.
  index_map-INDEX = 29.
APPEND index_map.
  index_map-index_inner = 29.
  index_map-INDEX = 28.
APPEND index_map.
  index_map-index_inner = 30.
  index_map-INDEX = 27.
APPEND index_map.
  index_map-index_inner = 31.
  index_map-INDEX = 26.
APPEND index_map.
  index_map-index_inner = 32.
  index_map-INDEX = 25.
APPEND index_map.
ENDFORM.                    "init
*&---------------------------------------------------------------------*
*&      Form  3des
*&---------------------------------------------------------------------*
*       3DES加解密核心算法
*----------------------------------------------------------------------*
*      -->MESSAGE    输入
*      -->ENCRYPT    1:加密,0:解密
*      -->MODE       1:CBC模式,0:ECB模式
*      -->IV         text
*      -->PADDING    填充模式
*      -->OUTPUT     输出
*----------------------------------------------------------------------*
FORM 3des USING value(message) TYPE string encrypt TYPE n mode TYPE n iv TYPE string padding TYPE n CHANGING output TYPE string.
DATA: c1 TYPE c.
DATA: tmpstr TYPE string VALUE ''.
DATA: index TYPE i VALUE 0.
DATA: msglen TYPE i.
FIELD-SYMBOLS <c1> TYPE x.
ASSIGN c1 TO <c1> CASTING.
  msglen = STRLEN( message ).
"将十六进制字符串转换为普通字符串
WHILE index < msglen.
    <c1> = message+index(2).
CONCATENATE tmpstr c1 INTO tmpstr SEPARATED BY `` RESPECTING BLANKS.
index = index + 2.
ENDWHILE.
message = tmpstr.
DATA: x4(4) TYPE x.
DATA: i TYPE i.
DATA: spfunction1 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '01010400'. i = x4. APPEND i TO spfunction1.
  x4 = '00000000'. i = x4. APPEND i TO spfunction1.
  x4 = '00010000'. i = x4. APPEND i TO spfunction1.
  x4 = '01010404'. i = x4. APPEND i TO spfunction1.
  x4 = '01010004'. i = x4. APPEND i TO spfunction1.
  x4 = '00010404'. i = x4. APPEND i TO spfunction1.
  x4 = '00000004'. i = x4. APPEND i TO spfunction1.
  x4 = '00010000'. i = x4. APPEND i TO spfunction1.
  x4 = '00000400'. i = x4. APPEND i TO spfunction1.
  x4 = '01010400'. i = x4. APPEND i TO spfunction1.
  x4 = '01010404'. i = x4. APPEND i TO spfunction1.
  x4 = '00000400'. i = x4. APPEND i TO spfunction1.
  x4 = '01000404'. i = x4. APPEND i TO spfunction1.
  x4 = '01010004'. i = x4. APPEND i TO spfunction1.
  x4 = '01000000'. i = x4. APPEND i TO spfunction1.
  x4 = '00000004'. i = x4. APPEND i TO spfunction1.
  x4 = '00000404'. i = x4. APPEND i TO spfunction1.
  x4 = '01000400'. i = x4. APPEND i TO spfunction1.
  x4 = '01000400'. i = x4. APPEND i TO spfunction1.
  x4 = '00010400'. i = x4. APPEND i TO spfunction1.
  x4 = '00010400'. i = x4. APPEND i TO spfunction1.
  x4 = '01010000'. i = x4. APPEND i TO spfunction1.
  x4 = '01010000'. i = x4. APPEND i TO spfunction1.
  x4 = '01000404'. i = x4. APPEND i TO spfunction1.
  x4 = '00010004'. i = x4. APPEND i TO spfunction1.
  x4 = '01000004'. i = x4. APPEND i TO spfunction1.
  x4 = '01000004'. i = x4. APPEND i TO spfunction1.
  x4 = '00010004'. i = x4. APPEND i TO spfunction1.
  x4 = '00000000'. i = x4. APPEND i TO spfunction1.
  x4 = '00000404'. i = x4. APPEND i TO spfunction1.
  x4 = '00010404'. i = x4. APPEND i TO spfunction1.
  x4 = '01000000'. i = x4. APPEND i TO spfunction1.
  x4 = '00010000'. i = x4. APPEND i TO spfunction1.
  x4 = '01010404'. i = x4. APPEND i TO spfunction1.
  x4 = '00000004'. i = x4. APPEND i TO spfunction1.
  x4 = '01010000'. i = x4. APPEND i TO spfunction1.
  x4 = '01010400'. i = x4. APPEND i TO spfunction1.
  x4 = '01000000'. i = x4. APPEND i TO spfunction1.
  x4 = '01000000'. i = x4. APPEND i TO spfunction1.
  x4 = '00000400'. i = x4. APPEND i TO spfunction1.
  x4 = '01010004'. i = x4. APPEND i TO spfunction1.
  x4 = '00010000'. i = x4. APPEND i TO spfunction1.
  x4 = '00010400'. i = x4. APPEND i TO spfunction1.
  x4 = '01000004'. i = x4. APPEND i TO spfunction1.
  x4 = '00000400'. i = x4. APPEND i TO spfunction1.
  x4 = '00000004'. i = x4. APPEND i TO spfunction1.
  x4 = '01000404'. i = x4. APPEND i TO spfunction1.
  x4 = '00010404'. i = x4. APPEND i TO spfunction1.
  x4 = '01010404'. i = x4. APPEND i TO spfunction1.
  x4 = '00010004'. i = x4. APPEND i TO spfunction1.
  x4 = '01010000'. i = x4. APPEND i TO spfunction1.
  x4 = '01000404'. i = x4. APPEND i TO spfunction1.
  x4 = '01000004'. i = x4. APPEND i TO spfunction1.
  x4 = '00000404'. i = x4. APPEND i TO spfunction1.
  x4 = '00010404'. i = x4. APPEND i TO spfunction1.
  x4 = '01010400'. i = x4. APPEND i TO spfunction1.
  x4 = '00000404'. i = x4. APPEND i TO spfunction1.
  x4 = '01000400'. i = x4. APPEND i TO spfunction1.
  x4 = '01000400'. i = x4. APPEND i TO spfunction1.
  x4 = '00000000'. i = x4. APPEND i TO spfunction1.
  x4 = '00010004'. i = x4. APPEND i TO spfunction1.
  x4 = '00010400'. i = x4. APPEND i TO spfunction1.
  x4 = '00000000'. i = x4. APPEND i TO spfunction1.
  x4 = '01010004'. i = x4. APPEND i TO spfunction1.
DATA: spfunction2 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '80108020'. i = x4. APPEND i TO spfunction2.
  x4 = '80008000'. i = x4. APPEND i TO spfunction2.
  x4 = '00008000'. i = x4. APPEND i TO spfunction2.
  x4 = '00108020'. i = x4. APPEND i TO spfunction2.
  x4 = '00100000'. i = x4. APPEND i TO spfunction2.
  x4 = '00000020'. i = x4. APPEND i TO spfunction2.
  x4 = '80100020'. i = x4. APPEND i TO spfunction2.
  x4 = '80008020'. i = x4. APPEND i TO spfunction2.
  x4 = '80000020'. i = x4. APPEND i TO spfunction2.
  x4 = '80108020'. i = x4. APPEND i TO spfunction2.
  x4 = '80108000'. i = x4. APPEND i TO spfunction2.
  x4 = '80000000'. i = x4. APPEND i TO spfunction2.
  x4 = '80008000'. i = x4. APPEND i TO spfunction2.
  x4 = '00100000'. i = x4. APPEND i TO spfunction2.
  x4 = '00000020'. i = x4. APPEND i TO spfunction2.
  x4 = '80100020'. i = x4. APPEND i TO spfunction2.
  x4 = '00108000'. i = x4. APPEND i TO spfunction2.
  x4 = '00100020'. i = x4. APPEND i TO spfunction2.
  x4 = '80008020'. i = x4. APPEND i TO spfunction2.
  x4 = '00000000'. i = x4. APPEND i TO spfunction2.
  x4 = '80000000'. i = x4. APPEND i TO spfunction2.
  x4 = '00008000'. i = x4. APPEND i TO spfunction2.
  x4 = '00108020'. i = x4. APPEND i TO spfunction2.
  x4 = '80100000'. i = x4. APPEND i TO spfunction2.
  x4 = '00100020'. i = x4. APPEND i TO spfunction2.
  x4 = '80000020'. i = x4. APPEND i TO spfunction2.
  x4 = '00000000'. i = x4. APPEND i TO spfunction2.
  x4 = '00108000'. i = x4. APPEND i TO spfunction2.
  x4 = '00008020'. i = x4. APPEND i TO spfunction2.
  x4 = '80108000'. i = x4. APPEND i TO spfunction2.
  x4 = '80100000'. i = x4. APPEND i TO spfunction2.
  x4 = '00008020'. i = x4. APPEND i TO spfunction2.
  x4 = '00000000'. i = x4. APPEND i TO spfunction2.
  x4 = '00108020'. i = x4. APPEND i TO spfunction2.
  x4 = '80100020'. i = x4. APPEND i TO spfunction2.
  x4 = '00100000'. i = x4. APPEND i TO spfunction2.
  x4 = '80008020'. i = x4. APPEND i TO spfunction2.
  x4 = '80100000'. i = x4. APPEND i TO spfunction2.
  x4 = '80108000'. i = x4. APPEND i TO spfunction2.
  x4 = '00008000'. i = x4. APPEND i TO spfunction2.
  x4 = '80100000'. i = x4. APPEND i TO spfunction2.
  x4 = '80008000'. i = x4. APPEND i TO spfunction2.
  x4 = '00000020'. i = x4. APPEND i TO spfunction2.
  x4 = '80108020'. i = x4. APPEND i TO spfunction2.
  x4 = '00108020'. i = x4. APPEND i TO spfunction2.
  x4 = '00000020'. i = x4. APPEND i TO spfunction2.
  x4 = '00008000'. i = x4. APPEND i TO spfunction2.
  x4 = '80000000'. i = x4. APPEND i TO spfunction2.
  x4 = '00008020'. i = x4. APPEND i TO spfunction2.
  x4 = '80108000'. i = x4. APPEND i TO spfunction2.
  x4 = '00100000'. i = x4. APPEND i TO spfunction2.
  x4 = '80000020'. i = x4. APPEND i TO spfunction2.
  x4 = '00100020'. i = x4. APPEND i TO spfunction2.
  x4 = '80008020'. i = x4. APPEND i TO spfunction2.
  x4 = '80000020'. i = x4. APPEND i TO spfunction2.
  x4 = '00100020'. i = x4. APPEND i TO spfunction2.
  x4 = '00108000'. i = x4. APPEND i TO spfunction2.
  x4 = '00000000'. i = x4. APPEND i TO spfunction2.
  x4 = '80008000'. i = x4. APPEND i TO spfunction2.
  x4 = '00008020'. i = x4. APPEND i TO spfunction2.
  x4 = '80000000'. i = x4. APPEND i TO spfunction2.
  x4 = '80100020'. i = x4. APPEND i TO spfunction2.
  x4 = '80108020'. i = x4. APPEND i TO spfunction2.
  x4 = '00108000'. i = x4. APPEND i TO spfunction2.
DATA: spfunction3 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00000208'. i = x4. APPEND i TO spfunction3.
  x4 = '08020200'. i = x4. APPEND i TO spfunction3.
  x4 = '00000000'. i = x4. APPEND i TO spfunction3.
  x4 = '08020008'. i = x4. APPEND i TO spfunction3.
  x4 = '08000200'. i = x4. APPEND i TO spfunction3.
  x4 = '00000000'. i = x4. APPEND i TO spfunction3.
  x4 = '00020208'. i = x4. APPEND i TO spfunction3.
  x4 = '08000200'. i = x4. APPEND i TO spfunction3.
  x4 = '00020008'. i = x4. APPEND i TO spfunction3.
  x4 = '08000008'. i = x4. APPEND i TO spfunction3.
  x4 = '08000008'. i = x4. APPEND i TO spfunction3.
  x4 = '00020000'. i = x4. APPEND i TO spfunction3.
  x4 = '08020208'. i = x4. APPEND i TO spfunction3.
  x4 = '00020008'. i = x4. APPEND i TO spfunction3.
  x4 = '08020000'. i = x4. APPEND i TO spfunction3.
  x4 = '00000208'. i = x4. APPEND i TO spfunction3.
  x4 = '08000000'. i = x4. APPEND i TO spfunction3.
  x4 = '00000008'. i = x4. APPEND i TO spfunction3.
  x4 = '08020200'. i = x4. APPEND i TO spfunction3.
  x4 = '00000200'. i = x4. APPEND i TO spfunction3.
  x4 = '00020200'. i = x4. APPEND i TO spfunction3.
  x4 = '08020000'. i = x4. APPEND i TO spfunction3.
  x4 = '08020008'. i = x4. APPEND i TO spfunction3.
  x4 = '00020208'. i = x4. APPEND i TO spfunction3.
  x4 = '08000208'. i = x4. APPEND i TO spfunction3.
  x4 = '00020200'. i = x4. APPEND i TO spfunction3.
  x4 = '00020000'. i = x4. APPEND i TO spfunction3.
  x4 = '08000208'. i = x4. APPEND i TO spfunction3.
  x4 = '00000008'. i = x4. APPEND i TO spfunction3.
  x4 = '08020208'. i = x4. APPEND i TO spfunction3.
  x4 = '00000200'. i = x4. APPEND i TO spfunction3.
  x4 = '08000000'. i = x4. APPEND i TO spfunction3.
  x4 = '08020200'. i = x4. APPEND i TO spfunction3.
  x4 = '08000000'. i = x4. APPEND i TO spfunction3.
  x4 = '00020008'. i = x4. APPEND i TO spfunction3.
  x4 = '00000208'. i = x4. APPEND i TO spfunction3.
  x4 = '00020000'. i = x4. APPEND i TO spfunction3.
  x4 = '08020200'. i = x4. APPEND i TO spfunction3.
  x4 = '08000200'. i = x4. APPEND i TO spfunction3.
  x4 = '00000000'. i = x4. APPEND i TO spfunction3.
  x4 = '00000200'. i = x4. APPEND i TO spfunction3.
  x4 = '00020008'. i = x4. APPEND i TO spfunction3.
  x4 = '08020208'. i = x4. APPEND i TO spfunction3.
  x4 = '08000200'. i = x4. APPEND i TO spfunction3.
  x4 = '08000008'. i = x4. APPEND i TO spfunction3.
  x4 = '00000200'. i = x4. APPEND i TO spfunction3.
  x4 = '00000000'. i = x4. APPEND i TO spfunction3.
  x4 = '08020008'. i = x4. APPEND i TO spfunction3.
  x4 = '08000208'. i = x4. APPEND i TO spfunction3.
  x4 = '00020000'. i = x4. APPEND i TO spfunction3.
  x4 = '08000000'. i = x4. APPEND i TO spfunction3.
  x4 = '08020208'. i = x4. APPEND i TO spfunction3.
  x4 = '00000008'. i = x4. APPEND i TO spfunction3.
  x4 = '00020208'. i = x4. APPEND i TO spfunction3.
  x4 = '00020200'. i = x4. APPEND i TO spfunction3.
  x4 = '08000008'. i = x4. APPEND i TO spfunction3.
  x4 = '08020000'. i = x4. APPEND i TO spfunction3.
  x4 = '08000208'. i = x4. APPEND i TO spfunction3.
  x4 = '00000208'. i = x4. APPEND i TO spfunction3.
  x4 = '08020000'. i = x4. APPEND i TO spfunction3.
  x4 = '00020208'. i = x4. APPEND i TO spfunction3.
  x4 = '00000008'. i = x4. APPEND i TO spfunction3.
  x4 = '08020008'. i = x4. APPEND i TO spfunction3.
  x4 = '00020200'. i = x4. APPEND i TO spfunction3.
DATA: spfunction4 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00802001'. i = x4. APPEND i TO spfunction4.
  x4 = '00002081'. i = x4. APPEND i TO spfunction4.
  x4 = '00002081'. i = x4. APPEND i TO spfunction4.
  x4 = '00000080'. i = x4. APPEND i TO spfunction4.
  x4 = '00802080'. i = x4. APPEND i TO spfunction4.
  x4 = '00800081'. i = x4. APPEND i TO spfunction4.
  x4 = '00800001'. i = x4. APPEND i TO spfunction4.
  x4 = '00002001'. i = x4. APPEND i TO spfunction4.
  x4 = '00000000'. i = x4. APPEND i TO spfunction4.
  x4 = '00802000'. i = x4. APPEND i TO spfunction4.
  x4 = '00802000'. i = x4. APPEND i TO spfunction4.
  x4 = '00802081'. i = x4. APPEND i TO spfunction4.
  x4 = '00000081'. i = x4. APPEND i TO spfunction4.
  x4 = '00000000'. i = x4. APPEND i TO spfunction4.
  x4 = '00800080'. i = x4. APPEND i TO spfunction4.
  x4 = '00800001'. i = x4. APPEND i TO spfunction4.
  x4 = '00000001'. i = x4. APPEND i TO spfunction4.
  x4 = '00002000'. i = x4. APPEND i TO spfunction4.
  x4 = '00800000'. i = x4. APPEND i TO spfunction4.
  x4 = '00802001'. i = x4. APPEND i TO spfunction4.
  x4 = '00000080'. i = x4. APPEND i TO spfunction4.
  x4 = '00800000'. i = x4. APPEND i TO spfunction4.
  x4 = '00002001'. i = x4. APPEND i TO spfunction4.
  x4 = '00002080'. i = x4. APPEND i TO spfunction4.
  x4 = '00800081'. i = x4. APPEND i TO spfunction4.
  x4 = '00000001'. i = x4. APPEND i TO spfunction4.
  x4 = '00002080'. i = x4. APPEND i TO spfunction4.
  x4 = '00800080'. i = x4. APPEND i TO spfunction4.
  x4 = '00002000'. i = x4. APPEND i TO spfunction4.
  x4 = '00802080'. i = x4. APPEND i TO spfunction4.
  x4 = '00802081'. i = x4. APPEND i TO spfunction4.
  x4 = '00000081'. i = x4. APPEND i TO spfunction4.
  x4 = '00800080'. i = x4. APPEND i TO spfunction4.
  x4 = '00800001'. i = x4. APPEND i TO spfunction4.
  x4 = '00802000'. i = x4. APPEND i TO spfunction4.
  x4 = '00802081'. i = x4. APPEND i TO spfunction4.
  x4 = '00000081'. i = x4. APPEND i TO spfunction4.
  x4 = '00000000'. i = x4. APPEND i TO spfunction4.
  x4 = '00000000'. i = x4. APPEND i TO spfunction4.
  x4 = '00802000'. i = x4. APPEND i TO spfunction4.
  x4 = '00002080'. i = x4. APPEND i TO spfunction4.
  x4 = '00800080'. i = x4. APPEND i TO spfunction4.
  x4 = '00800081'. i = x4. APPEND i TO spfunction4.
  x4 = '00000001'. i = x4. APPEND i TO spfunction4.
  x4 = '00802001'. i = x4. APPEND i TO spfunction4.
  x4 = '00002081'. i = x4. APPEND i TO spfunction4.
  x4 = '00002081'. i = x4. APPEND i TO spfunction4.
  x4 = '00000080'. i = x4. APPEND i TO spfunction4.
  x4 = '00802081'. i = x4. APPEND i TO spfunction4.
  x4 = '00000081'. i = x4. APPEND i TO spfunction4.
  x4 = '00000001'. i = x4. APPEND i TO spfunction4.
  x4 = '00002000'. i = x4. APPEND i TO spfunction4.
  x4 = '00800001'. i = x4. APPEND i TO spfunction4.
  x4 = '00002001'. i = x4. APPEND i TO spfunction4.
  x4 = '00802080'. i = x4. APPEND i TO spfunction4.
  x4 = '00800081'. i = x4. APPEND i TO spfunction4.
  x4 = '00002001'. i = x4. APPEND i TO spfunction4.
  x4 = '00002080'. i = x4. APPEND i TO spfunction4.
  x4 = '00800000'. i = x4. APPEND i TO spfunction4.
  x4 = '00802001'. i = x4. APPEND i TO spfunction4.
  x4 = '00000080'. i = x4. APPEND i TO spfunction4.
  x4 = '00800000'. i = x4. APPEND i TO spfunction4.
  x4 = '00002000'. i = x4. APPEND i TO spfunction4.
  x4 = '00802080'. i = x4. APPEND i TO spfunction4.
DATA: spfunction5 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00000100'. i = x4. APPEND i TO spfunction5.
  x4 = '02080100'. i = x4. APPEND i TO spfunction5.
  x4 = '02080000'. i = x4. APPEND i TO spfunction5.
  x4 = '42000100'. i = x4. APPEND i TO spfunction5.
  x4 = '00080000'. i = x4. APPEND i TO spfunction5.
  x4 = '00000100'. i = x4. APPEND i TO spfunction5.
  x4 = '40000000'. i = x4. APPEND i TO spfunction5.
  x4 = '02080000'. i = x4. APPEND i TO spfunction5.
  x4 = '40080100'. i = x4. APPEND i TO spfunction5.
  x4 = '00080000'. i = x4. APPEND i TO spfunction5.
  x4 = '02000100'. i = x4. APPEND i TO spfunction5.
  x4 = '40080100'. i = x4. APPEND i TO spfunction5.
  x4 = '42000100'. i = x4. APPEND i TO spfunction5.
  x4 = '42080000'. i = x4. APPEND i TO spfunction5.
  x4 = '00080100'. i = x4. APPEND i TO spfunction5.
  x4 = '40000000'. i = x4. APPEND i TO spfunction5.
  x4 = '02000000'. i = x4. APPEND i TO spfunction5.
  x4 = '40080000'. i = x4. APPEND i TO spfunction5.
  x4 = '40080000'. i = x4. APPEND i TO spfunction5.
  x4 = '00000000'. i = x4. APPEND i TO spfunction5.
  x4 = '40000100'. i = x4. APPEND i TO spfunction5.
  x4 = '42080100'. i = x4. APPEND i TO spfunction5.
  x4 = '42080100'. i = x4. APPEND i TO spfunction5.
  x4 = '02000100'. i = x4. APPEND i TO spfunction5.
  x4 = '42080000'. i = x4. APPEND i TO spfunction5.
  x4 = '40000100'. i = x4. APPEND i TO spfunction5.
  x4 = '00000000'. i = x4. APPEND i TO spfunction5.
  x4 = '42000000'. i = x4. APPEND i TO spfunction5.
  x4 = '02080100'. i = x4. APPEND i TO spfunction5.
  x4 = '02000000'. i = x4. APPEND i TO spfunction5.
  x4 = '42000000'. i = x4. APPEND i TO spfunction5.
  x4 = '00080100'. i = x4. APPEND i TO spfunction5.
  x4 = '00080000'. i = x4. APPEND i TO spfunction5.
  x4 = '42000100'. i = x4. APPEND i TO spfunction5.
  x4 = '00000100'. i = x4. APPEND i TO spfunction5.
  x4 = '02000000'. i = x4. APPEND i TO spfunction5.
  x4 = '40000000'. i = x4. APPEND i TO spfunction5.
  x4 = '02080000'. i = x4. APPEND i TO spfunction5.
  x4 = '42000100'. i = x4. APPEND i TO spfunction5.
  x4 = '40080100'. i = x4. APPEND i TO spfunction5.
  x4 = '02000100'. i = x4. APPEND i TO spfunction5.
  x4 = '40000000'. i = x4. APPEND i TO spfunction5.
  x4 = '42080000'. i = x4. APPEND i TO spfunction5.
  x4 = '02080100'. i = x4. APPEND i TO spfunction5.
  x4 = '40080100'. i = x4. APPEND i TO spfunction5.
  x4 = '00000100'. i = x4. APPEND i TO spfunction5.
  x4 = '02000000'. i = x4. APPEND i TO spfunction5.
  x4 = '42080000'. i = x4. APPEND i TO spfunction5.
  x4 = '42080100'. i = x4. APPEND i TO spfunction5.
  x4 = '00080100'. i = x4. APPEND i TO spfunction5.
  x4 = '42000000'. i = x4. APPEND i TO spfunction5.
  x4 = '42080100'. i = x4. APPEND i TO spfunction5.
  x4 = '02080000'. i = x4. APPEND i TO spfunction5.
  x4 = '00000000'. i = x4. APPEND i TO spfunction5.
  x4 = '40080000'. i = x4. APPEND i TO spfunction5.
  x4 = '42000000'. i = x4. APPEND i TO spfunction5.
  x4 = '00080100'. i = x4. APPEND i TO spfunction5.
  x4 = '02000100'. i = x4. APPEND i TO spfunction5.
  x4 = '40000100'. i = x4. APPEND i TO spfunction5.
  x4 = '00080000'. i = x4. APPEND i TO spfunction5.
  x4 = '00000000'. i = x4. APPEND i TO spfunction5.
  x4 = '40080000'. i = x4. APPEND i TO spfunction5.
  x4 = '02080100'. i = x4. APPEND i TO spfunction5.
  x4 = '40000100'. i = x4. APPEND i TO spfunction5.
DATA: spfunction6 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '20000010'. i = x4. APPEND i TO spfunction6.
  x4 = '20400000'. i = x4. APPEND i TO spfunction6.
  x4 = '00004000'. i = x4. APPEND i TO spfunction6.
  x4 = '20404010'. i = x4. APPEND i TO spfunction6.
  x4 = '20400000'. i = x4. APPEND i TO spfunction6.
  x4 = '00000010'. i = x4. APPEND i TO spfunction6.
  x4 = '20404010'. i = x4. APPEND i TO spfunction6.
  x4 = '00400000'. i = x4. APPEND i TO spfunction6.
  x4 = '20004000'. i = x4. APPEND i TO spfunction6.
  x4 = '00404010'. i = x4. APPEND i TO spfunction6.
  x4 = '00400000'. i = x4. APPEND i TO spfunction6.
  x4 = '20000010'. i = x4. APPEND i TO spfunction6.
  x4 = '00400010'. i = x4. APPEND i TO spfunction6.
  x4 = '20004000'. i = x4. APPEND i TO spfunction6.
  x4 = '20000000'. i = x4. APPEND i TO spfunction6.
  x4 = '00004010'. i = x4. APPEND i TO spfunction6.
  x4 = '00000000'. i = x4. APPEND i TO spfunction6.
  x4 = '00400010'. i = x4. APPEND i TO spfunction6.
  x4 = '20004010'. i = x4. APPEND i TO spfunction6.
  x4 = '00004000'. i = x4. APPEND i TO spfunction6.
  x4 = '00404000'. i = x4. APPEND i TO spfunction6.
  x4 = '20004010'. i = x4. APPEND i TO spfunction6.
  x4 = '00000010'. i = x4. APPEND i TO spfunction6.
  x4 = '20400010'. i = x4. APPEND i TO spfunction6.
  x4 = '20400010'. i = x4. APPEND i TO spfunction6.
  x4 = '00000000'. i = x4. APPEND i TO spfunction6.
  x4 = '00404010'. i = x4. APPEND i TO spfunction6.
  x4 = '20404000'. i = x4. APPEND i TO spfunction6.
  x4 = '00004010'. i = x4. APPEND i TO spfunction6.
  x4 = '00404000'. i = x4. APPEND i TO spfunction6.
  x4 = '20404000'. i = x4. APPEND i TO spfunction6.
  x4 = '20000000'. i = x4. APPEND i TO spfunction6.
  x4 = '20004000'. i = x4. APPEND i TO spfunction6.
  x4 = '00000010'. i = x4. APPEND i TO spfunction6.
  x4 = '20400010'. i = x4. APPEND i TO spfunction6.
  x4 = '00404000'. i = x4. APPEND i TO spfunction6.
  x4 = '20404010'. i = x4. APPEND i TO spfunction6.
  x4 = '00400000'. i = x4. APPEND i TO spfunction6.
  x4 = '00004010'. i = x4. APPEND i TO spfunction6.
  x4 = '20000010'. i = x4. APPEND i TO spfunction6.
  x4 = '00400000'. i = x4. APPEND i TO spfunction6.
  x4 = '20004000'. i = x4. APPEND i TO spfunction6.
  x4 = '20000000'. i = x4. APPEND i TO spfunction6.
  x4 = '00004010'. i = x4. APPEND i TO spfunction6.
  x4 = '20000010'. i = x4. APPEND i TO spfunction6.
  x4 = '20404010'. i = x4. APPEND i TO spfunction6.
  x4 = '00404000'. i = x4. APPEND i TO spfunction6.
  x4 = '20400000'. i = x4. APPEND i TO spfunction6.
  x4 = '00404010'. i = x4. APPEND i TO spfunction6.
  x4 = '20404000'. i = x4. APPEND i TO spfunction6.
  x4 = '00000000'. i = x4. APPEND i TO spfunction6.
  x4 = '20400010'. i = x4. APPEND i TO spfunction6.
  x4 = '00000010'. i = x4. APPEND i TO spfunction6.
  x4 = '00004000'. i = x4. APPEND i TO spfunction6.
  x4 = '20400000'. i = x4. APPEND i TO spfunction6.
  x4 = '00404010'. i = x4. APPEND i TO spfunction6.
  x4 = '00004000'. i = x4. APPEND i TO spfunction6.
  x4 = '00400010'. i = x4. APPEND i TO spfunction6.
  x4 = '20004010'. i = x4. APPEND i TO spfunction6.
  x4 = '00000000'. i = x4. APPEND i TO spfunction6.
  x4 = '20404000'. i = x4. APPEND i TO spfunction6.
  x4 = '20000000'. i = x4. APPEND i TO spfunction6.
  x4 = '00400010'. i = x4. APPEND i TO spfunction6.
  x4 = '20004010'. i = x4. APPEND i TO spfunction6.
DATA: spfunction7 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00200000'. i = x4. APPEND i TO spfunction7.
  x4 = '04200002'. i = x4. APPEND i TO spfunction7.
  x4 = '04000802'. i = x4. APPEND i TO spfunction7.
  x4 = '00000000'. i = x4. APPEND i TO spfunction7.
  x4 = '00000800'. i = x4. APPEND i TO spfunction7.
  x4 = '04000802'. i = x4. APPEND i TO spfunction7.
  x4 = '00200802'. i = x4. APPEND i TO spfunction7.
  x4 = '04200800'. i = x4. APPEND i TO spfunction7.
  x4 = '04200802'. i = x4. APPEND i TO spfunction7.
  x4 = '00200000'. i = x4. APPEND i TO spfunction7.
  x4 = '00000000'. i = x4. APPEND i TO spfunction7.
  x4 = '04000002'. i = x4. APPEND i TO spfunction7.
  x4 = '00000002'. i = x4. APPEND i TO spfunction7.
  x4 = '04000000'. i = x4. APPEND i TO spfunction7.
  x4 = '04200002'. i = x4. APPEND i TO spfunction7.
  x4 = '00000802'. i = x4. APPEND i TO spfunction7.
  x4 = '04000800'. i = x4. APPEND i TO spfunction7.
  x4 = '00200802'. i = x4. APPEND i TO spfunction7.
  x4 = '00200002'. i = x4. APPEND i TO spfunction7.
  x4 = '04000800'. i = x4. APPEND i TO spfunction7.
  x4 = '04000002'. i = x4. APPEND i TO spfunction7.
  x4 = '04200000'. i = x4. APPEND i TO spfunction7.
  x4 = '04200800'. i = x4. APPEND i TO spfunction7.
  x4 = '00200002'. i = x4. APPEND i TO spfunction7.
  x4 = '04200000'. i = x4. APPEND i TO spfunction7.
  x4 = '00000800'. i = x4. APPEND i TO spfunction7.
  x4 = '00000802'. i = x4. APPEND i TO spfunction7.
  x4 = '04200802'. i = x4. APPEND i TO spfunction7.
  x4 = '00200800'. i = x4. APPEND i TO spfunction7.
  x4 = '00000002'. i = x4. APPEND i TO spfunction7.
  x4 = '04000000'. i = x4. APPEND i TO spfunction7.
  x4 = '00200800'. i = x4. APPEND i TO spfunction7.
  x4 = '04000000'. i = x4. APPEND i TO spfunction7.
  x4 = '00200800'. i = x4. APPEND i TO spfunction7.
  x4 = '00200000'. i = x4. APPEND i TO spfunction7.
  x4 = '04000802'. i = x4. APPEND i TO spfunction7.
  x4 = '04000802'. i = x4. APPEND i TO spfunction7.
  x4 = '04200002'. i = x4. APPEND i TO spfunction7.
  x4 = '04200002'. i = x4. APPEND i TO spfunction7.
  x4 = '00000002'. i = x4. APPEND i TO spfunction7.
  x4 = '00200002'. i = x4. APPEND i TO spfunction7.
  x4 = '04000000'. i = x4. APPEND i TO spfunction7.
  x4 = '04000800'. i = x4. APPEND i TO spfunction7.
  x4 = '00200000'. i = x4. APPEND i TO spfunction7.
  x4 = '04200800'. i = x4. APPEND i TO spfunction7.
  x4 = '00000802'. i = x4. APPEND i TO spfunction7.
  x4 = '00200802'. i = x4. APPEND i TO spfunction7.
  x4 = '04200800'. i = x4. APPEND i TO spfunction7.
  x4 = '00000802'. i = x4. APPEND i TO spfunction7.
  x4 = '04000002'. i = x4. APPEND i TO spfunction7.
  x4 = '04200802'. i = x4. APPEND i TO spfunction7.
  x4 = '04200000'. i = x4. APPEND i TO spfunction7.
  x4 = '00200800'. i = x4. APPEND i TO spfunction7.
  x4 = '00000000'. i = x4. APPEND i TO spfunction7.
  x4 = '00000002'. i = x4. APPEND i TO spfunction7.
  x4 = '04200802'. i = x4. APPEND i TO spfunction7.
  x4 = '00000000'. i = x4. APPEND i TO spfunction7.
  x4 = '00200802'. i = x4. APPEND i TO spfunction7.
  x4 = '04200000'. i = x4. APPEND i TO spfunction7.
  x4 = '00000800'. i = x4. APPEND i TO spfunction7.
  x4 = '04000002'. i = x4. APPEND i TO spfunction7.
  x4 = '04000800'. i = x4. APPEND i TO spfunction7.
  x4 = '00000800'. i = x4. APPEND i TO spfunction7.
  x4 = '00200002'. i = x4. APPEND i TO spfunction7.
DATA: spfunction8 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '10001040'. i = x4. APPEND i TO spfunction8.
  x4 = '00001000'. i = x4. APPEND i TO spfunction8.
  x4 = '00040000'. i = x4. APPEND i TO spfunction8.
  x4 = '10041040'. i = x4. APPEND i TO spfunction8.
  x4 = '10000000'. i = x4. APPEND i TO spfunction8.
  x4 = '10001040'. i = x4. APPEND i TO spfunction8.
  x4 = '00000040'. i = x4. APPEND i TO spfunction8.
  x4 = '10000000'. i = x4. APPEND i TO spfunction8.
  x4 = '00040040'. i = x4. APPEND i TO spfunction8.
  x4 = '10040000'. i = x4. APPEND i TO spfunction8.
  x4 = '10041040'. i = x4. APPEND i TO spfunction8.
  x4 = '00041000'. i = x4. APPEND i TO spfunction8.
  x4 = '10041000'. i = x4. APPEND i TO spfunction8.
  x4 = '00041040'. i = x4. APPEND i TO spfunction8.
  x4 = '00001000'. i = x4. APPEND i TO spfunction8.
  x4 = '00000040'. i = x4. APPEND i TO spfunction8.
  x4 = '10040000'. i = x4. APPEND i TO spfunction8.
  x4 = '10000040'. i = x4. APPEND i TO spfunction8.
  x4 = '10001000'. i = x4. APPEND i TO spfunction8.
  x4 = '00001040'. i = x4. APPEND i TO spfunction8.
  x4 = '00041000'. i = x4. APPEND i TO spfunction8.
  x4 = '00040040'. i = x4. APPEND i TO spfunction8.
  x4 = '10040040'. i = x4. APPEND i TO spfunction8.
  x4 = '10041000'. i = x4. APPEND i TO spfunction8.
  x4 = '00001040'. i = x4. APPEND i TO spfunction8.
  x4 = '00000000'. i = x4. APPEND i TO spfunction8.
  x4 = '00000000'. i = x4. APPEND i TO spfunction8.
  x4 = '10040040'. i = x4. APPEND i TO spfunction8.
  x4 = '10000040'. i = x4. APPEND i TO spfunction8.
  x4 = '10001000'. i = x4. APPEND i TO spfunction8.
  x4 = '00041040'. i = x4. APPEND i TO spfunction8.
  x4 = '00040000'. i = x4. APPEND i TO spfunction8.
  x4 = '00041040'. i = x4. APPEND i TO spfunction8.
  x4 = '00040000'. i = x4. APPEND i TO spfunction8.
  x4 = '10041000'. i = x4. APPEND i TO spfunction8.
  x4 = '00001000'. i = x4. APPEND i TO spfunction8.
  x4 = '00000040'. i = x4. APPEND i TO spfunction8.
  x4 = '10040040'. i = x4. APPEND i TO spfunction8.
  x4 = '00001000'. i = x4. APPEND i TO spfunction8.
  x4 = '00041040'. i = x4. APPEND i TO spfunction8.
  x4 = '10001000'. i = x4. APPEND i TO spfunction8.
  x4 = '00000040'. i = x4. APPEND i TO spfunction8.
  x4 = '10000040'. i = x4. APPEND i TO spfunction8.
  x4 = '10040000'. i = x4. APPEND i TO spfunction8.
  x4 = '10040040'. i = x4. APPEND i TO spfunction8.
  x4 = '10000000'. i = x4. APPEND i TO spfunction8.
  x4 = '00040000'. i = x4. APPEND i TO spfunction8.
  x4 = '10001040'. i = x4. APPEND i TO spfunction8.
  x4 = '00000000'. i = x4. APPEND i TO spfunction8.
  x4 = '10041040'. i = x4. APPEND i TO spfunction8.
  x4 = '00040040'. i = x4. APPEND i TO spfunction8.
  x4 = '10000040'. i = x4. APPEND i TO spfunction8.
  x4 = '10040000'. i = x4. APPEND i TO spfunction8.
  x4 = '10001000'. i = x4. APPEND i TO spfunction8.
  x4 = '10001040'. i = x4. APPEND i TO spfunction8.
  x4 = '00000000'. i = x4. APPEND i TO spfunction8.
  x4 = '10041040'. i = x4. APPEND i TO spfunction8.
  x4 = '00041000'. i = x4. APPEND i TO spfunction8.
  x4 = '00041000'. i = x4. APPEND i TO spfunction8.
  x4 = '00001040'. i = x4. APPEND i TO spfunction8.
  x4 = '00001040'. i = x4. APPEND i TO spfunction8.
  x4 = '00040040'. i = x4. APPEND i TO spfunction8.
  x4 = '10000000'. i = x4. APPEND i TO spfunction8.
  x4 = '10041000'. i = x4. APPEND i TO spfunction8.
FIELD-SYMBOLS: <spfunction1> TYPE x,<spfunction2> TYPE x,<spfunction3> TYPE x,<spfunction4> TYPE x,
  <spfunction5> TYPE x,<spfunction6> TYPE x,<spfunction7> TYPE x,<spfunction8> TYPE x.
ASSIGN spfunction1 TO <spfunction1> CASTING.
ASSIGN spfunction2 TO <spfunction2> CASTING.
ASSIGN spfunction3 TO <spfunction3> CASTING.
ASSIGN spfunction4 TO <spfunction4> CASTING.
ASSIGN spfunction5 TO <spfunction5> CASTING.
ASSIGN spfunction6 TO <spfunction6> CASTING.
ASSIGN spfunction7 TO <spfunction7> CASTING.
ASSIGN spfunction8 TO <spfunction8> CASTING.
DATA: m TYPE i VALUE 0, j TYPE i, temp TYPE i, right1 TYPE i, right2 TYPE i, left TYPE i, right TYPE i.
FIELD-SYMBOLS:<left> TYPE x,<right> TYPE x,<temp> TYPE x,<right1> TYPE x,<right2> TYPE x.
ASSIGN temp TO <temp> CASTING.
ASSIGN right1 TO <right1> CASTING.
ASSIGN right2 TO <right2> CASTING.
ASSIGN left TO <left> CASTING.
ASSIGN right TO <right> CASTING.
DATA: cbcleft TYPE i, cbcleft2 TYPE i, cbcright TYPE i, cbcright2 TYPE i.
FIELD-SYMBOLS:<cbcleft> TYPE x,<cbcleft2> TYPE x, <cbcright> TYPE x,<cbcright2> TYPE x.
ASSIGN cbcleft TO <cbcleft> CASTING.
ASSIGN cbcleft2 TO <cbcleft2> CASTING.
ASSIGN cbcright TO <cbcright> CASTING.
ASSIGN cbcright2 TO <cbcright2> CASTING.
DATA: looping TYPE TABLE OF i WITH HEADER LINE.
DATA: endloop TYPE i, loopinc TYPE i.
DATA: len TYPE i.
DATA: chunk TYPE i.
DATA: keylen TYPE i.
DATA: iterations TYPE i.
  len = STRLEN( message ).
DESCRIBE TABLE keys LINES keylen.
IF keylen = 32.
    iterations = 3.
ELSE.
    iterations = 9.
ENDIF.
IF iterations = 3 .
IF encrypt = 1.
APPEND 0 TO looping.
APPEND 32 TO looping.
APPEND 2 TO looping.
ELSE.
APPEND 30 TO looping.
APPEND -2 TO looping.
APPEND -2 TO looping.
ENDIF.
ELSE.
IF encrypt = 1.
APPEND 0 TO looping.
APPEND 32 TO looping.
APPEND 2 TO looping.
APPEND 62 TO looping.
APPEND 30 TO looping.
APPEND -2 TO looping.
APPEND 64 TO looping.
APPEND 96 TO looping.
APPEND 2 TO looping.
ELSE.
APPEND 94 TO looping.
APPEND 62 TO looping.
APPEND -2 TO looping.
APPEND 32 TO looping.
APPEND 64 TO looping.
APPEND 2 TO looping.
APPEND 30 TO looping.
APPEND -2 TO looping.
APPEND -2 TO looping.
ENDIF.
ENDIF.
DATA: x2(2) TYPE x.
DATA: c4(4),c2(2).
IF padding = 2.
CONCATENATE message `        ` INTO message SEPARATED BY ``.
ELSEIF padding = 1."PKCS5 padding
IF encrypt = 1.
      temp = len MOD 8 .
      temp = 8 - temp.
      <c1> = temp.
      c4 = <c1>.
      c2 = c4+0(2).
      c4+0(2) = c4+2(2).
      c4+2(2) = c2.
      x2 = c4.
      <c1> = x2.
DO 8 TIMES.
CONCATENATE message c1 INTO message SEPARATED BY ``.
ENDDO.
IF temp = 8.
        len = len + 8.
ENDIF.
ENDIF.
ELSEIF padding = 0.
    x2 = '00'.
    <c1> = x2.
CONCATENATE message c1 c1 c1 c1 c1 c1 c1 c1  INTO message SEPARATED BY ``.
ENDIF.
DATA: result TYPE string.
DATA: tempresult TYPE string.
DATA: temp1_i TYPE i,temp2_i TYPE i,temp3_i TYPE i,temp4_i TYPE i,temp5_i TYPE i,temp6_i TYPE i,temp7_i TYPE i,temp8_i TYPE i.
FIELD-SYMBOLS: <temp1_i> TYPE x, <temp2_i> TYPE x, <temp3_i> TYPE x, <temp4_i> TYPE x, <temp5_i> TYPE x, <temp6_i> TYPE x, <temp7_i> TYPE x, <temp8_i> TYPE x.
ASSIGN temp1_i TO <temp1_i> CASTING.
ASSIGN temp2_i TO <temp2_i> CASTING.
ASSIGN temp3_i TO <temp3_i> CASTING.
ASSIGN temp4_i TO <temp4_i> CASTING.
ASSIGN temp5_i TO <temp5_i> CASTING.
ASSIGN temp6_i TO <temp6_i> CASTING.
ASSIGN temp7_i TO <temp7_i> CASTING.
ASSIGN temp8_i TO <temp8_i> CASTING.
FIELD-SYMBOLS: <keys> TYPE x.
ASSIGN keys TO <keys> CASTING.
"如果是CBC工作模式时,需初始化IV
IF mode = 1."CBC mode
    c1 = iv+m(1).
PERFORM lshfit_c USING c1 24 temp1_i.
m = m + 1.
    c1 = iv+m(1).
PERFORM lshfit_c USING c1 16 temp2_i.
m = m + 1.
    c1 = iv+m(1).
PERFORM lshfit_c USING c1 8 temp3_i.
m = m + 1.
    c1 = iv+m(1).
PERFORM c2int USING c1 temp4_i.
m = m + 1.
    <cbcleft> = <temp1_i> BIT-OR <temp2_i> BIT-OR <temp3_i> BIT-OR <temp4_i>.
    c1 = iv+m(1).
PERFORM lshfit_c USING c1 24 temp1_i.
m = m + 1.
    c1 = iv+m(1).
PERFORM lshfit_c USING c1 16 temp2_i.
m = m + 1.
    c1 = iv+m(1).
PERFORM lshfit_c USING c1 8 temp3_i.
m = m + 1.
    c1 = iv+m(1).
PERFORM c2int USING c1 temp4_i.
    <cbcright> = <temp1_i> BIT-OR <temp2_i> BIT-OR <temp3_i> BIT-OR <temp4_i>.
m = 0.
ENDIF.
"每8字节(64位)为一个处理单元,共需循环 (message.length + 7)/8 次
WHILE m < len.
"将64位(8字节)message消息块分成左右两部分,每部分32位(4字节)
    c1 = message+m(1).
PERFORM lshfit_c USING c1 24 temp1_i.
m = m + 1.
    c1 = message+m(1).
PERFORM lshfit_c USING c1 16 temp2_i.
m = m + 1.
    c1 = message+m(1).
PERFORM lshfit_c USING c1 8 temp3_i.
m = m + 1.
    c1 = message+m(1).
PERFORM c2int USING c1 temp4_i.
m = m + 1.
    <left> = <temp1_i> BIT-OR <temp2_i> BIT-OR <temp3_i> BIT-OR <temp4_i>.
    c1 = message+m(1).
PERFORM lshfit_c USING c1 24 temp1_i.
m = m + 1.
    c1 = message+m(1).
PERFORM lshfit_c USING c1 16 temp2_i.
m = m + 1.
    c1 = message+m(1).
PERFORM lshfit_c USING c1 8 temp3_i.
m = m + 1.
    c1 = message+m(1).
PERFORM c2int USING c1 temp4_i.
m = m + 1.
    <right> = <temp1_i> BIT-OR <temp2_i> BIT-OR <temp3_i> BIT-OR <temp4_i>.
*==========================
"在CBC模式中,每个明文块先与前一个密文块进行异或后,再进行加密。在这种模式下,每个密文块都依赖于它前面的所有明文块
IF mode = 1.
IF encrypt = 1.
        <left> = <left> BIT-XOR <cbcleft>.
        <right> = <right> BIT-XOR <cbcright>.
ELSE.
        cbcleft2 = cbcleft.
        cbcright2 = cbcright.
        cbcleft = left.
        cbcright = right.
ENDIF.
ENDIF.
*==========================
"每块(64位)根据置换规则表做IP置换(初始置换):目的是将输入的64位数据块按位重新组合
PERFORM rshfit_i USING left 4 temp1_i.
    <temp1_i> = <temp1_i> BIT-XOR <right>.
    x4 = '0F0F0F0F'.
    temp2_i = x4.
    <temp> = <temp1_i> BIT-AND <temp2_i>.
    <right> = <right> BIT-XOR <temp>.
PERFORM lshfit_i USING temp 4 temp1_i.
    <left> = <left> BIT-XOR <temp1_i>.
PERFORM rshfit_i USING left 16 temp1_i.
    <temp1_i> = <temp1_i> BIT-XOR <right>.
    x4 = '0000FFFF'.
    temp2_i = x4.
    <temp> = <temp1_i> BIT-AND <temp2_i>.
    <right> = <right> BIT-XOR <temp>.
PERFORM lshfit_i USING temp 16 temp1_i.
    <left> = <left> BIT-XOR <temp1_i>.
PERFORM rshfit_i USING right 2 temp1_i.
    <temp1_i> = <temp1_i> BIT-XOR <left>.
    x4 = '33333333'.
    temp2_i = x4.
    <temp> = <temp1_i> BIT-AND <temp2_i>.
    <left> = <left> BIT-XOR <temp>.
PERFORM lshfit_i USING temp 2 temp1_i.
    <right> = <right> BIT-XOR <temp1_i>.
PERFORM rshfit_i USING right 8 temp1_i.
    <temp1_i> = <temp1_i> BIT-XOR <left>.
    x4 = '00FF00FF'.
    temp2_i = x4.
    <temp> = <temp1_i> BIT-AND <temp2_i>.
    <left> = <left> BIT-XOR <temp>.
PERFORM lshfit_i USING temp 8 temp1_i.
    <right> = <right> BIT-XOR <temp1_i>.
PERFORM rshfit_i USING left 1 temp1_i.
    <temp1_i> = <temp1_i> BIT-XOR <right>.
    x4 = '55555555'.
    temp2_i = x4.
    <temp> = <temp1_i> BIT-AND <temp2_i>.
    <right> = <right> BIT-XOR <temp>.
PERFORM lshfit_i USING temp 1 temp1_i.
    <left> = <left> BIT-XOR <temp1_i>.
*==========================
PERFORM lshfit_i USING left 1 temp1_i.
PERFORM rshfit_i USING left 31 temp2_i.
    <left> = <temp1_i> BIT-OR <temp2_i>.
PERFORM lshfit_i USING right 1 temp1_i.
PERFORM rshfit_i USING right 31 temp2_i.
    <right> = <temp1_i> BIT-OR <temp2_i>.
*==========================
    j = 0.
WHILE j < iterations."每块经过3次DES加密
index = j + 2.
*      CLEAR looping.
READ TABLE looping INDEX index.
endloop = looping.
index = j + 3.
*      CLEAR looping.
READ TABLE looping INDEX index.
      loopinc = looping.
index = j + 1.
*      CLEAR looping.
READ TABLE looping INDEX index.
i = looping.
"经过16次循环,每一轮的运算包含扩展置换、S盒置换、P盒置换和两次异或运算,每次使用不同的子密钥
WHILE i <> endloop.
index = i + 1.
*        CLEAR keys.
READ TABLE keys INDEX index.
        <right1> = <right> BIT-XOR <keys>.
PERFORM rshfit_i USING right 4 temp1_i.
PERFORM lshfit_i USING right 28 temp2_i.
        <temp3_i> = <temp1_i> BIT-OR <temp2_i>.
index = i + 2.
*        CLEAR keys.
READ TABLE keys INDEX index.
        <right2> = <temp3_i> BIT-XOR <keys>.
        temp = left.
left = right.
PERFORM rshfit_i USING right1 24 temp1_i.
        x4 = '0000003F'.
        temp2_i = x4.
        <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
        temp3_i = temp3_i + 1.
*        CLEAR spfunction2.
READ TABLE spfunction2 INDEX temp3_i.
PERFORM rshfit_i USING right1 16 temp1_i.
*        x4 = '0000003F'.
*        temp2_i = x4.
        <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
        temp3_i = temp3_i + 1.
*        CLEAR spfunction4.
READ TABLE spfunction4 INDEX temp3_i.
PERFORM rshfit_i USING right1 8 temp1_i.
*        x4 = '0000003F'.
*        temp2_i = x4.
        <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
        temp3_i = temp3_i + 1.
*        CLEAR spfunction6.
READ TABLE spfunction6 INDEX temp3_i.
*        x4 = '0000003F'.
*        temp2_i = x4.
        <temp3_i> = <right1> BIT-AND <temp2_i>.
        temp3_i = temp3_i + 1.
*        CLEAR spfunction8.
READ TABLE spfunction8 INDEX temp3_i.
PERFORM rshfit_i USING right2 24 temp1_i.
*        x4 = '0000003F'.
*        temp2_i = x4.
        <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
        temp3_i = temp3_i + 1.
*        CLEAR spfunction1.
READ TABLE spfunction1 INDEX temp3_i.
PERFORM rshfit_i USING right2 16 temp1_i.
*        x4 = '0000003F'.
*        temp2_i = x4.
        <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
        temp3_i = temp3_i + 1.
*        CLEAR spfunction3.
READ TABLE spfunction3 INDEX temp3_i.
PERFORM rshfit_i USING right2 8 temp1_i.
*        x4 = '0000003F'.
*        temp2_i = x4.
        <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
        temp3_i = temp3_i + 1.
*        CLEAR spfunction5.
READ TABLE spfunction5 INDEX temp3_i.
*        x4 = '0000003F'.
*        temp2_i = x4.
        <temp3_i> = <right2> BIT-AND <temp2_i>.
        temp3_i = temp3_i + 1.
*        CLEAR spfunction7.
READ TABLE spfunction7 INDEX temp3_i.
        <temp4_i> = <spfunction2> BIT-OR <spfunction4>  BIT-OR <spfunction6>  BIT-OR <spfunction8>
BIT-OR <spfunction1>  BIT-OR <spfunction3>  BIT-OR <spfunction5>  BIT-OR <spfunction7>.
        <right> = <temp> BIT-XOR <temp4_i>.
i = i + loopinc.
ENDWHILE.
"最后一次完成异或后不交换位置
      temp = left.
left = right.
      right = temp.
      j = j + 3.
ENDWHILE.
PERFORM rshfit_i USING left 1 temp1_i.
PERFORM lshfit_i USING left 31 temp2_i.
    <left> = <temp1_i> BIT-OR <temp2_i>.
PERFORM rshfit_i USING right 1 temp1_i.
PERFORM lshfit_i USING right 31 temp2_i.
    <right> = <temp1_i> BIT-OR <temp2_i>.
*==========================
"根据逆置换规则表进行逆置换得到64位密文
PERFORM rshfit_i USING left 1 temp1_i.
    <temp1_i> = <temp1_i> BIT-XOR <right>.
    x4 = '55555555'.
    temp2_i = x4.
    <temp> = <temp1_i> BIT-AND <temp2_i>.
    <right> = <right> BIT-XOR <temp>.
PERFORM lshfit_i USING temp 1 temp1_i.
    <left> = <left> BIT-XOR <temp1_i>.
PERFORM rshfit_i USING right 8 temp1_i.
    <temp1_i> = <temp1_i> BIT-XOR <left>.
    x4 = '00FF00FF'.
    temp2_i = x4.
    <temp> = <temp1_i> BIT-AND <temp2_i>.
    <left> = <left> BIT-XOR <temp>.
PERFORM lshfit_i USING temp 8 temp1_i.
    <right> = <right> BIT-XOR <temp1_i>.
PERFORM rshfit_i USING right 2 temp1_i.
    <temp1_i> = <temp1_i> BIT-XOR <left>.
    x4 = '33333333'.
    temp2_i = x4.
    <temp> = <temp1_i> BIT-AND <temp2_i>.
    <left> = <left> BIT-XOR <temp>.
PERFORM lshfit_i USING temp 2 temp1_i.
    <right> = <right> BIT-XOR <temp1_i>.
PERFORM rshfit_i USING left 16 temp1_i.
    <temp1_i> = <temp1_i> BIT-XOR <right>.
    x4 = '0000FFFF'.
    temp2_i = x4.
    <temp> = <temp1_i> BIT-AND <temp2_i>.
    <right> = <right> BIT-XOR <temp>.
PERFORM lshfit_i USING temp 16 temp1_i.
    <left> = <left> BIT-XOR <temp1_i>.
PERFORM rshfit_i USING left 4 temp1_i.
    <temp1_i> = <temp1_i> BIT-XOR <right>.
    x4 = '0F0F0F0F'.
    temp2_i = x4.
    <temp> = <temp1_i> BIT-AND <temp2_i>.
    <right> = <right> BIT-XOR <temp>.
PERFORM lshfit_i USING temp 4 temp1_i.
    <left> = <left> BIT-XOR <temp1_i>.
*==========================
IF mode = 1."CBC密码块链接模式下,将本次加密结果存回cbcleft、cbcright,供下一轮加密解密使用
IF encrypt = 1.
        cbcleft = left.
        cbcright = right.
ELSE.
        <left> = <left> BIT-XOR <cbcleft2>.
        <right> = <right> BIT-XOR <cbcright2>.
ENDIF.
ENDIF.
*==========================
PERFORM rshfit_i USING left 24 temp1_i.
PERFORM int2c USING temp1_i c1.
CONCATENATE tempresult c1 INTO tempresult SEPARATED BY `` RESPECTING BLANKS.
PERFORM rshfit_i USING left 16 temp1_i.
    x4 = '000000FF'.
    temp2_i = x4.
    <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
PERFORM int2c USING temp3_i c1.
CONCATENATE tempresult c1 INTO tempresult SEPARATED BY `` RESPECTING BLANKS.
PERFORM rshfit_i USING left 8 temp1_i.
*    x4 = '000000FF'.
*    temp2_i = x4.
    <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
PERFORM int2c USING temp3_i c1.
CONCATENATE tempresult c1 INTO tempresult SEPARATED BY ``RESPECTING BLANKS.
*    x4 = '000000FF'.
*    temp2_i = x4.
    <temp3_i> = <left> BIT-AND <temp2_i>.
PERFORM int2c USING temp3_i c1.
CONCATENATE tempresult c1 INTO tempresult SEPARATED BY `` RESPECTING BLANKS.
PERFORM rshfit_i USING right 24 temp1_i.
PERFORM int2c USING temp1_i c1.
CONCATENATE tempresult c1 INTO tempresult SEPARATED BY `` RESPECTING BLANKS.
PERFORM rshfit_i USING right 16 temp1_i.
*    x4 = '000000FF'.
*    temp2_i = x4.
    <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
PERFORM int2c USING temp3_i c1.
CONCATENATE tempresult c1 INTO tempresult SEPARATED BY `` RESPECTING BLANKS.
PERFORM rshfit_i USING right 8 temp1_i.
*    x4 = '000000FF'.
*    temp2_i = x4.
    <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
PERFORM int2c USING temp3_i c1.
CONCATENATE tempresult c1 INTO tempresult SEPARATED BY `` RESPECTING BLANKS.
*    x4 = '000000FF'.
*    temp2_i = x4.
    <temp3_i> = <right> BIT-AND <temp2_i>.
PERFORM int2c USING temp3_i c1.
CONCATENATE tempresult c1 INTO tempresult SEPARATED BY `` RESPECTING BLANKS.
    chunk = chunk + 8.
IF chunk = 512.
*      CONCATENATE result tempresult INTO result SEPARATED BY `` RESPECTING BLANKS.
CONCATENATE result tempresult INTO result SEPARATED BY ``.
      tempresult = ''.
      chunk = 0.
ENDIF.
ENDWHILE.
初次加密解密出来的结果
CONCATENATE result tempresult INTO result SEPARATED BY ``.
DATA: paddingchars TYPE i.
IF encrypt = 0."如果是解密
IF padding = 1."且填充模式是PKCS5padding时,去掉尾部填充
      len = STRLEN( result ).
index = len - 1.
      c1 = result+index.
PERFORM c2int USING c1 paddingchars.
IF paddingchars <= 8.
        len = len - paddingchars.
        result = result+0(len).
ENDIF.
ENDIF.
ENDIF.
"转十六进输出
DATA: x1(1) TYPE x.
  len = STRLEN( result ).
index = 0.
WHILE index < len.
    c1 = result+index(1).
    x1 = <c1>.
    c2 = x1.
CONCATENATE output c2 INTO output SEPARATED BY ``.
index = index + 1.
ENDWHILE.
ENDFORM.                                                    "3des
*&---------------------------------------------------------------------*
*&      Form  get_keys
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->KEY        text
*----------------------------------------------------------------------*
FORM get_keys USING key TYPE string .
DATA: c1 TYPE c.
FIELD-SYMBOLS <c1> TYPE x.
ASSIGN c1 TO <c1> CASTING.
DATA: x1 TYPE x.
DATA: x4(4) TYPE x.
DATA: i TYPE i.
DATA: tmpstr TYPE string VALUE ''.
DATA: index TYPE i VALUE 0.
DATA: keylen TYPE i.
CLEAR:keys,keys[].
DATA: pc2bytes0 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes0.
  x4 = '00000004'. i = x4. APPEND i TO pc2bytes0.
  x4 = '20000000'. i = x4. APPEND i TO pc2bytes0.
  x4 = '20000004'. i = x4. APPEND i TO pc2bytes0.
  x4 = '00010000'. i = x4. APPEND i TO pc2bytes0.
  x4 = '00010004'. i = x4. APPEND i TO pc2bytes0.
  x4 = '20010000'. i = x4. APPEND i TO pc2bytes0.
  x4 = '20010004'. i = x4. APPEND i TO pc2bytes0.
  x4 = '00000200'. i = x4. APPEND i TO pc2bytes0.
  x4 = '00000204'. i = x4. APPEND i TO pc2bytes0.
  x4 = '20000200'. i = x4. APPEND i TO pc2bytes0.
  x4 = '20000204'. i = x4. APPEND i TO pc2bytes0.
  x4 = '00010200'. i = x4. APPEND i TO pc2bytes0.
  x4 = '00010204'. i = x4. APPEND i TO pc2bytes0.
  x4 = '20010200'. i = x4. APPEND i TO pc2bytes0.
  x4 = '20010204'. i = x4. APPEND i TO pc2bytes0.
DATA: pc2bytes1 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes1.
  x4 = '00000001'. i = x4. APPEND i TO pc2bytes1.
  x4 = '00100000'. i = x4. APPEND i TO pc2bytes1.
  x4 = '00100001'. i = x4. APPEND i TO pc2bytes1.
  x4 = '04000000'. i = x4. APPEND i TO pc2bytes1.
  x4 = '04000001'. i = x4. APPEND i TO pc2bytes1.
  x4 = '04100000'. i = x4. APPEND i TO pc2bytes1.
  x4 = '04100001'. i = x4. APPEND i TO pc2bytes1.
  x4 = '00000100'. i = x4. APPEND i TO pc2bytes1.
  x4 = '00000101'. i = x4. APPEND i TO pc2bytes1.
  x4 = '00100100'. i = x4. APPEND i TO pc2bytes1.
  x4 = '00100101'. i = x4. APPEND i TO pc2bytes1.
  x4 = '04000100'. i = x4. APPEND i TO pc2bytes1.
  x4 = '04000101'. i = x4. APPEND i TO pc2bytes1.
  x4 = '04100100'. i = x4. APPEND i TO pc2bytes1.
  x4 = '04100101'. i = x4. APPEND i TO pc2bytes1.
DATA: pc2bytes2 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes2.
  x4 = '00000008'. i = x4. APPEND i TO pc2bytes2.
  x4 = '00000800'. i = x4. APPEND i TO pc2bytes2.
  x4 = '00000808'. i = x4. APPEND i TO pc2bytes2.
  x4 = '01000000'. i = x4. APPEND i TO pc2bytes2.
  x4 = '01000008'. i = x4. APPEND i TO pc2bytes2.
  x4 = '01000800'. i = x4. APPEND i TO pc2bytes2.
  x4 = '01000808'. i = x4. APPEND i TO pc2bytes2.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes2.
  x4 = '00000008'. i = x4. APPEND i TO pc2bytes2.
  x4 = '00000800'. i = x4. APPEND i TO pc2bytes2.
  x4 = '00000808'. i = x4. APPEND i TO pc2bytes2.
  x4 = '01000000'. i = x4. APPEND i TO pc2bytes2.
  x4 = '01000008'. i = x4. APPEND i TO pc2bytes2.
  x4 = '01000800'. i = x4. APPEND i TO pc2bytes2.
  x4 = '01000808'. i = x4. APPEND i TO pc2bytes2.
DATA: pc2bytes3 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes3.
  x4 = '00200000'. i = x4. APPEND i TO pc2bytes3.
  x4 = '08000000'. i = x4. APPEND i TO pc2bytes3.
  x4 = '08200000'. i = x4. APPEND i TO pc2bytes3.
  x4 = '00002000'. i = x4. APPEND i TO pc2bytes3.
  x4 = '00202000'. i = x4. APPEND i TO pc2bytes3.
  x4 = '08002000'. i = x4. APPEND i TO pc2bytes3.
  x4 = '08202000'. i = x4. APPEND i TO pc2bytes3.
  x4 = '00020000'. i = x4. APPEND i TO pc2bytes3.
  x4 = '00220000'. i = x4. APPEND i TO pc2bytes3.
  x4 = '08020000'. i = x4. APPEND i TO pc2bytes3.
  x4 = '08220000'. i = x4. APPEND i TO pc2bytes3.
  x4 = '00022000'. i = x4. APPEND i TO pc2bytes3.
  x4 = '00222000'. i = x4. APPEND i TO pc2bytes3.
  x4 = '08022000'. i = x4. APPEND i TO pc2bytes3.
  x4 = '08222000'. i = x4. APPEND i TO pc2bytes3.
DATA: pc2bytes4 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes4.
  x4 = '00040000'. i = x4. APPEND i TO pc2bytes4.
  x4 = '00000010'. i = x4. APPEND i TO pc2bytes4.
  x4 = '00040010'. i = x4. APPEND i TO pc2bytes4.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes4.
  x4 = '00040000'. i = x4. APPEND i TO pc2bytes4.
  x4 = '00000010'. i = x4. APPEND i TO pc2bytes4.
  x4 = '00040010'. i = x4. APPEND i TO pc2bytes4.
  x4 = '00001000'. i = x4. APPEND i TO pc2bytes4.
  x4 = '00041000'. i = x4. APPEND i TO pc2bytes4.
  x4 = '00001010'. i = x4. APPEND i TO pc2bytes4.
  x4 = '00041010'. i = x4. APPEND i TO pc2bytes4.
  x4 = '00001000'. i = x4. APPEND i TO pc2bytes4.
  x4 = '00041000'. i = x4. APPEND i TO pc2bytes4.
  x4 = '00001010'. i = x4. APPEND i TO pc2bytes4.
  x4 = '00041010'. i = x4. APPEND i TO pc2bytes4.
DATA: pc2bytes5 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes5.
  x4 = '00000400'. i = x4. APPEND i TO pc2bytes5.
  x4 = '00000020'. i = x4. APPEND i TO pc2bytes5.
  x4 = '00000420'. i = x4. APPEND i TO pc2bytes5.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes5.
  x4 = '00000400'. i = x4. APPEND i TO pc2bytes5.
  x4 = '00000020'. i = x4. APPEND i TO pc2bytes5.
  x4 = '00000420'. i = x4. APPEND i TO pc2bytes5.
  x4 = '02000000'. i = x4. APPEND i TO pc2bytes5.
  x4 = '02000400'. i = x4. APPEND i TO pc2bytes5.
  x4 = '02000020'. i = x4. APPEND i TO pc2bytes5.
  x4 = '02000420'. i = x4. APPEND i TO pc2bytes5.
  x4 = '02000000'. i = x4. APPEND i TO pc2bytes5.
  x4 = '02000400'. i = x4. APPEND i TO pc2bytes5.
  x4 = '02000020'. i = x4. APPEND i TO pc2bytes5.
  x4 = '02000420'. i = x4. APPEND i TO pc2bytes5.
DATA: pc2bytes6 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes6.
  x4 = '10000000'. i = x4. APPEND i TO pc2bytes6.
  x4 = '00080000'. i = x4. APPEND i TO pc2bytes6.
  x4 = '10080000'. i = x4. APPEND i TO pc2bytes6.
  x4 = '00000002'. i = x4. APPEND i TO pc2bytes6.
  x4 = '10000002'. i = x4. APPEND i TO pc2bytes6.
  x4 = '00080002'. i = x4. APPEND i TO pc2bytes6.
  x4 = '10080002'. i = x4. APPEND i TO pc2bytes6.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes6.
  x4 = '10000000'. i = x4. APPEND i TO pc2bytes6.
  x4 = '00080000'. i = x4. APPEND i TO pc2bytes6.
  x4 = '10080000'. i = x4. APPEND i TO pc2bytes6.
  x4 = '00000002'. i = x4. APPEND i TO pc2bytes6.
  x4 = '10000002'. i = x4. APPEND i TO pc2bytes6.
  x4 = '00080002'. i = x4. APPEND i TO pc2bytes6.
  x4 = '10080002'. i = x4. APPEND i TO pc2bytes6.
DATA: pc2bytes7 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes7.
  x4 = '00010000'. i = x4. APPEND i TO pc2bytes7.
  x4 = '00000800'. i = x4. APPEND i TO pc2bytes7.
  x4 = '00010800'. i = x4. APPEND i TO pc2bytes7.
  x4 = '20000000'. i = x4. APPEND i TO pc2bytes7.
  x4 = '20010000'. i = x4. APPEND i TO pc2bytes7.
  x4 = '20000800'. i = x4. APPEND i TO pc2bytes7.
  x4 = '20010800'. i = x4. APPEND i TO pc2bytes7.
  x4 = '00020000'. i = x4. APPEND i TO pc2bytes7.
  x4 = '00030000'. i = x4. APPEND i TO pc2bytes7.
  x4 = '00020800'. i = x4. APPEND i TO pc2bytes7.
  x4 = '00030800'. i = x4. APPEND i TO pc2bytes7.
  x4 = '20020000'. i = x4. APPEND i TO pc2bytes7.
  x4 = '20030000'. i = x4. APPEND i TO pc2bytes7.
  x4 = '20020800'. i = x4. APPEND i TO pc2bytes7.
  x4 = '20030800'. i = x4. APPEND i TO pc2bytes7.
DATA: pc2bytes8 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes8.
  x4 = '00040000'. i = x4. APPEND i TO pc2bytes8.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes8.
  x4 = '00040000'. i = x4. APPEND i TO pc2bytes8.
  x4 = '00000002'. i = x4. APPEND i TO pc2bytes8.
  x4 = '00040002'. i = x4. APPEND i TO pc2bytes8.
  x4 = '00000002'. i = x4. APPEND i TO pc2bytes8.
  x4 = '00040002'. i = x4. APPEND i TO pc2bytes8.
  x4 = '02000000'. i = x4. APPEND i TO pc2bytes8.
  x4 = '02040000'. i = x4. APPEND i TO pc2bytes8.
  x4 = '02000000'. i = x4. APPEND i TO pc2bytes8.
  x4 = '02040000'. i = x4. APPEND i TO pc2bytes8.
  x4 = '02000002'. i = x4. APPEND i TO pc2bytes8.
  x4 = '02040002'. i = x4. APPEND i TO pc2bytes8.
  x4 = '02000002'. i = x4. APPEND i TO pc2bytes8.
  x4 = '02040002'. i = x4. APPEND i TO pc2bytes8.
DATA: pc2bytes9 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes9.
  x4 = '10000000'. i = x4. APPEND i TO pc2bytes9.
  x4 = '00000008'. i = x4. APPEND i TO pc2bytes9.
  x4 = '10000008'. i = x4. APPEND i TO pc2bytes9.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes9.
  x4 = '10000000'. i = x4. APPEND i TO pc2bytes9.
  x4 = '00000008'. i = x4. APPEND i TO pc2bytes9.
  x4 = '10000008'. i = x4. APPEND i TO pc2bytes9.
  x4 = '00000400'. i = x4. APPEND i TO pc2bytes9.
  x4 = '10000400'. i = x4. APPEND i TO pc2bytes9.
  x4 = '00000408'. i = x4. APPEND i TO pc2bytes9.
  x4 = '10000408'. i = x4. APPEND i TO pc2bytes9.
  x4 = '00000400'. i = x4. APPEND i TO pc2bytes9.
  x4 = '10000400'. i = x4. APPEND i TO pc2bytes9.
  x4 = '00000408'. i = x4. APPEND i TO pc2bytes9.
  x4 = '10000408'. i = x4. APPEND i TO pc2bytes9.
DATA: pc2bytes10 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes10.
  x4 = '00000020'. i = x4. APPEND i TO pc2bytes10.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes10.
  x4 = '00000020'. i = x4. APPEND i TO pc2bytes10.
  x4 = '00100000'. i = x4. APPEND i TO pc2bytes10.
  x4 = '00100020'. i = x4. APPEND i TO pc2bytes10.
  x4 = '00100000'. i = x4. APPEND i TO pc2bytes10.
  x4 = '00100020'. i = x4. APPEND i TO pc2bytes10.
  x4 = '00002000'. i = x4. APPEND i TO pc2bytes10.
  x4 = '00002020'. i = x4. APPEND i TO pc2bytes10.
  x4 = '00002000'. i = x4. APPEND i TO pc2bytes10.
  x4 = '00002020'. i = x4. APPEND i TO pc2bytes10.
  x4 = '00102000'. i = x4. APPEND i TO pc2bytes10.
  x4 = '00102020'. i = x4. APPEND i TO pc2bytes10.
  x4 = '00102000'. i = x4. APPEND i TO pc2bytes10.
  x4 = '00102020'. i = x4. APPEND i TO pc2bytes10.
DATA: pc2bytes11 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes11.
  x4 = '01000000'. i = x4. APPEND i TO pc2bytes11.
  x4 = '00000200'. i = x4. APPEND i TO pc2bytes11.
  x4 = '01000200'. i = x4. APPEND i TO pc2bytes11.
  x4 = '00200000'. i = x4. APPEND i TO pc2bytes11.
  x4 = '01200000'. i = x4. APPEND i TO pc2bytes11.
  x4 = '00200200'. i = x4. APPEND i TO pc2bytes11.
  x4 = '01200200'. i = x4. APPEND i TO pc2bytes11.
  x4 = '04000000'. i = x4. APPEND i TO pc2bytes11.
  x4 = '05000000'. i = x4. APPEND i TO pc2bytes11.
  x4 = '04000200'. i = x4. APPEND i TO pc2bytes11.
  x4 = '05000200'. i = x4. APPEND i TO pc2bytes11.
  x4 = '04200000'. i = x4. APPEND i TO pc2bytes11.
  x4 = '05200000'. i = x4. APPEND i TO pc2bytes11.
  x4 = '04200200'. i = x4. APPEND i TO pc2bytes11.
  x4 = '05200200'. i = x4. APPEND i TO pc2bytes11.
DATA: pc2bytes12 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes12.
  x4 = '00001000'. i = x4. APPEND i TO pc2bytes12.
  x4 = '08000000'. i = x4. APPEND i TO pc2bytes12.
  x4 = '08001000'. i = x4. APPEND i TO pc2bytes12.
  x4 = '00080000'. i = x4. APPEND i TO pc2bytes12.
  x4 = '00081000'. i = x4. APPEND i TO pc2bytes12.
  x4 = '08080000'. i = x4. APPEND i TO pc2bytes12.
  x4 = '08081000'. i = x4. APPEND i TO pc2bytes12.
  x4 = '00000010'. i = x4. APPEND i TO pc2bytes12.
  x4 = '00001010'. i = x4. APPEND i TO pc2bytes12.
  x4 = '08000010'. i = x4. APPEND i TO pc2bytes12.
  x4 = '08001010'. i = x4. APPEND i TO pc2bytes12.
  x4 = '00080010'. i = x4. APPEND i TO pc2bytes12.
  x4 = '00081010'. i = x4. APPEND i TO pc2bytes12.
  x4 = '08080010'. i = x4. APPEND i TO pc2bytes12.
  x4 = '08081010'. i = x4. APPEND i TO pc2bytes12.
DATA: pc2bytes13 TYPE TABLE OF i WITH HEADER LINE.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes13.
  x4 = '00000004'. i = x4. APPEND i TO pc2bytes13.
  x4 = '00000100'. i = x4. APPEND i TO pc2bytes13.
  x4 = '00000104'. i = x4. APPEND i TO pc2bytes13.
  x4 = '00000000'. i = x4. APPEND i TO pc2bytes13.
  x4 = '00000004'. i = x4. APPEND i TO pc2bytes13.
  x4 = '00000100'. i = x4. APPEND i TO pc2bytes13.
  x4 = '00000104'. i = x4. APPEND i TO pc2bytes13.
  x4 = '00000001'. i = x4. APPEND i TO pc2bytes13.
  x4 = '00000005'. i = x4. APPEND i TO pc2bytes13.
  x4 = '00000101'. i = x4. APPEND i TO pc2bytes13.
  x4 = '00000105'. i = x4. APPEND i TO pc2bytes13.
  x4 = '00000001'. i = x4. APPEND i TO pc2bytes13.
  x4 = '00000005'. i = x4. APPEND i TO pc2bytes13.
  x4 = '00000101'. i = x4. APPEND i TO pc2bytes13.
  x4 = '00000105'. i = x4. APPEND i TO pc2bytes13.
  keylen = STRLEN( key ).
"将十六进制字符串转换为普通字符串
WHILE index <  keylen.
    <c1> = key+index(2).
CONCATENATE tmpstr c1 INTO tmpstr SEPARATED BY `` RESPECTING BLANKS.
index = index + 2.
ENDWHILE.
key = tmpstr.
  keylen = STRLEN( key ).
DATA: i1 TYPE i.
  i1 = keylen.
"key串不足24个字符时补0字符
WHILE i1 < 24.
*    CONCATENATE key '0' INTO key SEPARATED BY `` RESPECTING BLANKS.
CONCATENATE key '0' INTO key SEPARATED BY ``.
    i1 = i1 + 1.
ENDWHILE.
DATA: iterations TYPE i.
  keylen = STRLEN( key ).
IF keylen >  8 .
    iterations = 3.
ELSE.
    iterations = 1.
ENDIF.
DATA: shifts TYPE TABLE OF i WITH HEADER LINE.
APPEND 0 TO shifts.
APPEND 0 TO shifts.
APPEND 1 TO shifts.
APPEND 1 TO shifts.
APPEND 1 TO shifts.
APPEND 1 TO shifts.
APPEND 1 TO shifts.
APPEND 1 TO shifts.
APPEND 0 TO shifts.
APPEND 1 TO shifts.
APPEND 1 TO shifts.
APPEND 1 TO shifts.
APPEND 1 TO shifts.
APPEND 1 TO shifts.
APPEND 1 TO shifts.
APPEND 0 TO shifts.
DATA: lefttemp TYPE i ,righttemp TYPE i,m TYPE i,n TYPE i,temp TYPE i.
FIELD-SYMBOLS: <lefttemp> TYPE x,<righttemp> TYPE x.
DATA:lefttemp_x4(4) TYPE x,righttemp_x4(4) TYPE x.
DATA: j TYPE i VALUE 0.
DATA: left_c32(32) TYPE c,left_c32_1(32) TYPE c,left_c32_2(32) TYPE c,left_c32_3(32) TYPE c,left_c32_4(32) TYPE c.
DATA: left_i TYPE i,left_i_1 TYPE i,left_i_2 TYPE i,left_i_3 TYPE i,left_i_4 TYPE i.
FIELD-SYMBOLS: <left_i_1> TYPE x,<left_i_2> TYPE x,<left_i_3> TYPE x,<left_i_4> TYPE x.
DATA: left_x(4) TYPE x.
DATA: right_c32(32) TYPE c,right_c32_1(32) TYPE c,right_c32_2(32) TYPE c,right_c32_3(32) TYPE c,right_c32_4(32) TYPE c.
DATA: right_i TYPE i,right_i_1 TYPE i,right_i_2 TYPE i,right_i_3 TYPE i,right_i_4 TYPE i.
FIELD-SYMBOLS: <right_i_1> TYPE x,<right_i_2> TYPE x,<right_i_3> TYPE x,<right_i_4> TYPE x.
DATA: right_x(4) TYPE x.
DATA: left TYPE i,right TYPE i.
FIELD-SYMBOLS:<left> TYPE x,<right> TYPE x.
DATA:i_tmp1 TYPE i,i_tmp2 TYPE i,x_tmp1(4) TYPE x,x_tmp2(4) TYPE x,x_tmp3(4) TYPE x.
FIELD-SYMBOLS:<i_tmp1> TYPE x,<i_tmp2> TYPE x,<temp> TYPE x.
FIELD-SYMBOLS: <pc2bytes0> TYPE x,<pc2bytes2> TYPE x,<pc2bytes3> TYPE x,<pc2bytes4> TYPE x,<pc2bytes5> TYPE x,<pc2bytes6> TYPE x,
  <pc2bytes7> TYPE x,<pc2bytes8> TYPE x,<pc2bytes9> TYPE x,<pc2bytes10> TYPE x,<pc2bytes11> TYPE x,<pc2bytes12> TYPE x,
  <pc2bytes13> TYPE x,<pc2bytes1> TYPE x.
ASSIGN left_i_1 TO <left_i_1> CASTING.
ASSIGN left_i_2 TO <left_i_2> CASTING.
ASSIGN left_i_3 TO <left_i_3> CASTING.
ASSIGN left_i_4 TO <left_i_4> CASTING.
ASSIGN right_i_1 TO <right_i_1> CASTING.
ASSIGN right_i_2 TO <right_i_2> CASTING.
ASSIGN right_i_3 TO <right_i_3> CASTING.
ASSIGN right_i_4 TO <right_i_4> CASTING.
ASSIGN i_tmp1 TO <i_tmp1> CASTING.
ASSIGN i_tmp2 TO <i_tmp2> CASTING.
ASSIGN right TO <right> CASTING.
ASSIGN temp TO <temp> CASTING.
ASSIGN left TO <left> CASTING.
ASSIGN pc2bytes0 TO <pc2bytes0> CASTING.
ASSIGN pc2bytes1 TO <pc2bytes1> CASTING.
ASSIGN pc2bytes2 TO <pc2bytes2> CASTING.
ASSIGN pc2bytes3 TO <pc2bytes3> CASTING.
ASSIGN pc2bytes4 TO <pc2bytes4> CASTING.
ASSIGN pc2bytes5 TO <pc2bytes5> CASTING.
ASSIGN pc2bytes6 TO <pc2bytes6> CASTING.
ASSIGN pc2bytes7 TO <pc2bytes7> CASTING.
ASSIGN pc2bytes8 TO <pc2bytes8> CASTING.
ASSIGN pc2bytes9 TO <pc2bytes9> CASTING.
ASSIGN pc2bytes10 TO <pc2bytes10> CASTING.
ASSIGN pc2bytes11 TO <pc2bytes11> CASTING.
ASSIGN pc2bytes12 TO <pc2bytes12> CASTING.
ASSIGN pc2bytes13 TO <pc2bytes13> CASTING.
ASSIGN lefttemp TO <lefttemp> CASTING.
ASSIGN righttemp TO <righttemp> CASTING.
DATA: temp1_i TYPE i,temp2_i TYPE i,temp3_i TYPE i,temp4_i TYPE i,temp5_i TYPE i,temp6_i TYPE i,temp7_i TYPE i,temp8_i TYPE i.
FIELD-SYMBOLS: <temp1_i> TYPE x, <temp2_i> TYPE x, <temp3_i> TYPE x, <temp4_i> TYPE x, <temp5_i> TYPE x, <temp6_i> TYPE x, <temp7_i> TYPE x, <temp8_i> TYPE x.
ASSIGN temp1_i TO <temp1_i> CASTING.
ASSIGN temp2_i TO <temp2_i> CASTING.
ASSIGN temp3_i TO <temp3_i> CASTING.
ASSIGN temp4_i TO <temp4_i> CASTING.
ASSIGN temp5_i TO <temp5_i> CASTING.
ASSIGN temp6_i TO <temp6_i> CASTING.
ASSIGN temp7_i TO <temp7_i> CASTING.
ASSIGN temp8_i TO <temp8_i> CASTING.
WHILE  j < iterations.
    c1 = key+m(1).
PERFORM lshfit_c USING c1 24 left_i_1.
m = m + 1.
    c1 = key+m(1).
PERFORM lshfit_c USING c1 16 left_i_2.
m = m + 1.
    c1 = key+m(1).
PERFORM lshfit_c USING c1 8 left_i_3.
m = m + 1.
    c1 = key+m(1).
PERFORM c2int USING c1 left_i_4.
m = m + 1.
    left_x = <left_i_1> BIT-OR <left_i_2> BIT-OR <left_i_3> BIT-OR <left_i_4>.
    <left> = left_x.
*==========================
    c1 = key+m(1).
PERFORM lshfit_c USING c1 24 right_i_1.
m = m + 1.
    c1 = key+m(1).
PERFORM lshfit_c USING c1 16 right_i_2.
m = m + 1.
    c1 = key+m(1).
PERFORM lshfit_c USING c1 8 right_i_3.
m = m + 1.
    c1 = key+m(1).
PERFORM c2int USING c1 right_i_4.
m = m + 1.
    right_x = <right_i_1> BIT-OR <right_i_2> BIT-OR <right_i_3> BIT-OR <right_i_4>.
    <right> = right_x.
*==========================
PERFORM rshfit_i USING left 4 temp1_i.
    <temp2_i> = <temp1_i> BIT-XOR <right>.
    x4 = '0F0F0F0F'.
    temp3_i = x4.
    <temp> = <temp2_i> BIT-AND <temp3_i>.
    <right> = <right> BIT-XOR <temp>.
PERFORM lshfit_i USING temp 4 i_tmp2.
    <left> = <left> BIT-XOR <i_tmp2>.
PERFORM rshfit_i USING right -16 temp1_i.
    <temp2_i> = <temp1_i> BIT-XOR <left>.
    x4 = '0000FFFF'.
    temp3_i = x4.
    <temp> = <temp2_i> BIT-AND <temp3_i>.
    <left> = <left> BIT-XOR <temp>.
PERFORM lshfit_i USING temp -16 i_tmp2.
    <right> = <right> BIT-XOR <i_tmp2>.
PERFORM rshfit_i USING left 2 temp1_i.
    <temp2_i> = <temp1_i> BIT-XOR <right>.
    x4 = '33333333'.
    temp3_i = x4.
    <temp> = <temp2_i> BIT-AND <temp3_i>.
    <right> = <right> BIT-XOR <temp>.
PERFORM lshfit_i USING temp 2 i_tmp2.
    <left> = <left> BIT-XOR <i_tmp2>.
PERFORM rshfit_i USING right -16 temp1_i.
    <temp2_i> = <temp1_i> BIT-XOR <left>.
    x4 = '0000FFFF'.
    temp3_i = x4.
    <temp> = <temp2_i> BIT-AND <temp3_i>.
    <left> = <left> BIT-XOR <temp>.
PERFORM lshfit_i USING temp -16 i_tmp2.
    <right> = <right> BIT-XOR <i_tmp2>.
PERFORM rshfit_i USING left 1 temp1_i.
    <temp2_i> = <temp1_i> BIT-XOR <right>.
    x4 = '55555555'.
    temp3_i = x4.
    <temp> = <temp2_i> BIT-AND <temp3_i>.
    <right> = <right> BIT-XOR <temp>.
PERFORM lshfit_i USING temp 1 i_tmp2.
    <left> = <left> BIT-XOR <i_tmp2>.
PERFORM rshfit_i USING right 8 temp1_i.
    <temp2_i> = <temp1_i> BIT-XOR <left>.
    x4 = '00FF00FF'.
    temp3_i = x4.
    <temp> = <temp2_i> BIT-AND <temp3_i>.
    <left> = <left> BIT-XOR <temp>.
PERFORM lshfit_i USING temp 8 i_tmp2.
    <right> = <right> BIT-XOR <i_tmp2>.
PERFORM rshfit_i USING left 1 temp1_i.
    <temp2_i> = <temp1_i> BIT-XOR <right>.
    x4 = '55555555'.
    temp3_i = x4.
    <temp> = <temp2_i> BIT-AND <temp3_i>.
    <right> = <right> BIT-XOR <temp>.
PERFORM lshfit_i USING temp 1 i_tmp2.
    <left> = <left> BIT-XOR <i_tmp2>.
*==========================
PERFORM rshfit_i USING right 20 temp1_i.
    x4 = '000000F0'.
    temp2_i = x4.
    <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
PERFORM lshfit_i USING left 8 temp4_i.
    <temp> = <temp4_i> BIT-OR <temp3_i>.
PERFORM lshfit_i USING right 24 temp1_i.
PERFORM lshfit_i USING right 8 temp2_i.
    x4 = '00FF0000'.
    temp3_i = x4.
    <temp4_i> = <temp2_i> BIT-AND <temp3_i>.
    <temp5_i> = <temp1_i> BIT-OR <temp4_i>.
PERFORM rshfit_i USING right 8 temp2_i.
    x4 = '0000FF00'.
    temp3_i = x4.
    <temp4_i> = <temp2_i> BIT-AND <temp3_i>.
    <temp5_i> = <temp5_i> BIT-OR <temp4_i>.
PERFORM rshfit_i USING right 24 temp2_i.
    x4 = '000000F0'.
    temp3_i = x4.
    <temp4_i> = <temp2_i> BIT-AND <temp3_i>.
    <temp5_i> = <temp5_i> BIT-OR <temp4_i>.
left = temp5_i.
    right = temp.
*==========================
index = 1.
WHILE index <= 16.
*      CLEAR:shifts.
READ TABLE shifts INDEX index.
IF shifts = 1.
PERFORM lshfit_i USING left 2 i_tmp1.
PERFORM rshfit_i USING left 26 i_tmp2.
        <left> = <i_tmp1> BIT-OR <i_tmp2>.
PERFORM lshfit_i USING right 2 i_tmp1.
PERFORM rshfit_i USING right 26 i_tmp2.
        <right> = <i_tmp1> BIT-OR <i_tmp2>.
ELSE.
PERFORM lshfit_i USING left 1 i_tmp1.
PERFORM rshfit_i USING left 27 i_tmp2.
        <left> = <i_tmp1> BIT-OR <i_tmp2>.
PERFORM lshfit_i USING right 1 i_tmp1.
PERFORM rshfit_i USING right 27 i_tmp2.
        <right> = <i_tmp1> BIT-OR <i_tmp2>.
ENDIF.
      x4 = 'FFFFFFF1'.
      temp1_i = x4.                                         " -15
      <left> = <left> BIT-AND <temp1_i>.
*      x4 = 'FFFFFFF1'.                                      " -15
*      temp1_i = x4.
      <right> = <right> BIT-AND <temp1_i>.
*==========================
PERFORM rshfit_i USING left 28 i_tmp1.
      i_tmp1 = i_tmp1 + 1.
READ TABLE pc2bytes0 INDEX i_tmp1.
PERFORM rshfit_i USING left 24 temp1_i.
      x4 = '0000000F'.
      temp2_i = x4.
      <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
      temp3_i = temp3_i + 1.
READ TABLE pc2bytes1 INDEX temp3_i.
PERFORM rshfit_i USING left 20 temp1_i.
*      x4 = '0000000F'.
*      temp2_i = x4.
      <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
      temp3_i = temp3_i + 1.
READ TABLE pc2bytes2 INDEX temp3_i.
PERFORM rshfit_i USING left 16 temp1_i.
*      x4 = '0000000F'.
*      temp2_i = x4.
      <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
      temp3_i = temp3_i + 1.
READ TABLE pc2bytes3 INDEX temp3_i.
PERFORM rshfit_i USING left 12 temp1_i.
*      x4 = '0000000F'.
*      temp2_i = x4.
      <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
      temp3_i = temp3_i + 1.
READ TABLE pc2bytes4 INDEX temp3_i.
PERFORM rshfit_i USING left 8 temp1_i.
*      x4 = '0000000F'.
*      temp2_i = x4.
      <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
      temp3_i = temp3_i + 1.
READ TABLE pc2bytes5 INDEX temp3_i.
PERFORM rshfit_i USING left 4 temp1_i.
*      x4 = '0000000F'.
*      temp2_i = x4.
      <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
      temp3_i = temp3_i + 1.
READ TABLE pc2bytes6 INDEX temp3_i.
      <lefttemp> = <pc2bytes0> BIT-OR <pc2bytes1> BIT-OR <pc2bytes2> BIT-OR <pc2bytes3>
BIT-OR <pc2bytes4> BIT-OR <pc2bytes5> BIT-OR <pc2bytes6>.
*==========================
PERFORM rshfit_i USING right 28 i_tmp1.
      i_tmp1 = i_tmp1 + 1.
READ TABLE pc2bytes7 INDEX i_tmp1.
PERFORM rshfit_i USING right 24 temp1_i.
*      x4 = '0000000F'.
*      temp2_i = x4.
      <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
      temp3_i = temp3_i + 1.
READ TABLE pc2bytes8 INDEX temp3_i.
PERFORM rshfit_i USING right 20 temp1_i.
*      x4 = '0000000F'.
*      temp2_i = x4.
      <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
      temp3_i = temp3_i + 1.
READ TABLE pc2bytes9 INDEX temp3_i.
PERFORM rshfit_i USING right 16 temp1_i.
*      x4 = '0000000F'.
*      temp2_i = x4.
      <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
      temp3_i = temp3_i + 1.
READ TABLE pc2bytes10 INDEX temp3_i.
PERFORM rshfit_i USING right 12 temp1_i.
*      x4 = '0000000F'.
*      temp2_i = x4.
      <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
      temp3_i = temp3_i + 1.
READ TABLE pc2bytes11 INDEX temp3_i.
PERFORM rshfit_i USING right 8 temp1_i.
*      x4 = '0000000F'.
*      temp2_i = x4.
      <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
      temp3_i = temp3_i + 1.
READ TABLE pc2bytes12 INDEX temp3_i.
PERFORM rshfit_i USING right 4 temp1_i.
*      x4 = '0000000F'.
*      temp2_i = x4.
      <temp3_i> = <temp1_i> BIT-AND <temp2_i>.
      temp3_i = temp3_i + 1.
READ TABLE pc2bytes13 INDEX temp3_i.
      <righttemp> = <pc2bytes7> BIT-OR <pc2bytes8> BIT-OR <pc2bytes9> BIT-OR <pc2bytes10>
BIT-OR <pc2bytes11> BIT-OR <pc2bytes12> BIT-OR <pc2bytes13>.
*==========================
PERFORM rshfit_i USING righttemp 16 temp1_i.
      <temp2_i> = <temp1_i> BIT-XOR <lefttemp>.
      x4 = '0000FFFF'.
      temp3_i = x4.
      <temp> = <temp3_i> BIT-AND <temp2_i>.
*==========================
      <temp1_i> = <lefttemp> BIT-XOR <temp>.
APPEND temp1_i TO keys..
PERFORM lshfit_i USING temp 16 temp1_i.
      <temp2_i> = <righttemp> BIT-XOR <temp1_i>.
APPEND temp2_i TO keys.
index = index + 1.
ENDWHILE.
    j = j + 1.
ENDWHILE.
ENDFORM.                    "get_keys

==========================LZHR3DESF00==========================

posted @ 2019-06-15 17:19  江正军  阅读(8150)  评论(4编辑  收藏  举报