Re: Encryption algorithm

From: Judson McClendon (judmc_at_sunvaley0.com)
Date: 01/08/04


Date: Thu, 08 Jan 2004 16:58:42 GMT


"Vik Mehta" <aul1231@yahoo.com> 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.

How 'strongly' do you want to encrypt it? If you simply don't want it to
be read by casual observation, a technique similar to the one JerryMouse
proposed is sufficient. If you want it to resist analysis, you will need a
more powerful method.

For a simple character substitution method, reasonably secure from
casual decription, but vulnerable to analytical methods, run the
following QBASIC program. You can copy/past it Notepad or other
text editor for input into QBASIC or most any QuickBasic compatible
compiler or interpreter such as PowerBasic. Don't past it directly
into the BASIC IDE, or the indenting will get messed up. If you don't
have one, email me and I will send you a Windows/DOS executable.

---------------------------------------------------------------------
DIM Chars(255)

FOR I = 0 TO 255
   Chars(I) = I
NEXT

OPEN "TRANTAB.COB" FOR OUTPUT AS #1
PRINT #1, " 01 TRANSLATION-STRING."
PRINT #1, " 03 TS-PLAIN."
FOR I = 0 TO 255
   PRINT #1, " 05 FILLER PIC X(01) VALUE x"; CHR$(34); RIGHT$("0" + HEX$(Chars(I)), 2); CHR$(34); "."
NEXT

RANDOMIZE TIMER
FOR I = 0 TO 255
   J = INT(RND * 256)
   SWAP Chars(I), Chars(J)
NEXT
FOR I = 0 TO 255
   J = INT(RND * 256)
   SWAP Chars(I), Chars(J)
NEXT

PRINT #1, " 03 TS-ENCRIPTED."
FOR I = 0 TO 255
   PRINT #1, " 05 FILLER PIC X(01) VALUE x"; CHR$(34); RIGHT$("0" + HEX$(Chars(I)), 2); CHR$(34); "."
NEXT

CLOSE #1
END
---------------------------------------------------------------------

which will create a disk file TRANTAB.COB containing a COBOL table
description like this:

       01 TRANSLATION-STRING.
           03 TS-PLAIN.
               05 FILLER PIC X(01) VALUE x"00".
               05 FILLER PIC X(01) VALUE x"01".
                   ... (252 more entries, "02"-"FD")
               05 FILLER PIC X(01) VALUE x"FE".
               05 FILLER PIC X(01) VALUE x"FF".
           03 TS-ENCRIPTED.
               05 FILLER PIC X(01) VALUE x"C5".
               05 FILLER PIC X(01) VALUE x"2F".
                    ... (252 more random, unique entries)
               05 FILLER PIC X(01) VALUE x"5F".
               05 FILLER PIC X(01) VALUE x"72".

where the values under TS-ENCRIPTED are all the hex values 0-255
in random order. Each time you run the program you will get a different
sequence. This is to prevent anyone else from using this program to
easily decript your data. If your COBOL compiler doesn't accept the
x".." form of specifying hexidecimal literals, you will need to reformat
it for your compiler.

Copy the above 01 record into Working Storage of any program that
will encript or decript.

To encrypt a plain key use this:

           INSPECT <field>
               CONVERTING TS-PLAIN
                       TO TS-ENCRIPTED

To decrypt an encrypted key use this:

           INSPECT <field>
               CONVERTING TS-ENCRIPTED
                       TO TS-PLAIN

This should encript/decript any kind of data you can put in a PIC X(??)
data item.

-- 
Judson McClendon      judmc@sunvaley0.com (remove zero)
Sun Valley Systems     http://sunvaley.com
"For God so loved the world that He gave His only begotten Son, that
whoever believes in Him should not perish but have everlasting life."


Relevant Pages

  • Re: Crypto (ICSF) on z890 with no coprocessors
    ... For example, get the number from the Internet, or whereever, have the Cobol program call some funciton to encrypt it in memory, and then store the encrypted field in IMS, VSAM etc. ... Yes, it is possible, especially if you have CPACF enabled (it's not a card). ... For IBM-MAIN subscribe / signoff / archive access instructions, ...
    (bit.listserv.ibm-main)
  • Crypto (ICSF) on z890 with no coprocessors
    ... coprocessors) to encrypt particular fields, SSN, credit card numbers, ... (cobol for example) ... For IBM-MAIN subscribe / signoff / archive access instructions, ... send email to listserv@xxxxxxxxxxx with the message: GET IBM-MAIN INFO ...
    (bit.listserv.ibm-main)
  • Re: Function keeps remembering last val?
    ... the code as supplied does not compile (Encrypt is not ... When a function returns a result of type string, ... Secondly, because "s" as a string is referenced counted, the compiler ... Consequently, when TestFunc is first called and references "Result", ...
    (borland.public.delphi.language.objectpascal)
  • How to protect tcl source code?
    ... Kit (ActiveState), but the compiler always crashes? ... ideas how to encrypt an windows executable with blowfish?? ...
    (comp.lang.tcl)