ear Friends,
Here is Version 1.2 of RateCrypt() below.
Thanks to all
-Mel Smith
------------------- snip -----------------------------
FUNCTION RATECRYPT(cCRYPT,nRATE,cEMPNUM)
// Author: Mel Smith, Aug 17, 2006
// With Lots of Help from the Guys on the c.l.g newsgroup
// Aug 18/06 -- Version 1.2
// 1. Removed Duplicate Code / Re-structured
// 2. Changed NUROUND() to standard ROUND()
// (Thanks to BillRobertson)
// 3. Changed the nMININC 'define' to lessen 'loops'
// (But would like to find a way to eliminate this step)
/*
My wish with this function is to create an encrypted rate which will
'fit' in the same field as the actual rate, but will have a value
that will be obvious (to my function) as either encrypted (or actual).
Thus, this function allows the programmer to 'obscure' an employee's
hourly
Rate from casual viewing (using database viewing software) by his peers.
The technique uses a pseudo Random Number generator copied/modified
from NanForum's rand1.prg
The mods include using the '%' operator (instead of the MOD() function),
and later including an organization's own code (nORGCODE) to
differentiate
it from other orgs who would also use this function.
I also have to deal with variously-structured 'Employee Numbers' which
require some extra coding below. *My* Employee numbers are (for now)
either, for example, 'R1234' or '59028'. So I have to use either
*all* digits or the right-most 4 digits.
*/
#define nB 31415621 // Good old 'PI' is used here
#define nM 100000000 // The widest possible range of values
#define nMIN 60000 // Minimum returned value from encryption
#define nMAX 99999 // Maximum returned value from encryption
#define nMININC 10000 // To 'boost' the nCODEBASE to within limits ----
Version 1.2 change
#define nORGCODE 1234 // Choose Your own private org's code here --
NEVER CHANGE !
#define nMINLENEMP 5 // Minimum input allowable length of employee
number
#define nMINCODERATE 400 // Any value > nMINCODERATE is already encrypted
LOCAL I,nSEED,nEMPVAL,nCODEBASE,nCODERATE,cDIGSTR,nDECRYPRATE
GABORT := .T. // Global 'Abort' indicator for Calling routine
// Assume failure at the outset
IF EMPTY(nRATE) // I won't encrypt a 'zero' Rate
RETURN nRATE
ENDIF
cEMPNUM := ALLTRIM(cEMPNUM)
IF EMPTY(cEMPNUM) .OR. LEN(cEMPNUM) < nMINLENEMP // Faulty Employee Number
RETURN nRATE
ENDIF
// Try to use *both* the n-digit Employee Numbers and also
// the letter + (n-1)-digit Employee Numbers used by other related orgs.
IF ISDIGIT(cEMPNUM) // THEN WE CAN USE ALL n DIGITS
nEMPVAL := VAL(cEMPNUM)
ELSE // ELSE ONLY USE THE RIGHT-MOST n-1 DIGITS
IF .NOT. ISDIGIT(cDIGSTR:=SUBSTR(cEMPNUM,2,10)) // THEN WE HAVE A
NON-CONFORMING EMPNUM
RETURN nRATE
ENDIF
nEMPVAL := VAL(cDIGSTR)
ENDIF
// Now we have a proper Employee 'Number' to work with as part of our seed
// nCodeBase calcs was moved and structure below changed from 1st version
// Modify the 'Seed' for your own organization's purposes
nSEED := nEMPVAL + nORGCODE // The seed is different for each different
// Employee Number (+ the Org's own code)
// This next line is from the NanForum 'Rand1.prg' module and
// authors Gary Baren and 'Glenn'