blowfish.writer-decrypt

function

Library: Blowfish (OMFFBLOWFISH)
Import : omffblowfish.xmd

Returns: A writable output target for streaming data.


Declaration
export string sink function
      writer-decrypt          into value string sink        output-data
                          with-key value string             encryption-key
                     trimming-mode value trimming-mode-type trimming-mode optional


Purpose

Use blowfish.writer-decrypt to write decrypted data to its value string sink output-data argument, decrypted using its encryption-key argument. The encrypted data is written to the string sink returned by the blowfish.writer-decrypt function call.

Note that the Blowfish algorithm processes data in 64-bit chunks. If the length of the input is not a multiple of 64 bits, it will be padded with null bytes. Similarly, the length of the data written to output-data by blowfish.writer-decrypt will be a multiple of 64 bits, and may therefore be null padded.

The optional trimming-mode argument can be used to specify if the null padding should be removed. The default behavior is leave null bytes. If their trimming is desired, you should specify blowfish.null-trimming as the third argument.

Example

The following example uses blowfish.writer-decrypt to decrypt a cypher text, using the output of the string source function character-dump () to get its input.

  import "omffblowfish.xmd" prefixed by blowfish.
  
  define string source function
     character-dump (value string source s)
  as
     using group "generate character dump"
        submit s
  
  process
     local string cypher-text    initial { "0b 15 cf b6 30 3c 5b bf e8 ad 3b ee 31 ce 59 5f" }
     local string encryption-key initial { "TESTKEY" }
  
     using output as blowfish.writer-decrypt          into #main-output 
                                                  with-key encryption-key 
                                             trimming-mode blowfish.null-trimming
        output character-dump (cypher-text) || "%n"
  
  group "generate character dump"
     find ul["a" to "f" | digit]{2} => n
        output "b" % (n base 16)
  
     find white-space+
        ; EMPTY
  
     find any => c
        not-reached message "An invalid character (" || c || ") was encountered in a hexadecimal stream."

Usage Note

To use blowfish.writer-decrypt, you must import OMBLOWFISH into your program using an import declaration such as:

  import "omffblowfish.xmd" prefixed by blowfish.