|
|
|||||||
Hi guys, It's me again, stuck as usual... I'm searching for a function that encrypts/decrypts a string. I don't need a very very secure algorithm, but I need to write a bit sensitive data to a text file and I want to prevent that people are able to read it. So I plan to encrypt the text before writing it to the text file. I do not want to encrypt the file itself, because I need to retrieve values from it during script execution via ReadProfileString() There a quite a lot VB samples available, but I'm too stupid to transform those scripts to kix. I search the UDF's but was unable to find one that does this job already... |
||||||||
|
|
|||||||
Hi Sam, Someone did do this in Kix. You could use the Vigenere UDF. Not sure if it is posted but is was the outcome of a round of KixGolf. Code: Break on ;Set the encryption key. $EncryptionKey = UCase("encryption key goes here") ;Set the text you want to encrypt. $text = "TEXT YOU WANT TO ENCRYPT" ;Encrypt text. $TextEncrypted = Vigenere($EncryptionKey, $text) ;Show encrypted text. ? $TextEncrypted ;Decrypt text. $TextDecrypted = Vigenere($EncryptionKey, $TextEncrypted, 1) ;Show decryptedt text. ?$TextDecrypted Sleep 5 ;Parameters are $key (Key, must be in uppercase), $text (string to encrypt, must be in uppercase) And $decrypt (0=encrypt, 1=decrypt). ;in this version you can define the alphabet which will be accepted, so it can be scaled to most needs: ; The alphabet used in the UDF is the classic "English letters only" version. ; If you want a richer alphabet, just change $ to reflect it, for example: ; $="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !"£$%^&*()_+{}:@~<>?,./;'#[]-="+'"' ; If you want to use lower case, don't for get to set case sensitivity on. Function Vigenere($key,$text,Optional $decrypt) Dim $range $range = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 /" While $text $i=InStr($range,Left($text,1)) If $i $Vigenere=$Vigenere+SubStr($range+$range+$range,$i+Len($range)+(1-2*$decrypt)*(Asc($key)-65),1) $key=SubStr($key,2)+Left($key,1) EndIf $text=SubStr($text,2) Loop EndFunction |
||||||||
|
|
|||||||
The CODEC (CODe-DECode) UDF is availble here and on my web site. It can encode/decode text strings using the full ASCII printable character set (codes 32-127) and can even include select control codes. By employing control codes such as CR, LF, and TAB, the actual appearance of a text document will change, although you should not use CR or LF when encoding data used in INI files. CODEC is a case-sensitive cypher tool that employs a random cypher sequence - never in natural or ASCII order - making it somewhat more difficult to hack. Note that this is not "encryption", but encoding (simple cypher) - sufficient to hide information from prying eyes. If you are looking to mask a password in a config file, this is usually enough. Glenn |
||||||||
|
|
|||||||
Just make sure that you tokenise any production script otherwise someone will just copy the decryption code and run it ![]() |
||||||||
|
|
|||||||
It would be interesting to see encryption/decryption for: TripleDES (3DES) AES (Rijndael) SHA01 (Hash) MD5 (Hash) HmacMD5 DES RSA Have fun! Kent |
||||||||
|
|
|||||||
Thanks Richard. You answered exactly what I was thinking/wondering. |
||||||||
|
|
|||||||
Tokenizing is kind of a given.. ![]() I've begun using a different (unpublished) form of CODEC that is based on a cypher used in an episode of Mission: Impossible from the late 1960's. ![]() Glenn PS - here's a sample cypher from the simple version: Code: kgt+,x*6]1io^t7nq8 w|6a⌂XyOi%f+(~~z{o$u⌂^e{⌂m1,\ )ozdx% `l{'⌂" xhvv |
||||||||
|
|
|||||||
Hi Glenn, perfect, absolutely perfect, exactly what I was looking for! Thanks to you and all the other contributors of this great board |