Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Sadlittleman on June 30, 2004, 03:09 PM

Title: Help inquiry for a simple project...
Post by: Sadlittleman on June 30, 2004, 03:09 PM
Hello, I'm working a tool that would allow me (or any other user) to encrypt the common letters of the alphabet into a different set of characters, and then decrypt the characters back to plain English. These different characters can be user-defined in the "settings" portion of the program. I've got most of the program done, but the problem is that I just really can't figure out the most necessary part of the whole program..
(http://img78.photobucket.com/albums/v260/Echoes512/10.jpg)
Now as you can see, I would like to push the button "Encrypt," and according to the user-defined settings, the lower box would say "{d44\c." (And for the decrypt form, I could type "{d44\c." and push decrypt, and have the bottom text box say "hi.")

I have tried different lines of code, and I just really can't get it...I'm trying to teach myself VB, but I get stuck sometimes.
I am stuck with

Private Sub cmdEncrypt_Click()
txtCrypt2.Text = txtCrypt1.Text
InStr(txtCrypt2.Text, frmSettings.txta.Text) = frmSettings.txta2.Text
End Sub

and so on,
where txta is the name of settings txt box with a, and txta2 is the name of the settings txt box that contains zf2&.
and wondering why it's not working. The funny part is, I'm probably way off, though.

Sorry if this sounds "noob," but I really didn't know where else to go for help. Thanks.
<scared on the side that a random user will steal my idea and make his own version because I posted a screenshot> oh well.
Title: Re:Help inquiry for a simple project...
Post by: CrAz3D on June 30, 2004, 06:38 PM
I think that the replace function would work quite nicely for what you're trying to do.
Title: Re:Help inquiry for a simple project...
Post by: Sadlittleman on June 30, 2004, 08:41 PM
Quote from: CrAz3D on June 30, 2004, 06:38 PM
I think that the replace function would work quite nicely for what you're trying to do.
Thanks, but I know nothing about this replace function! argh.  Could you help me get started or anything? I'll definately try to figure it out first, but probably to no avail.

Edit: okay, I got it working, except the text is appearing on the background, not in the 2nd textbox. Argh, :confused:

Print Replace(txtCrypt1, frmSettings.txta, frmSettings.txta2) is for the letter "a"

Working great, but how do I make it so that it prints in txtCrypt2 (the bottom txt box).

Another edit: it's only replacing one "a" even if I type in ten, so my code must be wrong. Help meeee.    :(
Title: Re:Help inquiry for a simple project...
Post by: Banana fanna fo fanna on June 30, 2004, 09:56 PM
replace(arg1, arg2, arg3, 1, 9999)

Also, in the future you might run into the "lookahead" problem. Just warning you in advance; try your program with this:
A => XXA
B => XXAB
Title: Re:Help inquiry for a simple project...
Post by: Sadlittleman on June 30, 2004, 10:05 PM
Quote from: $t0rm on June 30, 2004, 09:56 PM
replace(arg1, arg2, arg3, 1, 9999)

Also, in the future you might run into the "lookahead" problem. Just warning you in advance; try your program with this:
A => XXA
B => XXAB

ok thanks, I understand the 1, 9999 part, but the how do I make the text appear in textbox 2 (the lower one)...it's just appearing on the background.


Private Sub cmdEncrypt_Click()
Print Replace(txtCrypt1, frmSettings.txta.Text, frmSettings.txta2.Text, 1, 9999)
End Sub




Oh...and sorry that I'm not getting this quite like you might like, but what do you mean A => XXA and B => XXAB?

do you mean like..for b..

Private Sub cmdEncrypt_Click()
Print Replace(txtCrypt1, frmSettings.txtb.Text, frmSettings.txta2.Text, frmSettings.txtb2.text, 1, 9999)
End Sub


??


I'll take any insults if appropriate, like dumb noob or whatever, I just don't have quite the understanding of the language that you do.
Title: Re:Help inquiry for a simple project...
Post by: Banana fanna fo fanna on July 01, 2004, 11:00 PM
basically, replace the longer strings first.
Title: Re:Help inquiry for a simple project...
Post by: Stealth on July 01, 2004, 11:30 PM
Not even then.. you'd probably have to do something like:

[b]pseudocode[/b]

' for each letter in the string
'     determine what the encoded string is for that letter
'     append that string to a buffer


Using replace, you run into situations like:

y replaced with cdz\1
z is replaced with 9fch

"yz" would become first "cdz\1z", then "cd9fch\19fch" and your encryption system bites the dust.
Title: Re:Help inquiry for a simple project...
Post by: Banana fanna fo fanna on July 02, 2004, 10:40 AM
Well yeah, the proper way to do this is with regex.
Title: Re:Help inquiry for a simple project...
Post by: Sadlittleman on July 04, 2004, 04:55 PM
Quote from: Stealth on July 01, 2004, 11:30 PM
[b]pseudocode[/b]

' for each letter in the string
'     determine what the encoded string is for that letter
'     append that string to a buffer


If this is asking too much just tell me, but I just don't know where to start...how would I go about doing that?
Title: Re:Help inquiry for a simple project...
Post by: Dyndrilliac on July 05, 2004, 09:16 PM
Quote from: Stealth on July 01, 2004, 11:30 PM
Not even then.. you'd probably have to do something like:

[b]pseudocode[/b]

' for each letter in the string
'     determine what the encoded string is for that letter
'     append that string to a buffer


Using replace, you run into situations like:

y replaced with cdz\1
z is replaced with 9fch

"yz" would become first "cdz\1z", then "cd9fch\19fch" and your encryption system bites the dust.

You could use Mid() to get around that assuming the length of the encrypted text for each character is constant for all replacements.
Title: Re:Help inquiry for a simple project...
Post by: Stealth on July 06, 2004, 01:03 AM
True - in his screenshot above, it is not.
Title: Re:Help inquiry for a simple project...
Post by: Fr0z3N on July 06, 2004, 01:26 AM
Textbox = Replace(arg1, arg2, arg3, 1, 9999)
Title: Re:Help inquiry for a simple project...
Post by: Sadlittleman on July 06, 2004, 11:14 AM
Quote from: Fr0z3N on July 06, 2004, 01:26 AM
Textbox = Replace(arg1, arg2, arg3, 1, 9999)

Thank you, that works well...


txtCrypt2 = Replace(txtCrypt1, frmSettings.txta.Text, frmSettings.txta2.Text, 1, 9999)


It's working for the letter a, but if I add this:


txtCrypt2 = Replace(txtCrypt1, "a", frmSettings.txta2.Text, 1, 9999)
txtCrypt2 = Replace(txtCrypt1, "b", frmSettings.txtb2.Text, 1, 9999)


..it only works for b. How could I do it for multiple letters? Should it all be in one subfunction? or what?

doing it like this works except for one tiny thing:


txtCrypt2 = Replace(txtCrypt1, "a", frmSettings.txta2, 1, 9999) & Replace(txtCrypt1, "b", frmSettings.txtb2, 1, 9999)


a shows up as "zf2&a" when it should show up as "zf2&"
b shows up as "b4z9" when it should show up as "4z9"
ab comes up as "zf2&ba4z9" when it should say "zf2&4z9"

:frustrated....:
Title: Re:Help inquiry for a simple project...
Post by: Stealth on July 06, 2004, 04:16 PM
We just got done telling you that it WON'T work well..

In any event, you're replacing wrong. You should use txtCrypt2 in the second (and any subsequent) Replace() calls.
Title: Re:Help inquiry for a simple project...
Post by: Sadlittleman on July 06, 2004, 05:43 PM
Quote from: Stealth on July 06, 2004, 04:16 PM
We just got done telling you that it WON'T work well..

In any event, you're replacing wrong. You should use txtCrypt2 in the second (and any subsequent) Replace() calls.

I didn't hear anyone say "it won't work well", people just weren't helping.

Sorry, I admitted up front that I am probably doing it all wrong and that I needed help, didn't I?

So you're saying that this is impossible now?