WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Miscellaneous

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Scramble UnScramble - Encrypt Decrypt Function


Keywords: Encrypt Hide Password Decrypt Simple Text String 


Question:

I know I can do this on my own but if others would find this useful I would like to see it as a function so I don't have to keep up with the code. I often need/(would like)to scramble logins/passwords that I save in ini files. I'm not looking for super high encryption but just something to deter the casual browser. Any chance?????????

Answer:

As a *large* part of out customer base is outside the USA, we try to avoid getting into any kind useful encryption issue due to the US export laws in this matter.

Although it is easier now than it was in the past, there is still a significant paperwork burden to support good encryption.

This does not mean WinBatch cannot do it, it just kinds of means we don't really want to supply the direct means to do it. So you get to write your own udfs.....

Check out:
http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/Samples~from~Users/Encryption+Encrypt~a~String.txt

The following code is not high security but is does stop the average user.

;The following code is not high security but is does stop the average user.

#DefineFunction EncryptStr( pwd )
   ;*******************************
   ; Encrypt Password
   ;*******************************
   b = StrLen( pwd )
   aa = b : "@" : pwd
   b = StrLen(aa)
   aa = aa : "JKHJY&GY&RTFUI&YGRDRDTYY*()&*(&*GYGGYR"
   aa = StrFix( aa, "&GG&^R^$", b )
   np = ""
   For x=1 To b
      xx = Char2Num( StrSub( aa, x, 1 ) )
      xx = xx + 125
      np = np : Num2Char(xx)
   Next
   pwd = ChrStringToHex( np)
   Return pwd
#EndFunction

#DefineFunction DecryptStr( pwd )
   ;*******************************
   ; Decrypt Password
   ;*******************************
   np = ChrHexToString( pwd )
   b = StrLen( np )
   orig=""
   For x=1 To b
      xx = Char2Num( StrSub( np, x, 1 ) )
      xx = xx-125
      orig = orig : Num2Char(xx)
   Next
   ;ChrHexToString
   s1 = ItemExtract( 1, orig, "@" )
   pwd = StrSub( orig, StrLen( s1 ) + 2, -1 )
   Return pwd
#EndFunction

;*******************************
; Test
;*******************************
pwd = '527532'
pswd = 'abcdefghijklmnopqrstuvwxyz0123456789'

encrypted_pswd = EncryptStr( pswd )
Pause( 'Encrypted password', encrypted_pswd )

decrypted_pswd = DecryptStr( encrypted_pswd )
Pause( 'Decrypted password', decrypted_pswd )

Exit

Article ID:   W16029
File Created: 2014:07:18:09:51:38
Last Updated: 2014:07:18:09:51:38