One-way hash encrypting/decrypting

One-way hash encrypting/decrypting

One-way hash encrypting/decrypting
By Imre Kabai

This tip is published with the permission of Imre Kabai.

This program encrypts and decrypts a string using an 8 byte strong one-way-hash like encrypting method. Instead of bit operation, it uses byte operations, because of ABAP's lack of bit operations.

It is useful to process sensitive data (HR ...), that would be otherwise accessible by both ABAPs and UNIX users (root, adm).

The algorithm of the encrypting:
result(1) = source(1) @ initial_key
result(n) = source(n) @ source(n-1) @ result(n-1)

The algorithm of the decrypting:
source(1) = result(1) # initial_key
source(n) = result(n) # result(n-1) # source(n-1)

Where source, result, initial_key are 8 byte strings, @ and # are negate byte operations of each other


REPORT ZENCRYPT.
PARAMETERS: STRING(96), KEY(8).
PARAMETER ENCRYPT RADIOBUTTON GROUP RB.
PARAMETER DECRYPT RADIOBUTTON GROUP RB.
DATA: I TYPE I, J TYPE I.
DATA: BEGIN OF A,
   1 TYPE X, 2 TYPE X, 3 TYPE X, 4 TYPE X,
   5 TYPE X, 6 TYPE X, 7 TYPE X, 8 TYPE X,
END OF A.
DATA: BEGIN OF B,
   1 TYPE X, 2 TYPE X, 3 TYPE X, 4 TYPE X,
   5 TYPE X, 6 TYPE X, 7 TYPE X, 8 TYPE X,
END OF B.
DATA: BEGIN OF C,
   1 TYPE X, 2 TYPE X, 3 TYPE X, 4 TYPE X,
   5 TYPE X, 6 TYPE X, 7 TYPE X, 8 TYPE X,
END OF C.
DATA: BEGIN OF D,
   1 TYPE X, 2 TYPE X, 3 TYPE X, 4 TYPE X,
   5 TYPE X, 6 TYPE X, 7 TYPE X, 8 TYPE X,
END

    Requires Free Membership to View

    When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchSAP.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSAP.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

OF D. DATA: BEGIN OF E, 1 TYPE X, 2 TYPE X, 3 TYPE X, 4 TYPE X, 5 TYPE X, 6 TYPE X, 7 TYPE X, 8 TYPE X, END OF E. WRITE: / STRING. * encrypting J = STRLEN( STRING ). A = KEY. DO. B = STRING+I. E = B. IF SY-INDEX = 1. B-1 = A-1 + B-1.B-2 = A-2 + B-2.B-3 = A-3 + B-3.B-4 = A-4 + B-4. B-5 = A-5 + B-5.B-6 = A-6 + B-6.B-7 = A-7 + B-7.B-8 = A-8 + B-8. ELSE. B-1 = C-1 + D-1 + B-1.B-2 = C-2 + D-2 + B-2. B-3 = C-3 + D-3 + B-3.B-4 = C-4 + D-4 + B-4. B-5 = C-5 + D-5 + B-5.B-6 = C-6 + D-6 + B-6. B-7 = C-7 + D-7 + B-7.B-8 = C-8 + D-8 + B-8. ENDIF. D = B. C = E. STRING+I(8) = B. I = I + 8. IF I >= J. EXIT. ENDIF. ENDDO. WRITE: / STRING. * decrypting J = STRLEN( STRING ). I = 0. A = KEY. DO. B = STRING+I. E = B. IF SY-INDEX = 1. B-1 = B-1 - A-1.B-2 = B-2 - A-2.B-3 = B-3 - A-3.B-4 = B-4 - A-4. B-5 = B-5 - A-5.B-6 = B-6 - A-6.B-7 = B-7 - A-7.B-8 = B-8 - A-8. ELSE. B-1 = B-1 - C-1 - D-1.B-2 = B-2 - C-2 - D-2. B-3 = B-3 - C-3 - D-3.B-4 = B-4 - C-4 - D-4. B-5 = B-5 - C-5 - D-5.B-6 = B-6 - C-6 - D-6. B-7 = B-7 - C-7 - D-7.B-8 = B-8 - C-8 - D-8. ENDIF. D = B. C = E. STRING+I(8) = B. I = I + 8. IF I >= J. EXIT. ENDIF. ENDDO. WRITE: / STRING.

Visit Kabai.com to view this tip or to browse through a collection of other useful ABAP programs.

Did you like this tip? Hate it? Write to us at tips@searchSAP.com to let us know your thoughts.

Related Book
SAP R3 Reporting Tools
Author : Danielle Larocca
Publisher : McGraw-Hill
ISBN/CODE : 0072123427
Cover Type : Soft Cover
Pages : 400
Published : Dec 1999
Summary:
One of the key reasons to implement the SAP R/3 system in any organization is the ability to integrate information from every division of your company, and then generate reports that display the data in a useful format. But, whether you're an SAP user, developer, or consultant, you know that there is limited information available that shows how to locate and execute standard reports in SAP as well as how to retrieve data and create your own standard SAP reports. This user-friendly, practical guide will walk you through the process of creating, customizing, and producing reports quickly and easily.

This was first published in May 2001

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.