Microsoft KB Archive/98700

= Bit Manipulation in FoxPro for Data Encryption =

Article ID: 98700

Article Last Modified on 12/3/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft FoxPro 2.0
 * Microsoft FoxPro 2.5b for MS-DOS
 * Microsoft FoxPro 2.5a
 * Microsoft FoxPro 2.5b
 * Microsoft FoxPro 2.5a

-



This article was previously published under Q98700



SUMMARY
Because FoxPro uses characters that have values between 0 and 255 (1 byte), these character values and thus the bit pattern can be manipulated once the characters are converted to numeric values using the ASC command. This sort of operation could be used for data encryption.

The program below illustrates how the bit pattern of an entire string can be swapped by rotating the bit patterns of each character one at a time and placing the resulting characters in reverse order in the output string.



MORE INFORMATION
*PROGRAM SHIFTSTR.PRG * (RUN BY TYPING 'DO SHIFTSTR.PRG WITH ') PARAMETERS A  ?A A=shift(A) ?A

PROCEDURE shift PARAMETERS in_str result=[] SET DECIMAL TO 0 lngth=LEN(in_str) DIMENSION out_array(lngth) FOR char_num=1 TO lngth x=ASC(SUBSTR(in_str,char_num,1)) y=0 FOR bit=7 TO 0 STEP -1 IF x>((2^bit)-1) x=x-(2^bit) y=y+(2^(7-bit)) ENDIF ENDFOR out_array(lngth-char_num+1)=CHR(y) ENDFOR FOR char_num=1 TO lngth result=result+out_array(char_num) ENDFOR RETURN result

Additional query words: VFoxWin FoxDos FoxWin encrypt password

Keywords: kbcode KB98700

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.