Re: Encryption algorithm

From: LX-i (lxi0007_at_netscape.net)
Date: 01/09/04

  • Next message: LX-i: "Re: Encryption algorithm"
    Date: Thu, 08 Jan 2004 19:14:50 -0600
    
    

    Vik Mehta wrote:
    > I am looking for a simple encryption algorithm to encrypt a 13
    > character alphanumeric string in a COBOL program. Any help will be
    > appreciated.

    There are several different things you could probably do... Some may
    consider these "obscuring" rather than "encryption", but what you get
    from these is worth every bit of what you're paying for them. :)

      - ROT-13 - This can be done by Inspect...Converting.

          Inspect My-String
            Converting "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                    to "NOPQRSTUVWXYZABCDEFGHIJKLM"

      - Reversing - Again, Inspect...Converting.

          Inspect My-String
            Converting "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                    to "ZYXWVUTSRQPONMLKJIHGFEDCBA"

    Those two only work for letters - of course, the advantage to these is
    that you run the string through the same algorithm to encode and decode.
      There are some other options as well...

      - You could convert the string to a 39-digit number by using a loop
    combined with Function Ord (which you'd decode with Function Char).

          01 My-39-Digit-Number.
              12 My-3-Digits Occurs 13 Times Pic 9(03).

          Perform Varying My-Idx from 1 by 1
            Until My-Idx > 13
              Move Function Ord (My-String (My-Idx:1))
                to My-3-Digits (My-Idx)
          End-Perform

    This has the advantage of working with pretty much any character you'd
    have in your ASCII character set.

    If you wanted to get more fancy, you could strip the highest bit off,
    making the characters 7 bits each, then cramming them all together.
    Viewed in 8-bit format, it would look like junk, and it'll handle most
    keyboard characters. Of course, that's a bit more complex, and without
    knowing the environment you're in, it's more difficult to put together a
    quick-and-dirty solution.

    There is one more option - if you're using a database system that had
    functions for one-way hashes (such as MD5 or SHA32), you can utilize
    them from within your COBOL program.

          Exec SQL
              Select MD5(:My-String)
                Into :My-Hash
                From [Any_Table]
          End-Exec

    What exactly are you wanting to do with this encrypted string? That has
    a lot to do with how you go about encrypting it. :)

    -- 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~   /   \  /         ~        Live from Montgomery, AL!       ~
    ~  /     \/       o  ~                                        ~
    ~ /      /\   -   |  ~          LXi0007@Netscape.net          ~
    ~ _____ /  \      |  ~ http://www.knology.net/~mopsmom/daniel ~
    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
    ~         I do not read e-mail at the above address           ~
    ~    Please see website if you wish to contact me privately   ~
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

  • Next message: LX-i: "Re: Encryption algorithm"

    Relevant Pages