Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Encrypted table???
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00529827
Message ID:
00529835
Views:
14
I found this one day on MSDN Site and it was in VB, i converted it in VFP, it actually compresses a string or decompress it. here is the code:


*-- Compress or decompress a text string.
Function CompressOrDecompress( cText )
*-- Initialize the dictionary.
lcDictionary = ;
" e as tinthouerhet anreesr d " + ;
"onn or o i y wo tontyo. neisarte" + ;
"ed, ctiy bat snd fal pensestve" + ;
"ngitu talehaurllcousa mf dfoof " + ;
"siril hmeg om Icehironsasiossbe" + ;
"depe rli Tetel nicho lilprcactut" + ;
"Thpaeceachh wige ebuaisursulmawa" + ;
"otowtsmploI solyee Cunm rtieno S" + ;
"diwhs.rafincademe.irplk ury Pwo" + ;
"acos gams,duayavucColamowe Aoopu"

*-- If the first character has ASCII value 255,
*-- this is a compressed string.
If Left(cText, 1) = Chr(255) Then
*-- Remove the first character.
cText = SubStr(cText, 2)
output_text = "" && Start with a blank output.
For pos = 1 To Len(cText) && examine each char
ch_value = Asc(SubStr(cText, pos, 1))
*-- See whether the ASCII value is greater than 95.
If ch_value > 95 Then
*-- This is the code in the lcDictionary for the two
*-- chars starting at pos. 2 * (_valchue - 96) + 1.
output_text = output_text + ;
SubStr(lcDictionary, (ch_value - 96) * 2 + 1, 2)
CompressOrDecompress = cText
Else
IF ch_Value = 0 OR ch_Value = 32
IF ch_Value = 0
output_text = output_text + CHR( 0 )
ELSE
output_text = output_text + CHR( 32 )
ENDIF
ELSE
output_text = output_text + CHR(ch_value + 32)
ENDIF
Endif
EndFor
Else
*-- This is a normal string. Compress it. Start with
*-- CHR(255) to indicate a compressed string.
output_text = CHR(255)
pos = 1
Do While pos <= Len(cText)
*-- Consider the two chars at pos and pos + 1.
pair = SubStr(cText, pos, 2)
*-- See whether we've passed the end
*-- of the input string.
If Len(pair) < 2 Then
*-- Set dict_pos = 0 to save this char unencoded.
dict_pos = 0
Else && Find this pair in the lcDictionary.
dict_pos = AT(pair, lcDictionary)
Do While dict_pos > 0
*--If pair is here, see whether it's at an odd index.
If MOD(dict_pos, 2) = 1
Exit
ELSE
*-- The pair is at an even position.
dict_pos = AT(pair,lcDictionary, dict_pos + 1)
Loop
Endif
ENDDO
ENDIF
*-- Add the pair's code or the first char to the output.
If dict_pos > 0 && The pair is in the lcDictionary
output_text = output_text + CHR( (dict_pos - 1) / 2 + 96 ) && Move past pair
pos = pos + 2
Else && The pair isn't in the lcDictionary.
*-- Add the first character to the output.
lcChr = SUBSTR(pair,1,1)
IF ASC(lcChr) = 0 OR ASC(lcChr) = 32
output_text = output_text + lcChr
ELSE
output_text = output_text + CHR(ASC(lcChr) - 32)
ENDIF
*-- Move past the first char in the input text.
pos = pos + 1
Endif
ENDDO && Do While pos <= Len(cText)
ENDIF && End if decompressing

RETURN output_text

EndFunc




>Hi Friends!
>
>New Trivia: Is it possible to encrypt or protect a table? All that I need it´s avoid to user to see the content, but the apllication need to take a code from the table.
>
>TIA!
Previous
Reply
Map
View

Click here to load this message in the networking platform