Miggy, you need to multiply the ASC value of each character in the password by its position in the string, otherwise "DOG", "GOD", "OGD", etc. are all equivalent.
Here are a couple of variants. The first uses the infamous XOR encryption scheme (actually, a substitution but it's hard to unscramble since it uses all 256 characters) and the second uses substitution but only encrypts the letters A-Z and numbers 0-9 (handy when you want to send it in the body of an email).
[tt]
DECLARE FUNCTION XORcrypt$ (Cry$, Password$)
DECLARE FUNCTION Subst$ (Cry$, Password$)
CLS
INPUT "Enter first message: "; Clear1$
INPUT "Enter first password: "; Password1$
EncryptedText1$ = XORcrypt$(Clear1$, Password1$)
PRINT "Encrypted: "; EncryptedText1$
DeCrypted1$ = XORcrypt$(EncryptedText1$, Password1$)
PRINT "Decrypted: "; DeCrypted1$
INPUT "Enter second message: "; Clear2$
INPUT "Enter second password: "; Password2$
EncryptedText2$ = Subst$(Clear2$, Password2$)
PRINT "Encrypted: "; EncryptedText2$
Clear$ = Subst$(EncryptedText2$, Password2$)
PRINT "Decrypted: "; Clear$
[/tt]
'First method _________________________________
[tt]FUNCTION XORcrypt$ (Cry$, Password$)[/tt]
' Create a randomizing seed
' from the password
[tt]FOR Re = 1 TO LEN(Password$)
PassKey& = PassKey& + ASC(MID$(Password$, Re, 1)) * Re
NEXT
RANDOMIZE PassKey&
aa = RND(-1)[/tt]
' XOR the data
[tt]FOR Re = 1 TO LEN(Cry$)
MID$(Cry$, Re, 1) = CHR$(ASC(MID$(Cry$, Re, 1)) XOR INT(256 * RND))
NEXT
XORcrypt = Cry$
END FUNCTION
[/tt]
'Second method ___________________
[tt]FUNCTION Subst$ (Cry$, Password$)[/tt]
'Build clear key consisting of
'only the normal text characters
'Chr$(32) (SPACE) to Chr$(126) "~"
[tt]FOR Re = 32 TO 126
G$ = G$ + CHR$(Re)
NEXT
G1$ = G$ 'G$ will be destroyed[/tt]
'Create a randomizing seed from the password[tt]
FOR Re = 1 TO LEN(Password$)
PassKey& = PassKey& + ASC(MID$(Password$, Re, 1)) * Re
NEXT
RANDOMIZE PassKey&
aa = RND(-1)
G2$ = STRING$(LEN(G1$), 255)
G3$ = STRING$(LEN(G1$), 255)
Re = 1[/tt]
'Create a random substitution string in G2$[tt]
DO UNTIL G$ = ""
P = INT(LEN(G$) * RND + 1)
ip$ = MID$(G$, P, 1)
MID$(G2$, Re, 1) = ip$
Re = Re + 1
E = LEN(G$)
SELECT CASE P
CASE 1
G$ = RIGHT$(G$, E - 1)
CASE E
G$ = LEFT$(G$, E - 1)
CASE ELSE
G$ = LEFT$(G$, P - 1) + RIGHT$(G$, E - P)
END SELECT
LOOP
FOR Re = 1 TO LEN(G1$)
T1$ = MID$(G1$, Re, 1)
L1 = 0
IF INSTR(G3$, T1$) < 1 THEN
FOR Re2 = LEN(G1$) TO 1 STEP -1
IF MID$(G3$, Re2, 1) = CHR$(255) THEN
L1 = Re2
EXIT FOR
END IF
NEXT
MID$(G3$, L1, 1) = T1$
T2$ = MID$(G2$, L1, 1)
L2 = INSTR(G2$, T1$)
MID$(G3$, L2, 1) = T2$
END IF
NEXT
'Perform the actual substitution encryption
FOR Re = 1 TO LEN(Cry$)
F = INSTR(G2$, MID$(Cry$, Re, 1))
IF F > 0 THEN
MID$(Cry$, Re, 1) = MID$(G3$, F, 1)
END IF
NEXT
Subst = Cry$
END FUNCTION
Alt255@Vorpalcom.Intranets.com