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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make textbox not reformat the information stored with in it

Status
Not open for further replies.

DarkMercenary44

Technical User
May 19, 2000
55
US
I'm making an encryption program, and I'm haveing a problem. When I encrypt the text, then put it in a text box and then try to decrypt it, the encrypt algorit, gives me a boat load of errors. I just recently found out that when you use encrypts and you put the results in a text box that the text box reformats it, but how can I get rid of this so that what you see is what you get in side the textbox. It does work if I put the encrypted text into the tag property, but not in the textbox itself. Anyone know a way around this. DarkMercenary
darkmercenary44@earthlink.net

In the real world
As in dreams
Nothing is quite
What it seems
:Book of Counted Sorrows
 
Can't really help with the textbox reformatting, except to say that if you attempt to place intrinsic values in any control, they will generally be interperted by the controls. Examples of this include Cr, Lf, ...

On the other hand.

Even attempting to put the encrypted "text" into a visible control seems a little off the 'beaten path'. It would appear that at least part of the point of encryption would be to keep those w/o the encryption key(s) from getting to the content? Why would you put into a visible control?



MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
Well for one, you would have to put the text into a visible control. its an email encryption program, and a AOL Instant Messanger encrypter. The only one that I can get to work that vb does not reformat is RC4. I've got to figure out a way to get the other ones to work, SkipJack, BlowFish, TwoFish,DES,SimpleXor,TEA,Gost, and CryptAPI.

Thats the delima. I've even tried a RichTextBox Control and that don't work. I know it can be done, there's other emailers out there that put the encrypted text into a textbox and send it via email. DarkMercenary
darkmercenary44@earthlink.net

In the real world
As in dreams
Nothing is quite
What it seems
:Book of Counted Sorrows
 
I don't see why the Rich Text control didn't work for you (as long as you were using the correct methods). I had to test it just to make sure. This snippet reads a binary file into a string, loads the binary file into an RTF box and then checks to make sure the string and the RTF contents are identical (then it encrypts and decrypts the strings using a simple transformation to make sure the strings remain identical):
[tt]
Private Sub Form_Load()
Password$ = "3gQ9kKz"
'Read the file into a string
FiName$ = "d:\windows\win.com"
ff = FreeFile
Open FiName$ For Binary As #ff
GetFile$ = String$(LOF(ff), 0)
Get #ff, 1, GetFile$
Close #ff
Original$ = GetFile$
'Load the file into the control
RTF1.LoadFile FiName$
RTF1.SelStart = 0
RTF1.SelLength = Len(RTF1.Text)
'place the contents of the control into a string
GetRTF$ = RTF1.SelText
RTF1.SelLength = 0
If GetRTF$ = GetFile$ Then
MsgBox "The clear strings are identical."
End If
'Encrypt the 1st string with the password
Send$ = GetFile$
GetFile$ = Encrypt$(Send$, Password$)
'Encrypt the 2nd string with the password
Send$ = GetRTF$
GetRTF$ = Encrypt$(Send$, Password$)
If GetRTF$ = GetFile$ Then
MsgBox "The encrypted strings are identical."
End If
'Decrypt the 1st string with the password
Send$ = GetFile$
GetFile$ = Encrypt$(Send$, Password$)
'Decrypt the 2nd string with the password
Send$ = GetRTF$
GetRTF$ = Encrypt$(Send$, Password$)
If GetRTF$ = GetFile$ Then
MsgBox "The decrypted strings are identical."
End If
If GetRTF$ = Original$ Then
MsgBox "The encryption transformation works perfectly."
End If
End Sub

Function Encrypt$(Modify$, Password$)
StP = 1
For Re = 1 To Len(Modify$)
Mid$(Modify$, Re, 1) = _
Chr$(Asc(Mid$(Modify$, Re, 1)) _
Xor Asc(Mid$(Password$, StP, 1)))
StP = StP + 1
If StP > Len(Password$) Then StP = 1
Next
Encrypt$ = Modify$
End Function
[/tt]

One must remember that the RTF and Text Box controls do not necessarily correctly display all of the characters they contain and, of course, using RTF1.SaveFile will not save the original contents back to the file... only overwrite it with a Rich Text version.
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
I uploaded a small project to the following web-site. It uses a nasty little encryption scheme (XOR and substitution) that renders all characters into letters A-Z (the results are easy to e-mail):
Start the project and paste the following string into the lower-left Rich Text box. The RTF to its right will instantly translate it to clear text (providing you don't change the "default" password).

DSeuzeqzizGVxvHHEiTGFxSRhgHxHRwXyxVfVvwIEvdxvUxzYRTghGUVYyRDrwXeHYUuHzxYxQhyYXgIyXzEzWiqXHwFZQ

It is a fairly simple matter to type or paste in the "Clear Text" box and and copy the contents of the "Ecrypted ASCII" box into an email, or copy an encrypted email into the "Ecrypted ASCII" box and read the clear text on the right. I didn't include any provisions for sending or receiving the email (supposedly with ShellExecute) since I assume you have already worked out those details.

I hope this helps or, at least, gives you some ideas you hadn't considered.
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
I think I've figured it out, I can change it into binary format. Hopefully it will generate a binary code for every character, :). The only problem I see with that is the file will grown 8 times for every character :( I may try and encrypt to binary , then use one of the algoritoms which dont' use the 'other' characters to encrypt it again.

Don't know , I let you all know how it turns out, thanks for all the help DarkMercenary
darkmercenary44@earthlink.net

In the real world
As in dreams
Nothing is quite
What it seems
:Book of Counted Sorrows
 
Well the binary encrypt works, but the output is HUGE!!!.. So thats a no go.

darkmercenary44@earthlink.net

In the real world
As in dreams
Nothing is quite
What it seems
:Book of Counted Sorrows
 
Thanks for all your help guys I figured it out. I convert the encrypted data into hex format, I still gain a fraction of size, but not as much as with binary, and ALL 9 of the crypts work, so its cool.

Sometimes it just helps to talk about it for awhile, hehe :)

Thanks again. DarkMercenary
darkmercenary44@earthlink.net

In the real world
As in dreams
Nothing is quite
What it seems
:Book of Counted Sorrows
 
I'm glad you found a solution. Sorry we couldn't help more. :)
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top