3D key generator 
Author Message
 3D key generator

Hi there,

I've devised a key generator that uses a 3D matrix to store the key,
which is scrambled and scattered through the matrix at random
positions, each key location holds an encoded character and a pointer
to the next, seemingly random position. The matrix is otherwise filled
with garbage. Try to figure it out. But for a 30 char key you get a
120k file :), because I use the key length in every dimension of the
array/matrix.

Have phun.

-------
3DKEY.BAS
-------
$cpu 80386
$string 1
$compile exe

declare sub make3dkey(KeyContent$,KeyFile$)
declare sub read3dkey(KeyContent$,KeyFile$)

cls

make3dkey "Jeroen van Rijn&11111-1111111","TEST.KEY"
?:?
read3dkey KeyContent$,"TEST.KEY"
?KeyContent$

END

SUB Make3DKey(KeyContent$,KeyFile$) PUBLIC

?"Encoding "
Q%=LEN(KeyContent$)
?"Keylength:";Q%
DIM HUGE ThreeDArray(Q%,Q%,Q%) AS LONG
A%=32768
FOR X%=1 TO Q%
  A%=A% XOR ASC(MID$(KeyContent$,X%,1))
NEXT
RANDOMIZE A% 'use a as seed
A%=ABS(A% MOD 256) 'shorten and make positive for character encoding
?"Encoding with: ";A%
'First we're going to fill the array with nonsense so know one can
find
'anything.
FOR X%=1 TO Q%
  FOR Y%=1 TO Q%
    FOR Z%=1 TO Q%
      ThreeDArray(X%,Y%,Z%)=INT(RND*256^3)+1
    NEXT
  NEXT
NEXT
InitKeyX%=INT(RND*Q%)\2 'Find position to store the encoding seqeunce
InitKeyY%=INT(RND*Q%)\2
InitKeyZ%=INT(RND*Q%)\2
?"InitKeyX: ";InitKeyX%
?"InitKeyY: ";InitKeyY%
?"InitKeyZ: ";InitKeyZ%
ThreeDArray(InitKeyX%,InitKeyY%,InitKeyZ%)=A% 'store code in lsbyte
'Find next random pointer to store beginning of encoded KeyContent$.
OldX%=InitKeyX% 'store old pointer
OldY%=InitKeyY%
OldZ%=InitKeyZ%
FOR X%=1 TO Q%
  NextX%=INT(RND*Q%)+1
  NextY%=INT(RND*Q%)+1
  NextZ%=INT(RND*Q%)+1
  INCR ThreeDArray(OldX%,OldY%,OldZ%),NextX%*256   'Now store pointer
in high
  INCR ThreeDArray(OldX%,OldY%,OldZ%),NextY%*256^2 'bytes of the
longword
  INCR ThreeDArray(OldX%,OldY%,OldZ%),NextZ%*256^3 '
  OldX%=NextX%
  OldY%=NextY%
  OldZ%=NextZ%
  A%=A% XOR ASC(MID$(KeyContent$,X%,1))
  ThreeDArray(OldX%,OldY%,OldZ%)=A%
NEXT
ThreeDArray(Q%,Q%,Q%)=A% 'Copy for checking purposes
INCR ThreeDArray(Q%,Q%,Q%),InitKeyX%*256   'store code key place at
end
INCR ThreeDArray(Q%,Q%,Q%),InitKeyY%*256^2 '
INCR ThreeDArray(Q%,Q%,Q%),InitKeyZ%*256^3 '
OPEN KeyFile$ FOR OUTPUT AS #1
FOR X%=1 TO Q%
  FOR Y%=1 TO Q%
    FOR Z%=1 TO Q%
      PRINT #1, MKL$(ThreeDArray(X%,Y%,Z%));
    NEXT
  NEXT
NEXT
CLOSE #1
END SUB

SUB Read3DKey(KeyContent$,KeyFile$) PUBLIC
?"Decoding"
OPEN KeyFile$ FOR BINARY AS #1
L&=LOF(1)
Q&=L&/4
X&=0
DO
  INCR X&
  Y&=X&*X&*X&
LOOP UNTIl Y&=Q&
?"Key length:"+STR$(X&)
DIM HUGE ThreeDArray(X&,X&,X&) AS LONG
Q%=X&
FOR X%=1 TO Q%
  FOR Y%=1 TO Q%
    FOR Z%=1 TO Q%
      GET$ #1, 4, L$
      ThreeDArray(X%,Y%,Z%)=CVL(L$)
    NEXT
  NEXT
