Framework EDI Reference. Encoding Mechanism
EDC Filter

The EDC Filter converts binary to character sets compatible with UN/EDIFACT Syntax Level C, D, E and F character set repertoires.  The following describes the encoding mechanism as implemented by Framework EDI and as defined in ISO 9735-5: Security Rules for Batch EDI.

Encoding

The procedure for encoding is as follows:

  1. The data is subdivided into 7-byte subgroups.  The last subgroup in the data may have 7 or less bytes.
  2. For each 7-byte subgroup, a single control byte, is prepended with a starting value of 64 (01000000).  All bits in the control byte represents the data bytes that are in the same respective position, except for bit 0 which represents data byte 1.  That is, bit position 0 represents data byte 1, and bit position 2 to 7 represents data byte 2 to 7 in the subgroup.

    Example.  The figure below shows 8 bytes: 1 control byte and 7 data bytes.  The control byte has decimal value 64 having digits 01000000.  The data bytes comprise of "a", "1", "b", "2", "c", "3", and "d". 

    Control Byte

    Data Byte 1

    Data Byte 2

    Data Byte 3

    Data Byte 4

    Data Byte 5

    Data Byte 6

    Data Byte 7

    0 1 0 0 0 0 0 0

    a

    1

    b

    2

    c

    3

    d



  3. Each data byte in the subgroup, the bit in position 1 is set to 1 if and only if the two conditions are met: If the transformation is made, then the index position of the byte in the subgroup is used to set the corresponding position in the control byte to 1.

    Example.  The 8-byte subgroup having data "a1b2c3d" will be encoded to "jaqbrcsd" and will have the byte stream as follows (greyed):

    Control Byte

    Data Byte 1

    Data Byte 2

    Data Byte 3

    Data Byte 4

    Data Byte 5

    Data Byte 6

    Data Byte 7

    a

    1

    b

    2

    c

    3

    d

    Initial Bits 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 1 1 0 0 0 1 0 1 1 0 0 0 1 0 0 0 1 1 0 0 1 0 0 1 1 0 0 0 1 1 0 0 1 1 0 0 1 1 0 1 1 0 0 1 0 0
    Transformation Bits 0 1 1 0 1 0 1 0 0 1 1 0 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 0 0 0 1 0 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 1 0 1 1 1 0 0 1 1 0 1 1 0 0 1 0 0
    Encoded Char j a q b r c s d
    Byte Stream 0x6A 0x61 0x71 0x62 0x72 0x63 0x73 0x64

 

Decoding

The procedure for decoding is as follows:

  1. The encoded text is subdivided into 8-byte subgroups.  The last subgroup in the data may have 8 or less bytes.
  2. The first byte is the control byte and is stripped of from the remaining 7 data bytes in the subgroup.  The bits 0 and 2 to 7 in the control byte correspond to the positions 1 to 7 in the data bytes.  That is bit 0 correspond to data byte 1, and bit 2 to 7 correspond to data byte 2 to 7.

    Example.  The encoded text "jaqbrcsd" will have the char "j" stripped of as the control byte, and "aqbrcsd" will be the data bytes.

    Byte 1

    Byte 2

    Byte 3

    Byte 4

    Byte 5

    Byte 6

    Byte 7

    Byte 8

    Encoded Char j a q b r c s d
    Byte Stream 0x6A 0x61 0x71 0x62 0x72 0x63 0x73 0x64

    The control byte is interpreted as follows:

    Control Byte

    Encoded Char j
    Byte Stream 0x6A
    Encoded Bits 0 1 1 0 1 0 1 0

    The data bytes "aqbrcsd" are as follows:

    Data Byte 1

    Data Byte 2

    Data Byte 3

    Data Byte 4

    Data Byte 5

    Data Byte 6

    Data Byte 7

    Encoded Char a q b r c s d
    Byte Stream 0x61 0x71 0x62 0x72 0x63 0x73 0x64
    Encoded Bits 0 1 1 0 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 0 0 0 1 0 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 1 0 1 1 1 0 0 1 1 0 1 1 0 0 1 0 0

  3. For each bit that is set to 1 in the control byte, its corresponding byte has its bit in position 1 set to 0.  That is, if the control byte has its bit in position 0 set to 1, the data byte in position 1 has its bit in position 1 set to 0.

    Example.  The encoded text "jaqbrcsd" decodes to the text "a1b2c3d" (greyed).  The transformed bits that are affected by the control byte are in green.

    Data Byte 1

    Data Byte 2

    Data Byte 3

    Data Byte 4

    Data Byte 5

    Data Byte 6

    Data Byte 7

    Encoded Char a q b r c s d
    Byte Stream 0x61 0x71 0x62 0x72 0x63 0x73 0x64
    Encoded Bits 0 1 1 0 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 0 0 0 1 0 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 1 0 1 1 1 0 0 1 1 0 1 1 0 0 1 0 0
    Transformed Bits 0 1 1 0 0 0 0 1 0 0 1 1 0 0 0 1 0 1 1 0 0 0 1 0 0 0 1 1 0 0 1 0 0 1 1 0 0 0 1 1 0 0 1 1 0 0 1 1 0 1 1 0 0 1 0 0
    Decoded Char a 1 b 2 c 3 d