Author | Message | Time |
---|---|---|
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.. [img]http://img78.photobucket.com/albums/v260/Echoes512/10.jpg[/img] 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 [code] Private Sub cmdEncrypt_Click() txtCrypt2.Text = txtCrypt1.Text InStr(txtCrypt2.Text, frmSettings.txta.Text) = frmSettings.txta2.Text End Sub [/code] 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. | June 30, 2004, 8:09 PM |
CrAz3D | I think that the replace function would work quite nicely for what you're trying to do. | June 30, 2004, 11:38 PM |
Sadlittleman | [quote author=CrAz3D link=board=31;threadid=7513;start=0#msg68001 date=1088638710] I think that the replace function would work quite nicely for what you're trying to do. [/quote] 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. :( | July 1, 2004, 1:41 AM |
St0rm.iD | 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 | July 1, 2004, 2:56 AM |
Sadlittleman | [quote author=$t0rm link=board=31;threadid=7513;start=0#msg68032 date=1088650589] 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 [/quote] 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. [code] Private Sub cmdEncrypt_Click() Print Replace(txtCrypt1, frmSettings.txta.Text, frmSettings.txta2.Text, 1, 9999) End Sub [/code] 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.. [code] Private Sub cmdEncrypt_Click() Print Replace(txtCrypt1, frmSettings.txtb.Text, frmSettings.txta2.Text, frmSettings.txtb2.text, 1, 9999) End Sub [/code] ?? 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. | July 1, 2004, 3:05 AM |
St0rm.iD | basically, replace the longer strings first. | July 2, 2004, 4:00 AM |
Stealth | Not even then.. you'd probably have to do something like: [code]pseudocode ' for each letter in the string ' determine what the encoded string is for that letter ' append that string to a buffer[/code] 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. | July 2, 2004, 4:30 AM |
St0rm.iD | Well yeah, the proper way to do this is with regex. | July 2, 2004, 3:40 PM |
Sadlittleman | [quote author=Stealth link=board=31;threadid=7513;start=0#msg68185 date=1088742615] [code]pseudocode ' for each letter in the string ' determine what the encoded string is for that letter ' append that string to a buffer[/code] [/quote] 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? | July 4, 2004, 9:55 PM |
Dyndrilliac | [quote author=Stealth link=board=31;threadid=7513;start=0#msg68185 date=1088742615] Not even then.. you'd probably have to do something like: [code]pseudocode ' for each letter in the string ' determine what the encoded string is for that letter ' append that string to a buffer[/code] 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. [/quote] You could use Mid() to get around that assuming the length of the encrypted text for each character is constant for all replacements. | July 6, 2004, 2:16 AM |
Stealth | True - in his screenshot above, it is not. | July 6, 2004, 6:03 AM |
Fr0z3N | Textbox = Replace(arg1, arg2, arg3, 1, 9999) | July 6, 2004, 6:26 AM |
Sadlittleman | [quote author=Fr0z3N link=board=31;threadid=7513;start=0#msg68778 date=1089095175] Textbox = Replace(arg1, arg2, arg3, 1, 9999) [/quote] Thank you, that works well... [code] txtCrypt2 = Replace(txtCrypt1, frmSettings.txta.Text, frmSettings.txta2.Text, 1, 9999) [/code] It's working for the letter a, but if I add this: [code] txtCrypt2 = Replace(txtCrypt1, "a", frmSettings.txta2.Text, 1, 9999) txtCrypt2 = Replace(txtCrypt1, "b", frmSettings.txtb2.Text, 1, 9999) [/code] ..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: [code] txtCrypt2 = Replace(txtCrypt1, "a", frmSettings.txta2, 1, 9999) & Replace(txtCrypt1, "b", frmSettings.txtb2, 1, 9999) [/code] 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....: | July 6, 2004, 4:14 PM |
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. | July 6, 2004, 9:16 PM |
Sadlittleman | [quote author=Stealth link=board=31;threadid=7513;start=0#msg68893 date=1089148596] 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. [/quote] 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? | July 6, 2004, 10:43 PM |