Decode and Encode al long text

Wolterink

New Member
Hi,

How I can decode and encode a long text (1000 CHAR).
(I would decode an Progress *.p file.)

Pleaze help me.

bye
sascha

from germany
 
Sorry, but you can't decode the (standard Progress) encoded string.

From Help:
"The ENCODE function performs a one–way encoding operation that you cannot reverse. ... etc"

(ENCODE function)

I don't know another way.

Regards
 
Here is code for decoding.

&ANALYZE-SUSPEND _VERSION-NUMBER UIB_v9r12
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Method-Library
/*------------------------------------------------------------------------
Library :
Purpose :

Syntax :

Description :

Author(s) :
Created :
Notes :
----------------------------------------------------------------------*/
/* This .W file was created with the Progress AppBuilder. */
/*----------------------------------------------------------------------*/

/* *************************** Definitions ************************** */

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK

/* ******************** Preprocessor Definitions ******************** */



/* _UIB-PREPROCESSOR-BLOCK-END */
&ANALYZE-RESUME


/* ************************ Function Prototypes ********************** */

&IF DEFINED(EXCLUDE-HexToInt) = 0 &THEN

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD HexToInt Method-Library
FUNCTION HexToInt RETURNS INTEGER (INPUT Hex AS CHAR) FORWARD.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ENDIF

&IF DEFINED(EXCLUDE-URL-DECODE) = 0 &THEN

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD URL-DECODE Method-Library
FUNCTION URL-DECODE RETURNS CHARACTER (INPUT r AS CHARACTER) FORWARD.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ENDIF


/* *********************** Procedure Settings ************************ */

&ANALYZE-SUSPEND _PROCEDURE-SETTINGS
/* Settings for THIS-PROCEDURE
Type: Method-Library
Allow:
Frames: 0
Add Fields to: Neither
Other Settings: INCLUDE-ONLY
*/
&ANALYZE-RESUME _END-PROCEDURE-SETTINGS

/* ************************* Create Window ************************** */

&ANALYZE-SUSPEND _CREATE-WINDOW
/* DESIGN Window definition (used by the UIB)
CREATE WINDOW Method-Library ASSIGN
HEIGHT = 15
WIDTH = 60.
/* END WINDOW DEFINITION */
*/
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _XFTR "MethodLibraryCues" Method-Library _INLINE
/* Actions: adecomm/_so-cue.w ? adecomm/_so-cued.p ? adecomm/_so-cuew.p */
/* Method Library,uib,70080
Destroy on next read */
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Method-Library
/* ************************* Included-Libraries *********************** */

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME





&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Method-Library


/* *************************** Main Block *************************** */

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


/* ************************ Function Implementations ***************** */

&IF DEFINED(EXCLUDE-HexToInt) = 0 &THEN

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION HexToInt Method-Library
FUNCTION HexToInt RETURNS INTEGER (INPUT Hex AS CHAR):

DEF VAR HexAlphabet AS CHARACTER INIT "0123456789abcdef" NO-UNDO.
DEF VAR HexPower AS CHARACTER INIT "1,16,256,4096,65536,1048576,16888216,268435456" NO-UNDO.

DEF VAR fc AS CHARACTER NO-UNDO.
DEF VAR ix AS INTEGER NO-UNDO.

ASSIGN
fc = SUBSTRING(Hex,1,1)
ix = INDEX(HexAlphabet, fc) - 1.

IF fc = "" THEN RETURN 0.

ELSE RETURN (ix * INTEGER(ENTRY(LENGTH(Hex), HexPower)))
+ hexToInt(SUBSTRING(Hex,2)).

END FUNCTION. /* FUNCTION HexToInt */

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ENDIF

&IF DEFINED(EXCLUDE-URL-DECODE) = 0 &THEN

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION URL-DECODE Method-Library
FUNCTION URL-DECODE RETURNS CHARACTER (INPUT r AS CHARACTER):

DEF VAR l AS INTEGER NO-UNDO. /* length of r */
DEF VAR i AS INTEGER NO-UNDO. /* index in r */
DEF VAR c AS CHARACTER NO-UNDO. /* char representation of hex */
DEF VAR s AS CHARACTER NO-UNDO. /* output string */

ASSIGN l = LENGTH (r).

DO i = 1 TO l:

/* If there is no % marker, we are cool with the characters in */
/* the string. */

IF SUBSTRING (r, i, 1) <> "%" THEN DO:

ASSIGN s = s + SUBSTRING (r, i, 1).
NEXT.

END. /* Not a % representation */

/* Of course, getting here means we are looking at a %. Figure */
/* out what character that represents. Assuming a % would be */
/* encoded hexidecimally, so we grab the next two characters as */
/* the hex value, convert, and then put that on the string. */

ASSIGN c = CHR(HexToInt (SUBSTRING(r, i + 1, 2))).

/* We want to replace the %hh number with the char value we just */
/* computed and increment i so we move past the number in our */
/* original string. */

ASSIGN
i = i + 2
s = s + c.

END. /* DO i = 1 TO l */
RETURN s.

END FUNCTION. /* FUNCTION URL-DECODE () */

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ENDIF
 
Progress allows only to Encode data. Any data which needs to be compared to this data has to be encoded before comparison.

One of the alternatives is to, write your own encrytion & decription logic. This is helpful if you are going to do both. One suggestion for the same is ... Iterate through the data, increment/decrement (or use appropriate logic) the ascii value for encoding. Apply the reverse, when you are decoding.

HTH
P Menon
 
Back
Top