2 Replies - 7395 Views - Last Post: 29 December 2009 - 03:08 AM Rate Topic: -----

#1 jhouns  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 25
  • View blog
  • Posts: 100
  • Joined: 21-December 09

Writing/Reading .dat files

Posted 28 December 2009 - 11:03 PM

Hey there I was wondering, seeing as '.dat' files contain only what you want them to and there is no preset encryption for them etc could I write data to one by using this simple process:

1) Change file extension to '.txt'
2) Decrypt
3) Write
4) Encrypt
5) Change file extension to '.dat'

and pretty much the same for reading it. or am I thinking to simply?

I thought of the above way as i know how to write to text files already, but is this the best way to do it? or is there a better way?

EDIT: Nevermind you just write to it like a text file and encrypt/decrypt it. request lock/delete from mod.

This post has been edited by jhouns: 29 December 2009 - 01:01 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Writing/Reading .dat files

#2 Guest_NIXZ*


Reputation:

Re: Writing/Reading .dat files

Posted 29 December 2009 - 02:24 AM

If you are trying to save your settings in that .dat file. Why not to use My.Settings ?
It's much easier. Goto Project --> Properties... --> There's a tab "Settings" you ll figure out the rest.
To use it just call it. Example: (you want to save the size of the form when closed)
My.Settings.LastFormSize = New Size(1280,720)

You can even use this simple encryption/decryption function:
Public Function Crypt(ByVal Text As String) As String
		Dim TempChar As String, i As Integer
		For i = 1 To Len(Text)
			If Asc(Mid$(Text, i, 1)) < 128 Then
				TempChar = _
		  CType(Asc(Mid$(Text, i, 1)) + 128, String)
			ElseIf Asc(Mid$(Text, i, 1)) > 128 Then
				TempChar = _
		  CType(Asc(Mid$(Text, i, 1)) - 128, String)
			End If
			Mid$(Text, i, 1) = _
				Chr(CType(TempChar, Integer))
		Next i
		Return Text
	End Function

Just to be sure ;)
Was This Post Helpful? 0

#3 jhouns  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 25
  • View blog
  • Posts: 100
  • Joined: 21-December 09

Re: Writing/Reading .dat files

Posted 29 December 2009 - 03:08 AM

it's a nice thought but in fact i'm using it more peculiarly than that, i mean who checks their dat files anyway :P.

If you are interested it is actually a lan chat program because our college doesn't like us using emails for discussing work and other things accross the room or college. It required you to know the port (we just use 6570 until it gets blocked ;)) and the ip address. The '.dat' file contained all the contacts and what their ip address is in certain lessons as they always use the same computer. Simple stuff really xD.

As for encryption i am only encrypting the messages sent over the network and only very badly as i don't have time to do it properly yet and our it technicians are weak so it uses simple maths to change it heres the code:
	Private Function Encrypt(ByRef Message As String)
		'Encrypts the message
		Dim Encrypted As String
		'Clear any Encryption to prevent a null reference exception
		Encrypted = ""
		'loop through the messages chars and encrypt each
		For i As Integer = 0 To Message.Length - 1
			'Encrypted = Encrypted + Character created from ascii code(char in message * 2 + 6)
			Encrypted += Chr((Asc(Message(i)) * 2) + 6)
		Next
		Return Encrypted
	End Function

	Private Function Decrypt(ByRef Message As String)
		Dim Decrypted As String
		'Clear any Decryption to prevent a null reference exception
		Decrypted = ""
		'loop through the messages chars and decrypts each
		For i As Integer = 0 To Message.Length - 1
			'reverses encryption)
			Decrypted += Chr((Asc(Message(i)) - 6) / 2)
		Next
		Return Decrypted
	End Function



if they ever crack the encryption (or care enough to try to as we use less resources than ever) then i will just change the formula to make it more complex as this is only v3 (first with encryption) :P
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1