Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Encryption meathods? 1

Status
Not open for further replies.

eliuker

Programmer
Jul 11, 2000
12
0
0
US
I am looking into some encryption meathods that use passwords (ie not hardcoded algrothims) any ideas anyone?
 
IF you are planning on using just the basics (letters, numbers, punctuation), you can do an encryption method I like....

It uses a password to determine what each character will turn out after encrypted, like you needed. First you need to determine a sequence for all of the characters you're going to use. This allows you to reference each one either as an array element or as a portion of a string. (I think the latter would work better.) Anyway, you write the string down and choose a password. Then write the password as many times as necessary under the string you want to encrypt. Now shift each character in the string forward equal to the value of the character in the password under it. To decrypt, just shift each character backwards instead. I know this might be a little difficult to understand, so here's a little illustration for if your characters are just the 26 letters plus a space and period at the end:
[tt]
This is the stuff you want encrypted right here.
passwordpasswordpasswordpasswordpasswordpassword
^
|
|
-------- shift this character forward 16 spaces
[/tt]

I know this sounds more like a cipher to send secret messages back and forth than a computer encryption program, but this is one of the basic ways to do what you're trying to do. You can probably make it better with a few quick modifications.

Hope this helps and good luck!
 
Here's another quicky suggestion based on your question:

Add up the ascii values of each letter in the password. Say the password is "MOM" (that's ASC values 77+79+77, respectfully). This total is 233. Then use the integer division (see below) and the return is 8.

Now you do a loop and a for len of password, re-iterating until EOF, it's best to use a seek stmt in this case:

{val of password} 8 [plus]"+" {ascii value of a letter in the file you wish to encrypt} [minus]"-" {position of letter within password}

***** sample output *****
'Password = "MOM" = 233\26 = 8
'Positions = 3 ("M", "O", "M") get it???
'MyFile.txt contains one word on one line and
' coincedentially, it is "MOM"
'[tt]
8 + 77 - 1 = 84 (first letter is "M", now it's "T")
8 + 79 - 2 = 85 (second letter is "O", now it's "U")
8 + 77 - 3 = 82 (thrid letter is "M", now it's "R")
^ ^ ^ ^
| | | |
| | | new value
| | |
| | position in password
| |
| file's letter's ascii #
|
PassWord integer[/tt]

To decode the file you reverse the math functions.

In conclusion, based on a password being [red]MOM[/red], MyFile.txt that used to contain "MOM" now contains the word "TUR".

Obviously, if the Password is wrong in either length or by ascii tally, then the old saying "garbage in, garbage out" will apply. The person will not be able to read the text.

Unfortunately, all cyphering programs must be hardcoded or else someone will be able to analyze the routine(s) and break your code. Good luck in your endeavours.

Hope this is a clear enough method for you.

-MiggyD

 
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

VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Thanks for correcting me, Alt255. I had forgotten about that. I guess I didn't have enough coffee when I was answering it. Oh well, I did have the correct premis though.

Here's a for watching my &quot;back&quot; (or &quot;code&quot; as it were).

--MiggyD
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top