|
-
Oct 7th, 2002, 08:25 AM
#1
Thread Starter
Fanatic Member
*** Creating my own binary file thingo.... ***
Hi All!
I am only really a newbie with file handling. I can open a file, and read text from it, but thats about it.
What I'm looking to do is make my own file, with a header, and the data. The header will contain some sort of encrypted password string, and the data will contain a normal file (*.jpg, *.mpg).
If anyone could give me some sort of an idea on how to do this, or a demonstration, please reply, as I really want to learn how to do this.
Thanks in advance,
Last edited by tim_l_012; Oct 7th, 2002 at 10:45 PM.
/: Tim :\____________________
\: VB, HTML, ASP, VBScript, QBASIC, JavaScript :/
-
Oct 7th, 2002, 10:00 AM
#2
Frenzied Member
Take a look at User Define Types. Some examples of a similar sort are already available in earlier threads
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Oct 7th, 2002, 10:11 AM
#3
Thread Starter
Fanatic Member
I think i might have found something, but could you guys post some links or some source for me to check out??
Thanks in advance,
/: Tim :\____________________
\: VB, HTML, ASP, VBScript, QBASIC, JavaScript :/
-
Oct 7th, 2002, 10:12 AM
#4
Frenzied Member
Sure, 2 Secs...............
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Oct 7th, 2002, 10:17 AM
#5
Frenzied Member
VB Code:
'Needs one PictureBox, one Command Button
Private Type myBITMAP
Data() As Byte
Category As String * 4
Comments As String * 50
End Type
Private Sub Command1_Click()
Dim newPic As myBITMAP
'Read in a standard Bitmap
Open App.Path & "\Clouds.bmp" For Binary As #1
ReDim newPic.Data(LOF(1))
Get #1, , newPic.Data
Close #1
newPic.Category = "WPPR"
newPic.Comments = "Source: WIN98"
'Write our Bitmap
Open App.Path & "\NewPic.bmp" For Binary As #1
Put #1, , newPic
Close #1
MsgBox "done"
'Read the file back
Open App.Path & "\NewPic.bmp" For Binary As #1
'Leave the string values and take the rest
ReDim newPic.Data(LOF(1) - 108)
Get #1, , newPic
Close #1
'Write to the picture to temporary file for
'displaying in a picture box
Open App.Path & "\tmpFile.bmp" For Binary As #1
Put #1, , newPic.Data
Close
'Load into a PictureBox
Picture1.Picture = LoadPicture(App.Path & "\tmpFile.bmp")
Picture1.Refresh
'Delete the temporary file
Kill App.Path & "\tmpFile.bmp"
MsgBox "The Picture in the PictureBox is of Category " _
& newPic.Category & vbCrLf & vbCrLf & newPic.Comments
End Sub
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Oct 7th, 2002, 10:21 AM
#6
Thread Starter
Fanatic Member
THANKS HEAPS!!
That was exactly what I was looking for. Now I just need to set it up for handling MPEG and AVI Files... then it will be complete!
Thanks for your help!
/: Tim :\____________________
\: VB, HTML, ASP, VBScript, QBASIC, JavaScript :/
-
Oct 7th, 2002, 10:24 AM
#7
Frenzied Member
Just be careful of the file sizes. As you will have to write to disk and read them back for proper rendering. 10 MB or more and there will be noticable disk activity
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Oct 7th, 2002, 10:33 AM
#8
Frenzied Member
UR most welcome
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Oct 7th, 2002, 11:18 AM
#9
Thread Starter
Fanatic Member
How can I encrypt just the data??
so that I will still be able to read the comments, but not the data
Thanks in advance,
/: Tim :\____________________
\: VB, HTML, ASP, VBScript, QBASIC, JavaScript :/
-
Oct 7th, 2002, 11:28 AM
#10
Thread Starter
Fanatic Member
ok, i found this:
Code:
Sub EncryptFile(ByVal sName As String)
Dim b() As Byte
Dim nb() As Byte
n = FileLen(sName)
ReDim b(n - 1)
ReDim nb(n - 1)
Open sName For Binary Access Read As #1
Get #1, , b()
Close #1
Kill sName
For i = LBound(b) To UBound(b)
nb(i) = b(i) Xor 5
Next i
Open sName For Binary Access Write As #1
Put #1, , nb()
Close #1
End Sub
how can I make it encrypt the binary data??
Thanks in advance,
/: Tim :\____________________
\: VB, HTML, ASP, VBScript, QBASIC, JavaScript :/
-
Oct 7th, 2002, 11:28 AM
#11
Frenzied Member
Since the data is in a Byte Array, you can encrypt it as you please. For Example, reverse the bytes.
VB Code:
.........
Open App.Path & "\Clouds.bmp" For Binary As #1
ReDim newPic.Data(LOF(1))
Get #1, , newPic.Data
Close #1
'Here we encrypt the Bitmap, by reversing the bytes
Dim encData() As Byte, j As Long
'Create a new Byte Array to hold it
ReDim encData(UBound(newPic.Data))
For i = UBound(newPic.Data) To LBound(newPic.Data) Step -1
encData(j) = newPic.Data(i)
j = j + 1
Next i
'Over write the file with its reverse
For i = LBound(encData) to UBound(encData)
newPic.Data(i) = encData(i)
Next i
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Oct 7th, 2002, 11:30 AM
#12
Thread Starter
Fanatic Member
I would like to use a password, not just reversing it..
I changed the 'comments' string to a 'strPassword' string. is there any way I could use that in there somewhere???
Thanks in advance,
/: Tim :\____________________
\: VB, HTML, ASP, VBScript, QBASIC, JavaScript :/
-
Oct 7th, 2002, 11:30 AM
#13
Frenzied Member
Originally posted by tim_l_012
how can I make it encrypt the binary data??
Thanks in advance,  [/B]
The above code is for Binary data. b and nb are Byte Arrays
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Oct 7th, 2002, 11:33 AM
#14
Frenzied Member
Am I right in understanding that you want to encrypt the data using whatever password that is stored for that file.
But in that case the password itself would be exposed, would it not?
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Oct 7th, 2002, 11:36 AM
#15
So Unbanned
A good way to do encryption is random seeds using xor, a look-up-table, and interpolating characters.
That way, if the smallest change occurs, the entire file is corrupt.
-
Oct 7th, 2002, 11:37 AM
#16
Thread Starter
Fanatic Member
ok I'll go through this properly 
In my program, I want to be able to add passwords to certain files. Then, I give them my own file type, so they open with my program.
The password is passed by from the user, then encrypted using my encryption routine, and then placed in the file, along with the data.
the password is only encrypted using XOR, and I didn't know how to encrypt the binary stuff, so..
here you guys are to help me!
hope that helped, reply ASAP
Thanks in advance,
/: Tim :\____________________
\: VB, HTML, ASP, VBScript, QBASIC, JavaScript :/
-
Oct 7th, 2002, 11:38 AM
#17
Thread Starter
Fanatic Member
hey digital,
thats a sweet idea!
how would I incorporate that?
Thanks in advance,
/: Tim :\____________________
\: VB, HTML, ASP, VBScript, QBASIC, JavaScript :/
-
Oct 7th, 2002, 11:38 AM
#18
Frenzied Member
get it.......some time please..........
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Oct 7th, 2002, 11:39 AM
#19
So Unbanned
If you're not going to encrypt the data you should encrypt the password heavily, then distribute the bytes of it throughout the file. rendering the file corrupt, without password.
-
Oct 7th, 2002, 11:40 AM
#20
Thread Starter
Fanatic Member
ok, thanks for all your ideas, I have devised my solution, and have started on the new routines!
Thanks all who participated!
/: Tim :\____________________
\: VB, HTML, ASP, VBScript, QBASIC, JavaScript :/
-
Oct 7th, 2002, 11:42 AM
#21
Frenzied Member
UR Welcome
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Oct 7th, 2002, 11:44 AM
#22
So Unbanned
Well.
You define the seed to create psudeo random numbers using randomize -1
randomize seed
then rnd will generate the same seed of random numbers
then you do
chr$(rnd*256 xor asc(chr))
you have to store the seed as well, there are 64k seeds. I would suggest using base 256, and storing seeds in a 2 byte format.
-32k to 32k
where asc(chr1)*256+asc(chr2) = seed - 32k
-
Oct 7th, 2002, 09:52 PM
#23
Thread Starter
Fanatic Member
ok, for all who dont understand, I want to store an encrypted password in the header. When WMP or similar tries to open it, they wont understand it because the bytes will be reversed.
to un-reverse them, my program opens the file, encrypts the users password, and checks it against the encrypted password stored in the file. If it is the same, the bytes are un-reversed..
can anybody tell me why this wont work??
(btw, you will need a form with 5 command buttons, and a Windows Media Player control, called 'MP'
Thanks in advance, 
Code:
Option Explicit
Private Type myFILE
Data() As Byte
Category As String * 4
Word As String * 50
End Type
Dim strExtension As String
Dim strNewFilename As String
Private Function OnlyExtension(FileName As String) As String
Dim lngPos As Long
FileName = StrReverse(FileName)
lngPos = InStr(FileName, ".")
FileName = StrReverse(FileName)
OnlyExtension = Right(FileName, lngPos - 1)
End Function
Private Function NoExtension(FileName As String) As String
Dim lngPos As Long
lngPos = InStrRev(FileName, ".")
NoExtension = Left(FileName, lngPos - 1)
End Function
Public Sub PutPassWord(ByVal strFileName As String, ByVal strCategory As String, ByVal strPassword As String)
Dim newpic As myFILE
Dim I As Long
Dim encData() As Byte, j As Long
Debug.Print strFileName
Open strFileName For Binary As #1
ReDim newpic.Data(LOF(1))
Get #1, , newpic.Data
Close #1
newpic.Category = strCategory
newpic.Word = strPassword
'====================
'ENCRYPT THA DATA!!
'Create a new Byte Array to hold it
ReDim encData(UBound(newpic.Data))
For I = UBound(newpic.Data) To LBound(newpic.Data) Step -1
encData(j) = newpic.Data(I)
j = j + 1
Next I
'Over write the file with its reverse
For I = LBound(encData) To UBound(encData)
newpic.Data(I) = encData(I)
Next I
'====================
strExtension = OnlyExtension(strFileName)
strNewFilename = NoExtension(strFileName)
strNewFilename = strNewFilename & ".p" & strExtension
If Dir(strNewFilename, vbNormal) <> "" Then Kill strNewFilename
Debug.Print "Final: " & strNewFilename
Open strNewFilename For Binary As #1
Put #1, , newpic
Close #1
End Sub
Public Sub GetMovie(ByVal strFileName As String, ByVal strPassword As String)
Dim I As Long
Dim encData() As Byte, j As Long
Dim newpic As myFILE
Open strFileName For Binary As #1
ReDim newpic.Data(LOF(1) - 108)
Get #1, , newpic
Close #1
If RTrim(newpic.Word) = strPassword Then
'====== DECRYPT IT
'Create a new Byte Array to hold it
ReDim encData(UBound(newpic.Data))
For I = UBound(newpic.Data) To LBound(newpic.Data) Step -1
encData(j) = newpic.Data(I)
j = j + 1
Next I
'Over write the file with its reverse
For I = LBound(encData) To UBound(encData)
newpic.Data(I) = encData(I)
Next I
'==================
Open strFileName For Binary As #1
Put #1, , newpic.Data
Close #1
MP.FileName = strFileName
Me.Visible = True
MP.Play
End If
End Sub
Public Sub RemovePass(ByVal strFileName As String, ByVal strPassword As String)
Dim tmpString As String
Dim newpic As myFILE
Open strFileName For Binary As #1
ReDim newpic.Data(LOF(1) - 108)
Get #1, , newpic
Close #1
tmpString = NoExtension(strFileName) & "." & Right(OnlyExtension(strFileName), Len(OnlyExtension(strFileName)) - 1)
If newpic.Word = strPassword Then
Open tmpString For Binary As #1
Put #1, , newpic.Data
Close
Else
MsgBox "Password Incorrect. Password cannot be removed without Authorization.", vbOKOnly + vbCritical, "Remove Failed:"
End If
End Sub
Private Sub cmdtest_Click()
'Me.Show
If MP.FileName = "" Then
MP.FileName = App.Path & "\clock.avi"
Else
MP.FileName = ""
End If
End Sub
Private Sub Command1_Click()
PutPassWord App.Path & "\clock.avi", "PAVI", "testing"
End Sub
Private Sub Command2_Click()
RemovePass App.Path & "\clock.avi", "testing"
End Sub
Private Sub Command3_Click()
GetMovie App.Path & "\clock.avi", "testing"
End Sub
Private Sub Command4_Click()
If MP.FileName = "" Then
MP.FileName = App.Path & "\clock.avi"
Else
MP.FileName = ""
End If
End Sub
/: Tim :\____________________
\: VB, HTML, ASP, VBScript, QBASIC, JavaScript :/
-
Oct 7th, 2002, 10:45 PM
#24
Thread Starter
Fanatic Member
*BUMP*
/: Tim :\____________________
\: VB, HTML, ASP, VBScript, QBASIC, JavaScript :/
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
|
Click Here to Expand Forum to Full Width
|