Exercise
File encrypter
Objetive
Create a program to encrypt a text file into another text file.
Code
Imports System.IO
Imports System
Class TextFileEncrypter
Private Shared Sub Main(ByVal args As String())
Dim inputFile As StreamReader
Dim outputFile As StreamWriter
Dim line As String
Dim name As String
If args.Length < 1 Then
Console.WriteLine("Not enough parameters!")
Console.WriteLine("Enter file name: ")
name = Console.ReadLine()
Else
name = args(0)
End If
inputFile = File.OpenText(name)
outputFile = File.CreateText(name & ".encrypted")
Do
line = inputFile.ReadLine()
If line IsNot Nothing Then
Dim newText As String = Encrypter.Encrypt(line)
outputFile.WriteLine(newText)
End If
Loop While line IsNot Nothing
inputFile.Close()
outputFile.Close()
End Sub
End Class
Class Encrypter
Public Shared Function Encrypt(ByVal originalString As String) As String
Dim result As String = ""
For Each letter As Char In originalString
Dim newLetter As Char = letter
newLetter += 1
result += newLetter
Next
Return result
End Function
Public Shared Function Decrypt(ByVal originalString As String) As String
Dim result As String = ""
For Each letter As Char In originalString
Dim newLetter As Char = letter
newLetter -= 1
result += newLetter
Next
Return result
End Function
End Class