• Welcome to Valhalla Legends Archive.
 

Help inquiry for a simple project...

Started by Sadlittleman, June 30, 2004, 03:09 PM

Previous topic - Next topic

Sadlittleman

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..

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.

CrAz3D

I think that the replace function would work quite nicely for what you're trying to do.
rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...

Sadlittleman

#2
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.    :(

Banana fanna fo fanna

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

Sadlittleman

#4
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.

Banana fanna fo fanna

basically, replace the longer strings first.

Stealth

#6
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.
- Stealth
Author of StealthBot

Banana fanna fo fanna

Well yeah, the proper way to do this is with regex.

Sadlittleman

#8
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?

Dyndrilliac

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.
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

Stealth

True - in his screenshot above, it is not.
- Stealth
Author of StealthBot

Fr0z3N

Textbox = Replace(arg1, arg2, arg3, 1, 9999)

Sadlittleman

#12
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....:

Stealth

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.
- Stealth
Author of StealthBot

Sadlittleman

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?