forked from larshp/abapNTLM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zcl_des.clas.abap
1599 lines (1399 loc) · 30.3 KB
/
zcl_des.clas.abap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
class ZCL_DES definition
public
create public .
public section.
*"* public components of class ZCL_DES
*"* do not include other source files here!!!
types:
TY_BYTE7 type x length 7 .
types:
TY_BYTE8 type x length 8 .
class-methods DECRYPT
importing
!IV_KEY type TY_BYTE8
!IV_CIPHERTEXT type XSEQUENCE
returning
value(RV_PLAINTEXT) type XSTRING .
class-methods ENCRYPT
importing
!IV_KEY type TY_BYTE8
!IV_PLAINTEXT type XSEQUENCE
returning
value(RV_CIPHERTEXT) type XSTRING .
class-methods PARITY_ADJUST
importing
!IV_BYTE7 type TY_BYTE7
returning
value(RV_BYTE8) type TY_BYTE8 .
protected section.
*"* protected components of class ZCL_DES
*"* do not include other source files here!!!
class-methods XOR
importing
!IV_A type CLIKE
!IV_B type CLIKE
returning
value(RV_RES) type STRING .
class-methods TO_BITS
importing
!IV_BINARY type XSEQUENCE
returning
value(RV_BITS) type STRING .
class-methods S8
importing
!IV_B type CLIKE
returning
value(RV_S) type STRING .
class-methods S7
importing
!IV_B type CLIKE
returning
value(RV_S) type STRING .
class-methods S6
importing
!IV_B type CLIKE
returning
value(RV_S) type STRING .
class-methods S5
importing
!IV_B type CLIKE
returning
value(RV_S) type STRING .
class-methods S4
importing
!IV_B type CLIKE
returning
value(RV_S) type STRING .
class-methods S3
importing
!IV_B type CLIKE
returning
value(RV_S) type STRING .
class-methods S2
importing
!IV_B type CLIKE
returning
value(RV_S) type STRING .
class-methods S1
importing
!IV_B type CLIKE
returning
value(RV_S) type STRING .
class-methods ROW
importing
!IV_B type CLIKE
returning
value(RV_ROW) type I .
class-methods PERMUTE_PC2
importing
!IV_BITS type CLIKE
returning
value(RV_BITS) type STRING .
class-methods PERMUTE_PC1
importing
!IV_BITS type CLIKE
returning
value(RV_BITS) type STRING .
class-methods PERMUTE_P
importing
!IV_BITS type CLIKE
returning
value(RV_BITS) type STRING .
class-methods PERMUTE_IP1
importing
!IV_BITS type CLIKE
returning
value(RV_BITS) type STRING .
class-methods PERMUTE_IP
importing
!IV_BITS type CLIKE
returning
value(RV_BITS) type STRING .
class-methods PERMUTE_E
importing
!IV_BITS type CLIKE
returning
value(RV_BITS) type STRING .
class-methods L_AND_R
importing
!IV_L_0 type CLIKE
!IV_R_0 type CLIKE
!IT_K type STRING_TT
returning
value(RV_BITS) type STRING .
class-methods K
importing
!IT_BITS type STRING_TT
returning
value(RT_BITS) type STRING_TT .
class-methods I_TO_BITS_4
importing
!IV_I type I
returning
value(RV_BITS) type STRING .
class-methods FROM_BITS
importing
!IV_BITS type CLIKE
returning
value(RV_XSTR) type XSTRING .
class-methods F
importing
!IV_R type CLIKE
!IV_K type CLIKE
returning
value(RV_RES) type STRING .
class-methods C_AND_D
importing
!IV_C_0 type CLIKE
!IV_D_0 type CLIKE
returning
value(RT_BITS) type STRING_TT .
class-methods COLUMN
importing
!IV_B type CLIKE
returning
value(RV_COLUMN) type I .
private section.
*"* private components of class ZCL_DES
*"* do not include other source files here!!!
ENDCLASS.
CLASS ZCL_DES IMPLEMENTATION.
METHOD column.
CASE iv_b+1(4).
WHEN '0000'.
rv_column = 0.
WHEN '0001'.
rv_column = 1.
WHEN '0010'.
rv_column = 2.
WHEN '0011'.
rv_column = 3.
WHEN '0100'.
rv_column = 4.
WHEN '0101'.
rv_column = 5.
WHEN '0110'.
rv_column = 6.
WHEN '0111'.
rv_column = 7.
WHEN '1000'.
rv_column = 8.
WHEN '1001'.
rv_column = 9.
WHEN '1010'.
rv_column = 10.
WHEN '1011'.
rv_column = 11.
WHEN '1100'.
rv_column = 12.
WHEN '1101'.
rv_column = 13.
WHEN '1110'.
rv_column = 14.
WHEN '1111'.
rv_column = 15.
WHEN OTHERS.
ASSERT 1 = 1 + 1.
ENDCASE.
ENDMETHOD.
METHOD c_and_d.
DATA: lv_c_n TYPE c LENGTH 28,
lv_d_n TYPE c LENGTH 28,
lv_str TYPE string.
DEFINE _shift.
shift lv_c_n left by &1 places circular.
shift lv_d_n left by &1 places circular.
concatenate lv_c_n lv_d_n into lv_str.
append lv_str to rt_bits.
END-OF-DEFINITION.
lv_c_n = iv_c_0.
lv_d_n = iv_d_0.
_shift 1.
_shift 1.
_shift 2.
_shift 2.
_shift 2.
_shift 2.
_shift 2.
_shift 2.
_shift 1.
_shift 2.
_shift 2.
_shift 2.
_shift 2.
_shift 2.
_shift 2.
_shift 1.
ENDMETHOD.
METHOD decrypt.
* todo
RETURN.
ENDMETHOD.
METHOD encrypt.
* The MIT License (MIT)
*
* Copyright (c) 2015 Lars Hvam
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* https://www.utdallas.edu/~edsha/OS2000/des-algorithm-details.txt
* http://page.math.tu-berlin.de/~kant/teaching/hess/krypto-ws2006/des.htm
DATA: lt_bits TYPE string_tt,
lv_bits TYPE string,
lv_ip TYPE c LENGTH 64,
lv_k_plus TYPE c LENGTH 56.
* manipulate key
lv_k_plus = permute_pc1( to_bits( iv_key ) ).
lt_bits = c_and_d( iv_c_0 = lv_k_plus(28)
iv_d_0 = lv_k_plus+28(28) ).
lt_bits = k( lt_bits ).
* data block
lv_ip = permute_ip( to_bits( iv_plaintext ) ).
lv_bits = l_and_r( iv_l_0 = lv_ip(32)
iv_r_0 = lv_ip+32(32)
it_k = lt_bits ).
rv_ciphertext = from_bits( lv_bits ).
ENDMETHOD.
METHOD f.
DATA: lv_e TYPE c LENGTH 48,
lv_s TYPE c LENGTH 32,
lv_s1 TYPE c LENGTH 4,
lv_s2 TYPE c LENGTH 4,
lv_s3 TYPE c LENGTH 4,
lv_s4 TYPE c LENGTH 4,
lv_s5 TYPE c LENGTH 4,
lv_s6 TYPE c LENGTH 4,
lv_s7 TYPE c LENGTH 4,
lv_s8 TYPE c LENGTH 4,
lv_xor TYPE c LENGTH 48,
lv_b1 TYPE c LENGTH 6,
lv_b2 TYPE c LENGTH 6,
lv_b3 TYPE c LENGTH 6,
lv_b4 TYPE c LENGTH 6,
lv_b5 TYPE c LENGTH 6,
lv_b6 TYPE c LENGTH 6,
lv_b7 TYPE c LENGTH 6,
lv_b8 TYPE c LENGTH 6.
lv_e = permute_e( iv_r ).
lv_xor = xor( iv_a = lv_e
iv_b = iv_k ).
lv_b1 = lv_xor(6).
lv_xor = lv_xor+6.
lv_b2 = lv_xor(6).
lv_xor = lv_xor+6.
lv_b3 = lv_xor(6).
lv_xor = lv_xor+6.
lv_b4 = lv_xor(6).
lv_xor = lv_xor+6.
lv_b5 = lv_xor(6).
lv_xor = lv_xor+6.
lv_b6 = lv_xor(6).
lv_xor = lv_xor+6.
lv_b7 = lv_xor(6).
lv_xor = lv_xor+6.
lv_b8 = lv_xor(6).
lv_xor = lv_xor+6.
lv_s1 = s1( lv_b1 ).
lv_s2 = s2( lv_b2 ).
lv_s3 = s3( lv_b3 ).
lv_s4 = s4( lv_b4 ).
lv_s5 = s5( lv_b5 ).
lv_s6 = s6( lv_b6 ).
lv_s7 = s7( lv_b7 ).
lv_s8 = s8( lv_b8 ).
CONCATENATE lv_s1 lv_s2 lv_s3 lv_s4 lv_s5 lv_s6 lv_s7 lv_s8 INTO lv_s.
rv_res = permute_p( lv_s ).
ENDMETHOD.
METHOD from_bits.
DATA: lv_index TYPE i,
lv_res TYPE x LENGTH 8.
ASSERT strlen( iv_bits ) = 64.
DO 64 TIMES.
lv_index = sy-index - 1.
SET BIT lv_index + 1 OF lv_res TO iv_bits+lv_index(1).
ENDDO.
rv_xstr = lv_res.
ENDMETHOD.
METHOD i_to_bits_4.
CASE iv_i.
WHEN 0.
rv_bits = '0000'.
WHEN 1.
rv_bits = '0001'.
WHEN 2.
rv_bits = '0010'.
WHEN 3.
rv_bits = '0011'.
WHEN 4.
rv_bits = '0100'.
WHEN 5.
rv_bits = '0101'.
WHEN 6.
rv_bits = '0110'.
WHEN 7.
rv_bits = '0111'.
WHEN 8.
rv_bits = '1000'.
WHEN 9.
rv_bits = '1001'.
WHEN 10.
rv_bits = '1010'.
WHEN 11.
rv_bits = '1011'.
WHEN 12.
rv_bits = '1100'.
WHEN 13.
rv_bits = '1101'.
WHEN 14.
rv_bits = '1110'.
WHEN 15.
rv_bits = '1111'.
WHEN OTHERS.
ASSERT 1 = 1 + 1.
ENDCASE.
ENDMETHOD.
METHOD k.
DATA: lv_bits LIKE LINE OF it_bits.
DO 16 TIMES.
READ TABLE it_bits INDEX sy-index INTO lv_bits.
ASSERT sy-subrc = 0.
lv_bits = permute_pc2( lv_bits ).
APPEND lv_bits TO rt_bits.
ENDDO.
ENDMETHOD.
METHOD l_and_r.
DATA: lv_l_prev TYPE c LENGTH 32,
lv_r_prev TYPE c LENGTH 32,
lv_l_n TYPE c LENGTH 32,
lv_r_n TYPE c LENGTH 32,
lv_k_n TYPE c LENGTH 48,
lv_t TYPE c LENGTH 64.
lv_l_prev = iv_l_0.
lv_r_prev = iv_r_0.
DO 16 TIMES.
lv_l_n = lv_r_prev.
READ TABLE it_k INDEX sy-index INTO lv_k_n.
lv_r_n = xor( iv_a = lv_l_prev
iv_b = f( iv_r = lv_r_prev
iv_k = lv_k_n ) ).
lv_l_prev = lv_l_n.
lv_r_prev = lv_r_n.
ENDDO.
CONCATENATE lv_r_n lv_l_n INTO lv_t.
rv_bits = permute_ip1( lv_t ).
ENDMETHOD.
METHOD parity_adjust.
DATA: lv_input TYPE c LENGTH 56,
lv_output TYPE c LENGTH 64,
lv_bits TYPE c LENGTH 7,
lv_offset TYPE i,
lv_zeros TYPE i.
lv_input = to_bits( iv_byte7 ).
DO 8 TIMES.
lv_bits = lv_input(7).
lv_input = lv_input+7.
CONCATENATE lv_output lv_bits INTO lv_output.
FIND ALL OCCURRENCES OF '0' IN lv_bits MATCH COUNT lv_zeros.
IF lv_zeros MOD 2 = 0.
CONCATENATE lv_output '0' INTO lv_output.
ELSE.
CONCATENATE lv_output '1' INTO lv_output.
ENDIF.
ENDDO.
DO 64 TIMES.
lv_offset = sy-index - 1.
SET BIT sy-index OF rv_byte8 TO lv_output+lv_offset(1).
ENDDO.
ENDMETHOD.
METHOD PERMUTE_E.
DATA: lv_offset TYPE i.
DEFINE _bit.
lv_offset = &1 - 1.
concatenate rv_bits iv_bits+lv_offset(1) into rv_bits.
END-OF-DEFINITION.
_bit 32.
_bit 1.
_bit 2.
_bit 3.
_bit 4.
_bit 5.
_bit 4.
_bit 5.
_bit 6.
_bit 7.
_bit 8.
_bit 9.
_bit 8.
_bit 9.
_bit 10.
_bit 11.
_bit 12.
_bit 13.
_bit 12.
_bit 13.
_bit 14.
_bit 15.
_bit 16.
_bit 17.
_bit 16.
_bit 17.
_bit 18.
_bit 19.
_bit 20.
_bit 21.
_bit 20.
_bit 21.
_bit 22.
_bit 23.
_bit 24.
_bit 25.
_bit 24.
_bit 25.
_bit 26.
_bit 27.
_bit 28.
_bit 29.
_bit 28.
_bit 29.
_bit 30.
_bit 31.
_bit 32.
_bit 1.
ENDMETHOD.
METHOD permute_ip.
DATA: lv_offset TYPE i.
DEFINE _bit.
lv_offset = &1 - 1.
concatenate rv_bits iv_bits+lv_offset(1) into rv_bits.
END-OF-DEFINITION.
_bit 58.
_bit 50.
_bit 42.
_bit 34.
_bit 26.
_bit 18.
_bit 10.
_bit 2.
_bit 60.
_bit 52.
_bit 44.
_bit 36.
_bit 28.
_bit 20.
_bit 12.
_bit 4.
_bit 62.
_bit 54.
_bit 46.
_bit 38.
_bit 30.
_bit 22.
_bit 14.
_bit 6.
_bit 64.
_bit 56.
_bit 48.
_bit 40.
_bit 32.
_bit 24.
_bit 16.
_bit 8.
_bit 57.
_bit 49.
_bit 41.
_bit 33.
_bit 25.
_bit 17.
_bit 9.
_bit 1.
_bit 59.
_bit 51.
_bit 43.
_bit 35.
_bit 27.
_bit 19.
_bit 11.
_bit 3.
_bit 61.
_bit 53.
_bit 45.
_bit 37.
_bit 29.
_bit 21.
_bit 13.
_bit 5.
_bit 63.
_bit 55.
_bit 47.
_bit 39.
_bit 31.
_bit 23.
_bit 15.
_bit 7.
ENDMETHOD.
METHOD PERMUTE_IP1.
DATA: lv_offset TYPE i.
DEFINE _bit.
lv_offset = &1 - 1.
concatenate rv_bits iv_bits+lv_offset(1) into rv_bits.
END-OF-DEFINITION.
_bit 40.
_bit 8.
_bit 48.
_bit 16.
_bit 56.
_bit 24.
_bit 64.
_bit 32.
_bit 39.
_bit 7.
_bit 47.
_bit 15.
_bit 55.
_bit 23.
_bit 63.
_bit 31.
_bit 38.
_bit 6.
_bit 46.
_bit 14.
_bit 54.
_bit 22.
_bit 62.
_bit 30.
_bit 37.
_bit 5.
_bit 45.
_bit 13.
_bit 53.
_bit 21.
_bit 61.
_bit 29.
_bit 36.
_bit 4.
_bit 44.
_bit 12.
_bit 52.
_bit 20.
_bit 60.
_bit 28.
_bit 35.
_bit 3.
_bit 43.
_bit 11.
_bit 51.
_bit 19.
_bit 59.
_bit 27.
_bit 34.
_bit 2.
_bit 42.
_bit 10.
_bit 50.
_bit 18.
_bit 58.
_bit 26.
_bit 33.
_bit 1.
_bit 41.
_bit 9.
_bit 49.
_bit 17.
_bit 57.
_bit 25.
ENDMETHOD.
METHOD permute_p.
DATA: lv_offset TYPE i.
DEFINE _bit.
lv_offset = &1 - 1.
concatenate rv_bits iv_bits+lv_offset(1) into rv_bits.
END-OF-DEFINITION.
_bit 16.
_bit 7.
_bit 20.
_bit 21.
_bit 29.
_bit 12.
_bit 28.
_bit 17.
_bit 1.
_bit 15.
_bit 23.
_bit 26.
_bit 5.
_bit 18.
_bit 31.
_bit 10.
_bit 2.
_bit 8.
_bit 24.
_bit 14.
_bit 32.
_bit 27.
_bit 3.
_bit 9.
_bit 19.
_bit 13.
_bit 30.
_bit 6.
_bit 22.
_bit 11.
_bit 4.
_bit 25.
ENDMETHOD.
METHOD permute_pc1.
DATA: lv_offset TYPE i.
DEFINE _bit.
lv_offset = &1 - 1.
concatenate rv_bits iv_bits+lv_offset(1) into rv_bits.
END-OF-DEFINITION.
_bit 57.
_bit 49.
_bit 41.
_bit 33.
_bit 25.
_bit 17.
_bit 9.
_bit 1.
_bit 58.
_bit 50.
_bit 42.
_bit 34.
_bit 26.
_bit 18.
_bit 10.
_bit 2.
_bit 59.
_bit 51.
_bit 43.
_bit 35.
_bit 27.
_bit 19.
_bit 11.
_bit 3.
_bit 60.
_bit 52.
_bit 44.
_bit 36.
_bit 63.
_bit 55.
_bit 47.
_bit 39.
_bit 31.
_bit 23.
_bit 15.
_bit 7.
_bit 62.
_bit 54.
_bit 46.
_bit 38.
_bit 30.
_bit 22.
_bit 14.
_bit 6.
_bit 61.
_bit 53.
_bit 45.
_bit 37.
_bit 29.
_bit 21.
_bit 13.
_bit 5.
_bit 28.
_bit 20.
_bit 12.
_bit 4.
ENDMETHOD.
METHOD permute_pc2.
DATA: lv_offset TYPE i.
DEFINE _bit.
lv_offset = &1 - 1.
concatenate rv_bits iv_bits+lv_offset(1) into rv_bits.
END-OF-DEFINITION.
_bit 14.
_bit 17.
_bit 11.
_bit 24.
_bit 1.
_bit 5.
_bit 3.
_bit 28.
_bit 15.
_bit 6.
_bit 21.
_bit 10.
_bit 23.
_bit 19.
_bit 12.
_bit 4.
_bit 26.
_bit 8.
_bit 16.
_bit 7.
_bit 27.
_bit 20.
_bit 13.
_bit 2.
_bit 41.
_bit 52.
_bit 31.
_bit 37.
_bit 47.
_bit 55.
_bit 30.
_bit 40.
_bit 51.
_bit 45.
_bit 33.
_bit 48.
_bit 44.
_bit 49.
_bit 39.
_bit 56.
_bit 34.
_bit 53.
_bit 46.
_bit 42.
_bit 50.
_bit 36.
_bit 29.
_bit 32.
ENDMETHOD.
METHOD row.
DATA: lv_c TYPE c LENGTH 2.
CONCATENATE iv_b(1) iv_b+5(1) INTO lv_c.
CASE lv_c.
WHEN '00'.
rv_row = 0.
WHEN '01'.
rv_row = 1.
WHEN '10'.
rv_row = 2.
WHEN '11'.
rv_row = 3.
WHEN OTHERS.
ASSERT 1 = 1 + 1.
ENDCASE.
ENDMETHOD.
METHOD s1.
DATA: lt_table TYPE TABLE OF i,
lv_index TYPE i,
lv_i TYPE i.
APPEND 14 TO lt_table.
APPEND 4 TO lt_table.
APPEND 13 TO lt_table.
APPEND 1 TO lt_table.
APPEND 2 TO lt_table.
APPEND 15 TO lt_table.
APPEND 11 TO lt_table.
APPEND 8 TO lt_table.
APPEND 3 TO lt_table.
APPEND 10 TO lt_table.
APPEND 6 TO lt_table.
APPEND 12 TO lt_table.
APPEND 5 TO lt_table.
APPEND 9 TO lt_table.
APPEND 0 TO lt_table.
APPEND 7 TO lt_table.
APPEND 0 TO lt_table.
APPEND 15 TO lt_table.
APPEND 7 TO lt_table.
APPEND 4 TO lt_table.
APPEND 14 TO lt_table.
APPEND 2 TO lt_table.
APPEND 13 TO lt_table.
APPEND 1 TO lt_table.
APPEND 10 TO lt_table.
APPEND 6 TO lt_table.
APPEND 12 TO lt_table.
APPEND 11 TO lt_table.
APPEND 9 TO lt_table.
APPEND 5 TO lt_table.
APPEND 3 TO lt_table.
APPEND 8 TO lt_table.
APPEND 4 TO lt_table.
APPEND 1 TO lt_table.
APPEND 14 TO lt_table.
APPEND 8 TO lt_table.
APPEND 13 TO lt_table.
APPEND 6 TO lt_table.
APPEND 2 TO lt_table.
APPEND 11 TO lt_table.
APPEND 15 TO lt_table.
APPEND 12 TO lt_table.
APPEND 9 TO lt_table.
APPEND 7 TO lt_table.
APPEND 3 TO lt_table.
APPEND 10 TO lt_table.
APPEND 5 TO lt_table.
APPEND 0 TO lt_table.
APPEND 15 TO lt_table.
APPEND 12 TO lt_table.
APPEND 8 TO lt_table.
APPEND 2 TO lt_table.
APPEND 4 TO lt_table.
APPEND 9 TO lt_table.
APPEND 1 TO lt_table.
APPEND 7 TO lt_table.
APPEND 5 TO lt_table.
APPEND 11 TO lt_table.
APPEND 3 TO lt_table.
APPEND 14 TO lt_table.
APPEND 10 TO lt_table.
APPEND 0 TO lt_table.
APPEND 6 TO lt_table.
APPEND 13 TO lt_table.
lv_index = ( row( iv_b ) * 16 ) + column( iv_b ) + 1.
READ TABLE lt_table INDEX lv_index INTO lv_i.
ASSERT sy-subrc = 0.
rv_s = i_to_bits_4( lv_i ).