Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
88 views6 pages

Assignment No3 OF Modern Programming Tools & Techniques Iii

The document discusses programming tools and techniques for file input/output, text editing, and encryption/decryption. It includes code snippets for: 1. Reading and writing file contents to/from a file. 2. Setting font and color for text in a rich text box using dialog boxes. 3. Opening an existing file using an OpenFileDialog. 4. Saving a file using a SaveFileDialog. 5. Encrypting and decrypting data in a file using DES encryption with a password, key, and initialization vector.

Uploaded by

Ankur Singh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views6 pages

Assignment No3 OF Modern Programming Tools & Techniques Iii

The document discusses programming tools and techniques for file input/output, text editing, and encryption/decryption. It includes code snippets for: 1. Reading and writing file contents to/from a file. 2. Setting font and color for text in a rich text box using dialog boxes. 3. Opening an existing file using an OpenFileDialog. 4. Saving a file using a SaveFileDialog. 5. Encrypting and decrypting data in a file using DES encryption with a password, key, and initialization vector.

Uploaded by

Ankur Singh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

LPU

ASSIGNMENT NO3
OF
MODERN
PROGRAMMING
TOOLS &
TECHNIQUES III
SUBMITTED TO SUBMITTED BY

DEEPAK MEHTA VARUN KATOCH

E3801B53
BCA-MCA

Q 1. Taking into consideration the details about a student write a program to read
& write data of a file.

Public Function GetFileContents(ByVal FullPath As String, Optional ByRef ErrInfo As String =


"") As String

Dim strContents As String


Dim objReader As StreamReader
Try

objReader = New StreamReader(FullPath)


strContents = objReader.ReadToEnd()
objReader.Close()
Return strContents
Catch Ex As Exception
ErrInfo = Ex.Message
End Try
End Function

Public Function SaveTextToFile(ByVal strData As String, _


ByVal FullPath As String, _
Optional ByVal ErrInfo As String = "") As Boolean

Dim Contents As String


Dim bAns As Boolean = False
Dim objReader As StreamWriter
Try

objReader = New StreamWriter(FullPath)


objReader.Write(strData)
objReader.Close()
bAns = True
Catch Ex As Exception
ErrInfo = Ex.Message

End Try
Return bAns
End Function
Qus 2 Using rich Text box, create an editor and perform font and color setting of
text using font and colour dialog boxes.

Button 1 :-

Openfiledialog1.show dialog()

Button 2 :-

Colordialog1.coloe=color.blue
Colordialog1.showdialog()
Me.backcolor=colordialog1.color

Qus 3 Using rich Text box, create an editor and Open an existing file using
OpenFileDialog box.

Button1:-
Opendialog1.showdialog()

Button2:-

Openfiledialog1.initialdirectory=”c:/”
Openfiledialog1.filter=”(”.html)/*.html*
Openfiledialog1.showdialog()
Name=openfiledialog1.filename
Messagebox.show(name)
Qus 4 Using Rich Text Box, Create an Editor and save a file using Save File
Dialog:-

Button1:-
Opendialog1.showdialog()

Button2:-

Openfiledialog1.initialdirectory=”c:/”
Openfiledialog1.filter=”(”.html)/*.html*
Openfiledialog1.showdialog()
Name=openfiledialog1.filename
Messagebox.show(name)

Button 3 :-

Savefiledialog.filter=”(“.html)/*.html”
Openfiledialog1.show dialog()
Name=openfiledialog1.file name
Savefiledialog1.file name=openfiledialog1.file name
Savefiledialog1.showdialog()

Qus 5 We may need to encrypt our sensitive data Write a program for encryption
& Decryption of data in a file.

Private Sub CryptFile(ByVal password As String, ByVal _ in_file As String, ByVal out_file As
String, ByVal _ encrypt As Boolean)
' Create input and output file streams.
Dim in_stream As New FileStream(in_file, FileMode.Open, _ FileAccess.Read)
Dim out_stream As New FileStream(out_file, _ FileMode.Create, FileAccess.Write)
' Find a valid key size for this provider.
Dim key_size_bits As Integer = 0
For i As Integer = 1024 To 1 Step -1
If des_provider.ValidKeySize(i) Then
key_size_bits = i
Exit For
End If
Next i
Debug.Assert(key_size_bits > 0)

' Get the block size for this provider.


Dim block_size_bits As Integer = des_provider.BlockSize

' Generate the key and initialization vector.


Dim key As Byte() = Nothing
Dim iv As Byte() = Nothing
MakeKeyAndIV(password, key_size_bits, block_size_bits, _
key, iv)

' Make the encryptor or decryptor.


Dim crypto_transform As ICryptoTransform
If encrypt Then
crypto_transform = _
des_provider.CreateEncryptor(key, iv)
Else
crypto_transform = _
des_provider.CreateDecryptor(key, iv)
End If

' Attach a crypto stream to the output stream.


Dim crypto_stream As New CryptoStream(out_stream, _
crypto_transform, CryptoStreamMode.Write)

' Encrypt or decrypt the file.


Const BLOCK_SIZE As Integer = 1024
Dim buffer(BLOCK_SIZE) As Byte
Dim bytes_read As Integer
Do
' Read some bytes.
bytes_read = in_stream.Read(buffer, 0, BLOCK_SIZE)
If bytes_read = 0 Then Exit Do

' Write the bytes into the CryptoStream.


crypto_stream.Write(buffer, 0, bytes_read)
Loop

' Close the streams.


crypto_stream.Close()
in_stream.Close()
out_stream.Close()
End Sub

You might also like