Page 1 of 1 1
Topic Options
#59887 - 2001-10-17 10:26 PM Password encryption algorythm
Anonymous
Unregistered


Dear all,

There have been moments when i needed to store a user's password or the one of a special "service / su" account in registry or files. That way, you could make that account log on automatically (e.g. to install Office2000 with elevated rights). I don't like storing a plain-text password in registry (even with security set on the key), as it is not exactly what i would call "secure"
So, I made an algorythm to "encrypt" those passwords. The algorythm is not too complicated: it returns a string inverted, converts it to ANSI char code and strips the separators.

e.g:

My "PaSsW)oRD" after Encrypt becomes
6882111è4187115è83978040121è77
(For stronger encryption, use 2/3 pass encryption)

Syntax:
Encrypt(ItemToEncrypt,Number of codepasses)
Decrypt(ItemToDecrypt,Number of codepasses)


;-----------------------------------Start-----------
Break ON
$o=SetConsole("AlwaysOnTop")
$o=SetAscii("ON")
Cls

"Enter a string to en- and decode:>"
Gets $String
"Enter the number of passes to encrypt the code:>"
Get $Passes
$RES=Encrypt($String,$Passes)
$p=Decrypt($res,$Passes)
?
?"The encrypted Code ="
?
?"$Res"
?
?"And the unencrypted result ="
?
?"$p"
?
?
;Encoder******************************************************************************

FUNCTION Encrypt($Source,$pass)

FOR $t=1 TO $pass STEP 1
$l=Len($Source)
Dim $Cont[$l]
Dim $i,$j
Redim $Inv[$l]
$Enc=""
$k=""
GLOBAL $Enc
?"lenght of String = $l"
?
$i=0 $j=0
FOR $i=0 TO $l-1 STEP 1
$Cont[$i]=Substr($Source,$l-$i,1)
?"Array this far = "+ $Cont[$i]
NEXT
FOR EACH $Cell IN $Cont
$k="$k" + "$Cell"
GLOBAL $Inv[$l]
$Enl=Asc($Cell)
IF $j < $l
SELECT
CASE
Len($Enl)=3
$Inv[$j]="$Enl" +"!"
CASE 1
$Inv[$j]="$Enl"
ENDSELECT
$j=$j+1
ENDIF
NEXT
?
?"The new inverted String = $k"
?
FOR EACH $El IN $Inv
$Enc="$Enc" + "$El"
?"Encrypted Array so far = $Enc"
NEXT
?
?"The Encrypted String = $Enc"

$Source=$Enc
NEXT

$Encrypt=$Enc
? "Show $Encrypt as the result"
ENDFUNCTION

;Decoder******************************************************************************

FUNCTION Decrypt($Des,$Pass)

FOR $t=1 TO $Pass STEP 1
?"Decrypt gets this input: $des, $pass"
GLOBAL $Spl
GLOBAL $SpltD
$Dec=""
$SpltD=""
$Spl=Split($Des,"!")
FOR EACH $Eld IN $Spl
$LngthE=Len($Eld)
?
?"Length of the encrypted Array Element= $LngthE"
$OddOrEven=$LngthE/2 ;Would like to see the INT change in FLOAT, but in KIX "/" always returns INT
If $OddOrEven*2 <> $LngthE ;Hence this trick
$OddorEven=1,2
Endif
$ret=VarType($OddOrEven)
SELECT
CASE VarType($OddOrEven)=3 ;An even element - Read in groups of 2
FOR $i=0 TO $LngthE-1 STEP 2
$Eldf=Substr($Eld,$i+1,2)
$EldFD=CHR($Eldf)
$SpltD="$Spltd" + "$EldfD"
? "Unencrypted cell = $EldfD"
NEXT
CASE 1
FOR $i=0 TO $LngthE-4 STEP 2 ;An odd element -Read in groups of 2 until last 3
$Eldf=Substr($Eld,$i+1,2)
$EldFD=CHR($Eldf)
? "Unencrypted cell = $EldFD"
$SpltD="$SpltD" + "$EldFD"
NEXT
? "The encrypted String this far $SpltD"
$EldLastCell=Substr($Eld,$LngthE-2,3)
$EldLastCell=CHR("$EldLastCell")
? "The last Cell of 3: $EldLastCell"
$SpltD="$SpltD" + "$EldLastCell"
ENDSELECT
NEXT
?
? "The inverted, decoded String = $Spltd, Now inverting..."
?
$l=Len($Spltd)
Dim $DCont[$l]
Dim $i,$j
$i=0 $j=0
FOR $i=0 TO $l-1 STEP 1
$DCont[$i]=Substr($Spltd,$l-$i,1)
?"Array this far = "+ $DCont[$i]
NEXT
FOR EACH $Cell IN $DCont
$Dec="$Dec" + "$Cell"

NEXT
$Des=$Dec
NEXT
$Decrypt="$Dec"
ENDFUNCTION


;------------------------end------------------


greetz,

Grrrippp!
(Stefaan Degroote)

Top
#59888 - 2001-10-18 07:06 AM Re: Password encryption algorythm
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

Welcome to the board.

So far with read your script. In some circumstances it has some usefull
possibilities.
The output result is indeed unreadable and such a piece of code is hard
to manipulate without the complete software (encrypt+decrypt parts).

