Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
_crypt.vcx
Message
From
09/01/2007 03:45:23
Metin Emre
Ozcom Bilgisayar Ltd.
Istanbul, Turkey
 
 
To
05/01/2007 13:28:32
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, United States
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Title:
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01182913
Message ID:
01183710
Views:
18
>Is there a setting to adjust to make the encryption algorithm the same?

I'm not sure, but if remember correctly I take that from Sergey codes, I converted that work for even fox 2.x:
  mytext=cipher("my message","my password")
*----------cipher.prg----------
PARAMETERS tcStr, tcPassword

#define   PW_MIN_LEN   3        &&  /* number of chars in password */
#define   PW_MIN_NUM   1000 	  &&  /* number of digits in password return number */

priv lnStrLen, lnPassLen, lnPassNum, laPassword[1,2], lcPassword
priv lcStrOut, lnPassPos, lnNum01, lcStrOut, lnInPos, lnPassPos

IF TYPE("tcStr") <> "C" ;
		OR TYPE("tcPassword") <> "C" ;
		OR LEN(tcPassword) < PW_MIN_LEN
	retu ""
ENDIF

lnStrLen = LEN(tcStr)

* Because of the bug in the original C code we've to add CHR(0) to the password
* 		and use it later
lcPassword = tcPassword + CHR(0)
lnPassLen = LEN(lcPassword)
DIMENSION laPassword[lnPassLen+1,2]
FOR lnPassPos=1 TO lnPassLen
	laPassword[lnPassPos,2] = SUBSTR(lcPassword,lnPassPos,1)
	laPassword[lnPassPos,1] = ASC(laPassword[lnPassPos,2])
ENDFOR

* Get seed value
lnPassNum = INT((((_CipherG(lcPassword)/997) - 1) % 254) + 1 )
lcStrOut = ""
lnPassPos = 1

* Encode/decode each character
FOR lnInPos=0 TO lnStrLen-1
	* Get new seed value
	lnNum01 = (( lnPassNum + (lnInPos - lnStrLen)) - 1)
	lnPassNum = (ABS(lnNum01) % 254) * SIGN(lnNum01) + 1
	* Encode current character
	lnByte = __BITXOR( ASC(SUBSTR(tcStr,lnInPos+1,1)), ;
		__BITXOR(lnPassNum, laPassword[lnPassPos,1]))
	* Convert signed value to unsigned, if necessary
	lnByte = __BITAND(lnByte, 255)
	* If result is zero, use current character
	lcStrOut = lcStrOut + IIF(lnByte = 0, SUBSTR(tcStr,lnInPos+1,1), CHR(lnByte))
	* Advance to the next password character
	lnPassPos = IIF( lnPassPos => lnPassLen, 1, lnPassPos + 1)
ENDFOR

RETURN lcStrOut

func __bitxor
para xrakam1,xrakam2
priv xhesap1,xhesap2,xhesap3,xnum1,xnum2,xnum

xhesap1=__dectobin(xrakam1)
xhesap2=__dectobin(xrakam2)

if len(xhesap1)>len(xhesap2)
 xhesap2=repl("0",len(xhesap1)-len(xhesap2))+xhesap1
endi 

if len(xhesap2)>len(xhesap1)
 xhesap1=repl("0",len(xhesap2)-len(xhesap1))+xhesap1
endi 


xhesap3=""
for i=1 to len(xhesap1)
  xnum1=subs(xhesap1,i,1)
  xnum2=subs(xhesap2,i,1)
    do case
      case xnum1="0" and xnum2="0"
         xnum="0"
      case xnum1="0" and xnum2="1"
         xnum="1"
      case xnum1="1" and xnum2="0"
         xnum="1"
      othe
         xnum="0"
    endc
  xhesap3=xhesap3+xnum
next

retu __bintodec(xhesap3)

func __bitand
para xrakam1,xrakam2
priv xhesap1,xhesap2,xhesap3,xnum1,xnum2,xnum

xhesap1=__dectobin(xrakam1)
xhesap2=__dectobin(xrakam2)

if len(xhesap1)>len(xhesap2)
 xhesap2=repl("0",len(xhesap1)-len(xhesap2))+xhesap1
endi 

if len(xhesap2)>len(xhesap1)
 xhesap1=repl("0",len(xhesap2)-len(xhesap1))+xhesap1
endi 


xhesap3=""
for i=1 to len(xhesap1)
  xnum1=subs(xhesap1,i,1)
  xnum2=subs(xhesap2,i,1)
      if  xnum1="1" and xnum2="1"
         xnum="1"
      else
         xnum="0"
      endi
  xhesap3=xhesap3+xnum
next

retu __bintodec(xhesap3)

func _cipherg
* Returns a seed value based on the string passed as parameter
  para tcstr
	priv liRet, lnPos
	liRet = 1
	FOR lnPos=0 TO LEN(tcStr ) - 1
		liRet = liRet + ASC(SUBSTR(tcStr,lnPos+1,1)) + lnPos
	ENDFOR
	DO WHILE (liRet < PW_MIN_NUM)
		liRet = __bitlsh(liRet,1)
	ENDDO
	RETURN liRet


FUNCTION __DecToBin
* Converts POSITIVE decimal integers to BIN.
*   Input:  NUMERIC
*   Output: CHAR

        PARAMETER InNum
	OutStr=SPACE(0)

        DO WHILE InNum>0
			OutStr=STR(MOD(InNum,2),1,0)+OUTSTR 				
			InNum=INT(InNum/2)
	ENDDO
RETURN(OutStr)


FUNCTION __BinToDec
* Converts POSITIVE binary numbers (represented by Char) to decimal integer.
*   Input:  CHAR
*   Output: NUMERIC

        PARAMETER InStr
	PRIVATE ALL LIKE j*

        jnLen=LEN(ALLTRIM(InStr))
	jnSum=0

        FOR nCtr=0 TO jnLen
		IF SUBSTR(InStr,jnLen-nCtr,1)='1'
			jnSum=jnSum+(2^nCtr)
		ENDIF
	ENDFOR
RETURN(int(jnSum))


func __bitlsh
para xrakam,xkactane
priv xhesap
xhesap=__dectobin(xrakam)

xhesap=xhesap+repl("0",xkactane)
retu int(__bintodec(xhesap))
Previous
Reply
Map
View

Click here to load this message in the networking platform