#198132 - 2010-03-23 10:18 AM
Encrypt/Decrypt a string with kix
|
Sam_B
Getting the hang of it
Registered: 2005-10-25
Posts: 68
Loc: Bern, Switzerland
|
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...
|
Top
|
|
|
|
#198133 - 2010-03-23 10:54 AM
Re: Encrypt/Decrypt a string with kix
[Re: Sam_B]
|
Mart
KiX Supporter
   
Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
|
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.
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
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
Top
|
|
|
|
#198140 - 2010-03-23 04:57 PM
Re: Encrypt/Decrypt a string with kix
[Re: Glenn Barnas]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Just make sure that you tokenise any production script otherwise someone will just copy the decryption code and run it
|
Top
|
|
|
|
#198142 - 2010-03-23 05:49 PM
Re: Encrypt/Decrypt a string with kix
[Re: Richard H.]
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
It would be interesting to see encryption/decryption for: TripleDES (3DES) AES (Rijndael) SHA01 (Hash) MD5 (Hash) HmacMD5 DES RSA
Have fun!
Kent
|
Top
|
|
|
|
#198153 - 2010-03-24 07:58 AM
Re: Encrypt/Decrypt a string with kix
[Re: Glenn Barnas]
|
Sam_B
Getting the hang of it
Registered: 2005-10-25
Posts: 68
Loc: Bern, Switzerland
|
Hi Glenn, perfect, absolutely perfect, exactly what I was looking for! Thanks to you and all the other contributors of this great board
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 86 anonymous users online.
|
|
|