It need some additional work for maintain and transfer the encrypted key to
a script, but it make it hard to modify it.

To make it hard to analyze your decryption part we transfer your code.
We have convert your variable names to mnemonic code.

uncompressed version

code:

FUNCTION Decrypt($x1,$x2)
FOR $x3=1 TO $x2 STEP 1
?"Decrypt gets this input: $x1, $x2"
GLOBAL $x4
GLOBAL $x5
$x6=""
$x5=""
$x4=Split($x1,"!")
FOR EACH $x7 IN $x4
$x8=Len($x7)
?
?"Length of the encrypted Array Element= $x8"
$x9=$x8/2 ;Would like to see the INT change in FLOAT, but in KIX "/" always returns INT
IF $x9*2 <> $x8 ;Hence this trick
$x9=1,2
ENDIF
$x10=VarType($x9)
SELECT
CASE
VarType($x9)=3 ;An even element - Read in groups of 2
FOR $x11=0 TO $x8-1 STEP 2
$x12=Substr($x7,$x11+1,2)
$x13=CHR($x12)
$x5="$x5" + "$x13"
? "Unencrypted cell = $x13"
NEXT
CASE
1
FOR $x11=0 TO $x8-4 STEP 2 ;An odd element -Read in groups of 2 until last 3
$x12=Substr($x7,$x11+1,2)
$x13=CHR($x12)
? "Unencrypted cell = $x13"
$x5="$x5" + "$x13"
NEXT
? "The encrypted String this far $x5"
$x14=Substr($x7,$x8-2,3)
$x14=CHR("$x14")
? "The last Cell of 3: $x14"
$x5="$x5" + "$x14"
ENDSELECT
NEXT
?
? "The inverted, decoded String = $x5, Now inverting..."
?
$x15=Len($x5)
DIM $x16[$x15]
DIM $x11,$x17
$x11=0 $x17=0
FOR $x11=0 TO $x15-1 STEP 1
$x16[$x11]=Substr($x5,$x15-$x11,1)
?"Array this far = "+ $x16[$x11]
NEXT
FOR EACH $x18 IN $x16
$x6="$x6" + "$x18"
NEXT
$x1=$x6
NEXT
$decrypt="$x6"
ENDFUNCTION


compressed version (by tool kixstrip):
code:

function Decrypt($x1,$x2) for $x3=1 to $x2 step 1 global $x4 global $x5 $x6="" $x5=""
$x4=Split($x1,"!") for each $x7 in $x4 $x8=Len($x7) $x9=$x8/2 if $x9*2<>$x8 $x9=1,2 endif
$x10=VarType($x9) select case VarType($x9)=3 for $x11=0 to $x8-1 step 2 $x12=Substr($x7,$x11+1,2)
$x13=CHR($x12) $x5="$x5"+"$x13" next case 1 for $x11=0 to $x8-4 step 2 $x12=Substr($x7,$x11+1,2)
$x13=CHR($x12) $x5="$x5"+"$x13" next $x14=Substr($x7,$x8-2,3) $x14=CHR("$x14") $x5="$x5"+"$x14" endselect
next $x15=Len($x5) dim $x16[$x15] dim $x11,$x17 $x11=0 $x17=0 for $x11=0 to $x15-1 step 1
$x16[$x11]=Substr($x5,$x15-$x11,1) next for each $x18 in $x16 $x6="$x6"+"$x18" next
$x1=$x6 next $decrypt="$x6" endfunction


Code has been checked and programs still works.
!!!! remark 20011020: layout of one-line has been modify to prevent an unwanted format of this board topic. !!!!
!!!! !!!!
!!!! see later: how to create such one-line statement !!!!
Greetings.


btw: to prevent more security we are using our tools codec and compress.
Complete code is unreadable, but not unbreakable with the right tools.

[ 20 October 2001: Message edited by: MCA ]

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#59889 - 2001-10-18 03:18 PM Re: Password encryption algorythm
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
WOW !!!

What did you do with this topic !?!?
My wheel mouse is catching fire

_________________________



Top
#59890 - 2001-10-18 05:13 PM Re: Password encryption algorythm
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
quote:

What did you do with this topic !?!?
My wheel mouse is catching fire

loOool Me is dizzy too

Anyways.. hmm... can't someone just use this script to decode the password? Where to store the password / script now?

Do we have a "catch 22" here, or is it just me being stupid as usual?

[ 18 October 2001: Message edited by: masken ]

_________________________
The tart is out there

Top
#59891 - 2001-10-19 06:40 AM Re: Password encryption algorythm
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Hi, focks,

It wasn't a new way of terrorism. Possible in the future something like
that is possible. Possible that another guy can influence your home
environment and let the mouse scroll on your desk.

This strange reformatting of this topic is just a problem of UBB version 6.
Also a nice way of encryption. Neary you see nothing.
Greetings.

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#59892 - 2001-10-20 09:13 AM Re: Password encryption algorythm
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

We have change above reaction for layout of this topic.
To create an one line statement without license remark we run
kixstrip input.kix output.kix /nolicense /print
Greetings.

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 781 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.043 seconds in which 0.02 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org