-
decrypt txt file?
I have a txt file that is encrypted.
It has many lines of encrypted data.
How would i parse the file then decrypt it, then the new file has the same spaces but is decrypted?
Last edited by WeightOver2001; 02-25-2009 at 07:57 AM.
-
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
 Originally Posted by Hack
How was it encrypted?
Printed off items from listview (XorEncrypt(listview(i)).
Any ideas how to decrypt the file now so that it successfully decrypts yet also stays in the spaces from the original file?
encrypted
encrypted
encrypted
encrypted
encrypted
encrypted
=
test
test
test
test
test
test
-
 Originally Posted by WeightOver2001
(XorEncrypt(listview(i)).
Never heard of it...is there a corresponding XorDecrypt?
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
It was an example for the sake of telling you how to do it, it just encrypts the listview items one by one.... so is there a way to decrypt the entire file ?
-
 Originally Posted by WeightOver2001
stays in the spaces from the original file?
I am not sure exactly what you mean by that; but what you can do is read
in the file line by line, decrypt each line and print that to a new file. If the
line is blank then you just print it out to the new file without decrypting it.
When you are done you will have a new file that looks just like your example.
At that point you can even delete the old file and rename the new file to
match the name of the old one....if you want...or you could move the old
file to a different folder, for backup, and then rename the new one...
-
Why doesn't this code successfully decrypt a logfile?
Code:
l_FF = FreeFile
lFF2 = FreeFile
Open txtFile.Text For Input As #l_FF
Do Until EOF(l_FF) = True
Input #l_FF, l_Buf
l_Log = l_Buf
If LenB(l_Log) <> 0 Then
l_Path = RC4HexDecrypt(l_ProfileName, txtPass.Text)
Open strPath For Output As #lFF2
Print #lFF2, l_Path
Close #lFF2
End If
Loop
Close #l_FF
Its using the RC4HexEncrypt/Decrypt module you made.
Last edited by WeightOver2001; 02-25-2009 at 07:57 AM.
-
So many problems, where do I start???
First - FreeFile returns the next available file number, so:
l_FF = FreeFile
lFF2 = FreeFile
assigns the same file number to both l_FF and lFF2
Next - Input # is for reading in individual values from the file
if you want to read an entire line you need to use Line Input #
Next - LenB() is the wrong function for ordinary strings use Len() instead
Next - RC4HexDecrypt is not decrypting what was read from the file
it is decrypting the same value each time, whatever is in l_ProfileName
you should change this to l_Log
Next - You keep opening, printing, and closing your output file for each item
read from the Input file. This is not only slower because you keep opening
and closing the file; but it also resets the file pointer so each new item
overwrites the old item. When you are done all you will have is the last thing
written to the file.
Next - you included the print to the output file inside your IF/EndIF block so
now only the Decrypted Data is written to the new file. Any empty lines
used for spacing will not make it into the new file. Basically you lose your
spacing.
FYI: your variable naming is incorrect and inconsistant.
A few tips:
- Use either underscores or Capitalization to seperate words
- Ex: FirstName or first_name ... strBuf or str_buf ... lIndex or l_index
- Be consistant, either use underscores or don't, and don't mix the two
- don't use the same prefix letters for different data types, 'l' usually means
Long, but you used it for both longs and strings
- I don't use prefix letters on simple control variables, like variables used
as loop counters, or simple string buffers, like I for my For/Next loops and
buf for a simple string buffer.
- Most important is to be consistant. Years later if you need to modify a piece
of old code, it's nice to not have to waste time trying to figure out what each
variable was used for.
Ok now for the revised version of your routine. I made it a Sub for testing and
I did not bother to use a form with controls, so I change txtFile and txtPass
to just String variables and hard coded the file names and password. I didn't
have the password you used to create your test data so my results were not
very readable, but it ran and correctly created the new file 'logfile2.log'
Code:
Sub DecryptFile()
Dim txtFile As String
Dim txtPass As String
Dim strPath As String
Dim buf As String
Dim log As String
Dim lFF As Long
Dim lFF2 As Long
txtPass = "409"
txtFile = App.Path & "\logfile.log"
strPath = App.Path & "\logfile2.log"
'open Input file
lFF = FreeFile
Open txtFile For Input As #lFF
'open output file
lFF2 = FreeFile
Open strPath For Output As #lFF2
'read through the input file
Do Until EOF(lFF) = True
Line Input #lFF, buf
log = Trim$(buf)
'if there is data then decrypt it
If Len(Log) <> 0 Then
buf = RC4HexDecrypt(log, txtPass)
End If
'write the line to output file
Print #lFF2, buf
Loop
'all done so close files
Close #lFF, #lFF2
End Sub
-
Thanks it semi-works. Why does it decrypt only some of it? Is because how its being printed off, can their not be a space?
~decrypt
type: vðH0> †cE
registered: ’Ð;¹Øžb|'óß;ˆ
user: ‘Ü*úÍš
date: ƒÁ.óБ
~what it is
type: xaQ2
registered: 24654-45423-35353
user: Weight
date: 2009
~encrypted
AB58CBC34899AAB58CD5684954899AAB58C
BC3D564899AAB58C84954899AAB58C
4899AAB58CBC3D5684954899AAB58C
99BC3D5684954899AAB54899AAB58C8C
-
What is the password that you used to encrypt it.
-
I solved the problem, thanks for the help.
Last edited by WeightOver2001; 02-17-2009 at 01:04 AM.
Similar Threads
-
By ajshap1 in forum VB Classic
Replies: 4
Last Post: 04-19-2007, 11:52 AM
-
By partyk1d24 in forum Web
Replies: 0
Last Post: 03-30-2007, 12:47 PM
-
By Andrew McLellan in forum Java
Replies: 3
Last Post: 05-09-2001, 05:34 PM
-
By Imran in forum ASP.NET
Replies: 0
Last Post: 08-26-2000, 05:08 AM
-
Replies: 1
Last Post: 08-23-2000, 07:36 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks