*&---------------------------------------------------------------------*
* & Report ztest
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
Report ztest.
Types: Begin of dswpclientkey,
Instno type num10,
Dbid (3 ),
Bundle_id (8 ),
Service_key (40 ),
End of dswpclientkey.
* Data: dswpclientkey_w type standard table of dswpclientkey.
Data: p_value (10 ),
P_instno (10 ).
Parameters: p_sid (3 ),
P_sysno (2 ),
P_server (15 ).
Start-of-selection.
Perform get_sp_value using p_sid
P_sysno
P_server
P_instno
Changing p_value.
End-of-selection.
Write p_value.
*&---------------------------------------------------------------------*
* & Form get_sp_value
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
* --> P_pf_sid text
* --> P_pf_sysno text
* --> P_pf_server text
* <-- P_pf_value text
*----------------------------------------------------------------------*
Form get_sp_value using p_pf_sid
P_pf_sysno
P_pf_server
P_pf_instno
Changing p_pf_value.
Constants: lc_part_len type I value 5,
Lc_pw_len type I value 10,
Lc_allowed_chars (38) Type C value
'-0123456789abcdefghijklmnopqrstuvwxyz _'.
Data: lf_string (20) type C,
Lf_key type I,
Ls_key type dswpclientkey,
Lf_part (lc_part_len) type C,
Lf_finalf (lc_pw_len) type C,
Lf_finalx type xstring,
Lf_xbuffer type xstring,
Lf_opf (10) type C,
Lf_langu like sy-Langu,
Lf_subrc like sy-subrc,
Lf_len type I,
Lo_conv_to_x type ref to cl_abap_conv_out_ce.
Clear: lf_string, lf_finalx, lf_opf.
Concatenate p_pf_sid p_pf_sysno p_pf_server into lf_string.
* Large letters only
Translate lf_string to upper case.
Lf_langu = sy-Langu.
Set locale language 'E '.
Lo_conv_to_x = cl_abap_conv_out_ce => Create (encoding = '20170101 ').
Lf_len = strlen (lf_string ).
If lf_string (lf_len) Cn lc_allowed_chars.
Else.
* Fold the input string to a lc_part_len long string
While lf_len> 0.
Lf_part = lf_string (lc_part_len ).
Shift lf_string by lc_part_len places.
Lf_len = strlen (lf_string ).
Call method lo_conv_to_x-> Reset.
Call method lo_conv_to_x-> write (Data = lf_part n =-1 ).
Lf_xbuffer = lo_conv_to_x-> get_buffer ().
Lf_finalx = lf_finalx BIT-XOR lf_xbuffer.
Endwhile.
Lf_key = 12.
Perform scramble using lf_finalx
Lf_key
Lc_part_len
Changing lf_finalf
Lf_subrc.
If not lf_finalf is initial.
P_pf_value = lf_finalf.
Ls_key-dbid = p_pf_sid.
Ls_key-instno = p_pf_instno.
Ls_key-bundle_id = 'sm _ key '.
Ls_key-service_key = lf_finalf.
If not p_pf_instno is initial.
* Insert dswpclientkey_w from ls_key.
If sy-subrc <> 0.
* Update dswpclientkey_w from ls_key.
Endif.
Endif.
Else.
Clear p_pf_value.
Endif.
Endif.
Endform. "get_sp_value
*&---------------------------------------------------------------------*
* & Form scramble
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
* --> P_lf_finalx text
* --> P_lf_key text
* --> P_lc_part_len text
* <-- P_lf_finalf text
* <-- P_lf_subrc text
*----------------------------------------------------------------------*
Form scramble using iv_xstring type xstring
Iv_key type I
Iv_src_len type I
Changing lf_finalf
Lf_subrc like sy-subrc.
constants: lc_max_len type I value 20,
lc_mask (4) Type X value '0000003f',
lc_random (64) type X value
'f0ed53b83244f1f876c67959fd4f13a2 '&
'c15195ec5483c234774943a27de26596' &
'hangzhou '.
Data: lv_key_index (4) Type X,
Lv_rand_index (4) Type X,
Lv_xkey (4) Type X,
Lv_xkey_shl_1 (4) Type X,
Lv_xkey_shr_5 (4) Type X,
Lv_scramble_byte Type X,
Lv_dest (lc_max_len) Type X,
Lv_index type I,
Lv_len type I.
Clear lf_subrc.
If iv_src_len EQ 0. Exit. endif.
Lv_len = xstrlen (iv_xstring ).
If iv_src_len GT lc_max_len or
Iv_src_len GT lv_len.
Lf_subrc = 2.
Exit.
Endif.
Lv_xkey = iv_key.
Lv_xkey_shl_1 = iv_key * 2.
Lv_xkey_shr_5 = iv_key Div 32.
Lv_rand_index = lv_xkey BIT-XOR lv_xkey_shr_5 BIT-XOR lv_xkey_shl_1.
Lv_rand_index = lv_rand_index bit-And lc_mask.
Lv_index = 0.
Do iv_src_len times.
Catch system-exceptions compute_int_times_overflow = 1.
Lv_key_index = (iv_key * lv_index)-lv_index.
Endcatch.
If sy-subrc <> 0.
Lf_subrc = 1.
Exit.
Endif.
Lv_scramble_byte = lc_random + lv_rand_index (1) BIT-XOR
Lv_key_index + 3 (1 ).
Lv_dest + lv_index (1) = iv_xstring + lv_index (1) BIT-XOR
Lv_scramble_byte.
Lv_index = lv_index + 1.
Lv_rand_index = lv_rand_index + 1.
Lv_rand_index = lv_rand_index bit-And lc_mask.
Enddo.
If lf_subrc <> 0.
Exit.
Endif.
Write lv_dest (iv_src_len) to lf_finalf.
Endform. "Scramble