NEXT
CLOSE #1
Lastkey%=ASC(MID$(MKL$(ThreeDArray(Q%,Q%,Q%)),1,1))
InitKeyX%=ASC(MID$(MKL$(ThreeDArray(Q%,Q%,Q%)),2,1))
InitKeyY%=ASC(MID$(MKL$(ThreeDArray(Q%,Q%,Q%)),3,1))
InitKeyZ%=ASC(MID$(MKL$(ThreeDArray(Q%,Q%,Q%)),4,1))

?"InitkeyX: ";InitKeyX%
?"InitkeyY: ";InitKeyY%
?"InitkeyZ: ";InitKeyZ%
?"Lastkey : ";Lastkey%
OldX%=InitKeyX%
OldY%=InitKeyY%
OldZ%=InitKeyZ%
CodeKey%=ASC(MID$(MKL$(ThreeDArray(OldX%,OldY%,OldZ%)),1,1))
NextX%=ASC(MID$(MKL$(ThreeDArray(OldX%,OldY%,OldZ%)),2,1))
NextY%=ASC(MID$(MKL$(ThreeDArray(OldX%,OldY%,OldZ%)),3,1))
NextZ%=ASC(MID$(MKL$(ThreeDArray(OldX%,OldY%,OldZ%)),4,1))
OldX%=NextX%
OldY%=NextY%
OldZ%=NextZ%
FOR T%=1 TO Q%
  Value%=ASC(MID$(MKL$(ThreeDArray(OldX%,OldY%,OldZ%)),1,1))
  NextX%=ASC(MID$(MKL$(ThreeDArray(OldX%,OldY%,OldZ%)),2,1))
  NextY%=ASC(MID$(MKL$(ThreeDArray(OldX%,OldY%,OldZ%)),3,1))
  NextZ%=ASC(MID$(MKL$(ThreeDArray(OldX%,OldY%,OldZ%)),4,1))
  KeyContent$=KeyContent$+CHR$(Value% XOR CodeKey%)
  CodeKey%=Value%
  OldX%=NextX%
  OldY%=NextY%
  OldZ%=NextZ%
NEXT
END SUB



Wed, 07 Nov 2001 03:00:00 GMT  
 3D key generator
Hi there,

I've devised a key generator that uses a 3D matrix to store the key,
which is scrambled and scattered through the matrix at random
positions, each key location holds an encoded character and a pointer
to the next, seemingly random position. The matrix is otherwise filled
with garbage. Try to figure it out. But for a 30 char key you get a
120k file :), because I use the key length in every dimension of the
array/matrix.

Have phun.

-------
3DKEY.BAS
-------
$cpu 80386
$string 1
$compile exe

declare sub make3dkey(KeyContent$,KeyFile$)
declare sub read3dkey(KeyContent$,KeyFile$)

cls

make3dkey "Jeroen van Rijn&11111-1111111","TEST.KEY"
?:?
read3dkey KeyContent$,"TEST.KEY"
?KeyContent$

END

SUB Make3DKey(KeyContent$,KeyFile$) PUBLIC

?"Encoding "
Q%=LEN(KeyContent$)
?"Keylength:";Q%
DIM HUGE ThreeDArray(Q%,Q%,Q%) AS LONG
A%=32768
FOR X%=1 TO Q%
  A%=A% XOR ASC(MID$(KeyContent$,X%,1))
NEXT
RANDOMIZE A% 'use a as seed
A%=ABS(A% MOD 256) 'shorten and make positive for character encoding
?"Encoding with: ";A%
'First we're going to fill the array with nonsense so know one can
find
'anything.
FOR X%=1 TO Q%
  FOR Y%=1 TO Q%
    FOR Z%=1 TO Q%
      ThreeDArray(X%,Y%,Z%)=INT(RND*256^3)+1
    NEXT
  NEXT
NEXT
InitKeyX%=INT(RND*Q%)\2 'Find position to store the encoding seqeunce
InitKeyY%=INT(RND*Q%)\2
InitKeyZ%=INT(RND*Q%)\2
?"InitKeyX: ";InitKeyX%
?"InitKeyY: ";InitKeyY%
?"InitKeyZ: ";InitKeyZ%
ThreeDArray(InitKeyX%,InitKeyY%,InitKeyZ%)=A% 'store code in lsbyte
'Find next random pointer to store beginning of encoded KeyContent$.
OldX%=InitKeyX% 'store old pointer
OldY%=InitKeyY%
OldZ%=InitKeyZ%
FOR X%=1 TO Q%
  NextX%=INT(RND*Q%)+1
  NextY%=INT(RND*Q%)+1
  NextZ%=INT(RND*Q%)+1
  INCR ThreeDArray(OldX%,OldY%,OldZ%),NextX%*256   'Now store pointer
in high
  INCR ThreeDArray(OldX%,OldY%,OldZ%),NextY%*256^2 'bytes of the
longword
  INCR ThreeDArray(OldX%,OldY%,OldZ%),NextZ%*256^3 '
  OldX%=NextX%
  OldY%=NextY%
  OldZ%=NextZ%
  A%=A% XOR ASC(MID$(KeyContent$,X%,1))
  ThreeDArray(OldX%,OldY%,OldZ%)=A%
NEXT
ThreeDArray(Q%,Q%,Q%)=A% 'Copy for checking purposes
INCR ThreeDArray(Q%,Q%,Q%),InitKeyX%*256   'store code key place at
end
INCR ThreeDArray(Q%,Q%,Q%),InitKeyY%*256^2 '
INCR ThreeDArray(Q%,Q%,Q%),InitKeyZ%*256^3 '
OPEN KeyFile$ FOR OUTPUT AS #1
FOR X%=1 TO Q%
  FOR Y%=1 TO Q%
    FOR Z%=1 TO Q%
      PRINT #1, MKL$(ThreeDArray(X%,Y%,Z%));
    NEXT
  NEXT
NEXT
CLOSE #1
END SUB

SUB Read3DKey(KeyContent$,KeyFile$) PUBLIC
?"Decoding"
OPEN KeyFile$ FOR BINARY AS #1
L&=LOF(1)
Q&=L&/4
X&=0
DO
  INCR X&
  Y&=X&*X&*X&
LOOP UNTIl Y&=Q&
?"Key length:"+STR$(X&)
DIM HUGE ThreeDArray(X&,X&,X&) AS LONG
Q%=X&
FOR X%=1 TO Q%
  FOR Y%=1 TO Q%
    FOR Z%=1 TO Q%
      GET$ #1, 4, L$
      ThreeDArray(X%,Y%,Z%)=CVL(L$)
    NEXT
  NEXT
NEXT
CLOSE #1
Lastkey%=ASC(MID$(MKL$(ThreeDArray(Q%,Q%,Q%)),1,1))
InitKeyX%=ASC(MID$(MKL$(ThreeDArray(Q%,Q%,Q%)),2,1))
InitKeyY%=ASC(MID$(MKL$(ThreeDArray(Q%,Q%,Q%)),3,1))
InitKeyZ%=ASC(MID$(MKL$(ThreeDArray(Q%,Q%,Q%)),4,1))

?"InitkeyX: ";InitKeyX%
?"InitkeyY: ";InitKeyY%
?"InitkeyZ: ";InitKeyZ%
?"Lastkey : ";Lastkey%
OldX%=InitKeyX%
OldY%=InitKeyY%
OldZ%=InitKeyZ%
CodeKey%=ASC(MID$(MKL$(ThreeDArray(OldX%,OldY%,OldZ%)),1,1))
NextX%=ASC(MID$(MKL$(ThreeDArray(OldX%,OldY%,OldZ%)),2,1))
NextY%=ASC(MID$(MKL$(ThreeDArray(OldX%,OldY%,OldZ%)),3,1))
NextZ%=ASC(MID$(MKL$(ThreeDArray(OldX%,OldY%,OldZ%)),4,1))
OldX%=NextX%
OldY%=NextY%
OldZ%=NextZ%
FOR T%=1 TO Q%
  Value%=ASC(MID$(MKL$(ThreeDArray(OldX%,OldY%,OldZ%)),1,1))
  NextX%=ASC(MID$(MKL$(ThreeDArray(OldX%,OldY%,OldZ%)),2,1))
  NextY%=ASC(MID$(MKL$(ThreeDArray(OldX%,OldY%,OldZ%)),3,1))
  NextZ%=ASC(MID$(MKL$(ThreeDArray(OldX%,OldY%,OldZ%)),4,1))
  KeyContent$=KeyContent$+CHR$(Value% XOR CodeKey%)
  CodeKey%=Value%
  OldX%=NextX%
  OldY%=NextY%
  OldZ%=NextZ%
NEXT
END SUB



Wed, 07 Nov 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Search for 3d FEM mesh generator

2. Clarion 4 -Application Generator - Invalid Date when AutoNumber in Key

3. accessing 3D FFT data as 1D/3D complex/real arrays

4. ? subroutine to check if a 3D point is in the 3D region or not

5. Parser Generator/Scanner Generator for Scheme?

6. Wanted: parser-generator/lexical-analyser-generator outputting Scheme

7. Enhanced Generators - two-way generators

8. Generator syntax (was: Calling a generator multiple times)

9. generator within a generator doesn't execute?

10. F10 Key disabling the other keys

11. Problem:Want ENTER key in form to act as TAB key

12. Set(Key,Key) Question

 

 
Powered by phpBB® Forum Software