Option Explicit
'Option Strict

'Imports System.IO


Module Module1
	Dim ArrKey(255) As Byte 'Bit array
	Dim ArrHeader(67) As Byte
	Dim ArrImageByte() As Byte
	Dim ArrSecretByte() As Byte
	Dim DecryptedBit As Byte 'Bit
	Dim EncryptedBit As Byte 'Bit
	Dim Key1 As Byte 'Bit
	Dim Key2 As Byte 'Bit
	Dim OneTimePad As Byte 'Bit
	Dim SecretBit As Byte 'Bit
	Dim ImageHeight As Integer
	Dim ImageWidth As Integer
	Dim NumSecretBits As Integer
	Dim NumSecretBytes As Integer
	Dim NumPixelBytes As Integer
	Dim NumLSBs As Integer
	Dim PixelAddress As Integer
	Dim SecretNameLength As Integer
	Dim InputImage As String
	Dim OutputImage As String
	Dim SecretFile As String
	Dim SecretName As String
	Dim PowerOf2(7) As Byte
	
	
	Sub Main()
		Dim Args() As String = Environment.GetCommandLineArgs
		Select Case Args.GetUpperBound(0)
		Case 0
			Console.WriteLine("Show some helppp")
		Case 1
			Call UnhideFile(Args(1))
		Case 2
			Call HideFile(Args(1),Args(2))
		Case > 2
			Console.WriteLine("Too many arguments")
			MsgBox("Boo Msg")
		End Select
	End Sub
	
	
	Sub HideFile(InputImage As String, SecretFile As String)
		Dim t as Double
		Call LoadFile(SecretFile, ArrSecretByte)
		Call LoadFile(InputImage, ArrImageByte)
		t = DateAndTime.Timer
		Call GetImageData
		Call CheckImageSuitable
		Call MakeKeyArray
		Call WriteHeaderArray
		Call MakePowerOf2Array
		Call EncryptArray(ArrHeader, 256)
		Call EncryptArray(ArrSecretByte, 800)
		Call SaveFile(OutputImage, ArrImageByte)
		Console.WriteLine(DateAndTime.Timer - t)
	End Sub
	
	
	Sub UnhideFile(InputImage As String)
		Call LoadFile(InputImage, ArrImageByte)
		Call GetImageData
		Call MakePowerOf2Array
		Call GetKeyArray
		Call DecryptArray(ArrHeader, 256)
		Call InitialiseSecretFile
		Call DecryptArray(ArrSecretByte, 800)
		Call SaveFile(SecretFile, ArrSecretByte)
	End Sub
	
	
	Sub LoadFile(FilePath As String, ByRef ArrByte() As Byte)
		If IO.File.Exists(FilePath) Then
			Console.WriteLine("yes")
		Else
			Console.WriteLine("no")
			End
		End If
		ArrByte = IO.File.ReadAllBytes(FilePath)
	End Sub
	
	
	Sub GetImageData()
		'Check header begins with "BM"
		If Not (ArrImageByte(0) = 66 And ArrImageByte(1) = 77) Then
			Console.WriteLine(InputImage & " is not a BMP file.")
			End
		End If
		PixelAddress = GetDWord(ArrImageByte, 10)
		ImageWidth = GetDWord(ArrImageByte, 18)
		ImageHeight = GetDWord(ArrImageByte, 22)
		NumPixelBytes = 3 * ImageWidth * ImageHeight
	End Sub
	
	
	Function GetDWord(ArrByte() As Byte, StartAddress As Integer) As Integer
		'Convert a little-endian DWord from a byte array into a Integer integer
		Dim j As Integer
		Dim x As Integer
		For i As Integer = 0 To 3
			j = StartAddress + i
			x = x + ArrByte(j) * 256 ^ i
		Next i
		GetDWord = x
	End Function
	
	
	Sub CheckImageSuitable()
		'Check number of columns is divisible by 4 (avoids bitmap row padding)
		If ImageWidth Mod 4 > 0 Then
			Console.WriteLine(InputImage & " must be a multiple of 4 pixels.")
			End
		End If
		'Check image is large enough to store secret file
		NumSecretBytes = ArrSecretByte.GetUpperBound(0) + 1
		NumSecretBits = 8 * NumSecretBytes
		NumLSBs = -Int(-(800 + NumSecretBits) / NumPixelBytes)
		If NumLSBs > 4 Then
			Console.WriteLine(InputImage & "is too small to contain the message.")
			End
		End If
		OutputImage = Replace(InputImage, ".bmp", " v2.bmp")
	End Sub
	
	
	Sub MakeKeyArray()
		Dim j As Integer
		For i As Integer = 0 To ArrKey.GetUpperBound(0)
			j = PixelAddress + i
			ArrKey(i) = Int(2 * Rnd)
			ArrImageByte(j) = ArrImageByte(j) And 254 Or ArrKey(i)
		Next i
	End Sub
	
	
	Sub WriteHeaderArray()
		Dim x As Integer = NumSecretBytes
		'Cap filename at 64 characters
		SecretName = Left(Dir(SecretFile), 64)
		SecretNameLength = Len(SecretName)
		ArrHeader(0) = SecretNameLength
		For i As Integer = 1 To SecretNameLength
			ArrHeader(i) = Asc(Mid(SecretName, i, 1))
		Next i
		For i As Integer = 65 To 67
			ArrHeader(i) = x Mod 256
			x = x \ 256
		Next i
	End Sub
	
	
	Sub MakePowerOf2Array()
		PowerOf2(0) = 1
		For i As Integer = 1 To 7
			PowerOf2(i) = 2 * PowerOf2(i - 1)
		Next i
	End Sub
	
	
	Sub EncryptArray(ArrToEncrypt() As Byte, StartBit As Integer)
		Dim m As Integer 'Position in image byte array
		Dim n As Integer = StartBit 'Bit counter
		Dim q As Integer 'Quotient (LSB number from 0 to 3)
		Dim r As Integer 'Remainder (pixel byte number from 0 to NumPixelBytes - 1)
		For i As Integer = 0 To ArrToEncrypt.GetUpperBound(0)
			For j As Integer = 0 To 7
				q = n \ NumPixelBytes
				r = n Mod NumPixelBytes
				m = PixelAddress + r
				SecretBit = -CBool(ArrToEncrypt(i) And PowerOf2(j))
				Key1 = ArrKey(n Mod 256) 'ADJUST
				Key2 = -CBool(ArrImageByte(m) And PowerOf2(4 + (q + j) Mod 4))
				OneTimePad = Key1 Xor Key2
				EncryptedBit = SecretBit Xor OneTimePad
				ArrImageByte(m) = ArrImageByte(m) And Not PowerOf2(q) Or EncryptedBit * PowerOf2(q)
				n += 1
			Next j
		Next i
	End Sub
	
	
	Sub SaveFile(FilePath As String, ArrByte() As Byte)
		IO.File.WriteAllBytes(FilePath, ArrByte)
	End Sub
	
	
	Sub GetKeyArray()
		Dim j As Integer
		For i As Integer = 0 To ArrKey.GetUpperBound(0)
			j = PixelAddress + i
			ArrKey(i) = ArrImageByte(j) And 1
		Next i
	End Sub
	
	
	Sub DecryptArray(ArrToDecrypt() As Byte, StartBit As Integer)
		Dim m As Integer 'Position in image byte array
		Dim n As Integer = StartBit 'Bit counter
		Dim q As Integer 'Quotient (LSB number from 0 to 3)
		Dim r As Integer 'Remainder (pixel byte number from 0 to NumPixelBytes - 1)
		For i As Integer = 0 To ArrToDecrypt.GetUpperBound(0)
			For j As Integer = 0 To 7
				q = n \ NumPixelBytes
				r = n Mod NumPixelBytes
				m = PixelAddress + r
				EncryptedBit = -CBool(ArrImageByte(m) And PowerOf2(q))
				Key1 = ArrKey(n Mod 256) 'ADJUST
				Key2 = -CBool(ArrImageByte(m) And PowerOf2(4 + (q + j) Mod 4))
				OneTimePad = Key1 Xor Key2
				DecryptedBit = EncryptedBit Xor OneTimePad
				ArrToDecrypt(i) = ArrToDecrypt(i) Or DecryptedBit * PowerOf2(j)
				n += 1
			Next j
		Next i
	End Sub
	
	
	Sub InitialiseSecretFile()
		Dim x As Integer
		Dim s As String = ""
		SecretNameLength = ArrHeader(0)
		For i As Integer = 0 To 2
			x = x + ArrHeader(65 + i) * 256 ^ i
		Next i
		NumSecretBytes = x
		NumSecretBits = 8 * NumSecretBytes
		NumLSBs = -Int(-(800 + NumSecretBits) / NumPixelBytes)
		If SecretNameLength > 64 Or NumLSBs > 4 Then
			Console.WriteLine(InputImage & "has an invalid header.")
			End
		End If
		For i As Integer = 1 To SecretNameLength
			s &= Chr(ArrHeader(i))
		Next i
		SecretName = s
		SecretFile = Left(InputImage, InStrRev(InputImage, "\")) & "Decrypted - " & SecretName
		ReDim ArrSecretByte(NumSecretBytes - 1)
	End Sub


End Module 

Visual basic (VB.net) Online Compiler

Write, Run & Share VB.net code online using OneCompiler's VB.net online compiler for free. It's one of the robust, feature-rich online compilers for VB.net language, running on the latest version 16. Getting started with the OneCompiler's VB.net compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as VB.net. OneCompiler also has reference programs, where you can look for the sample code to get started with.

Read input from STDIN in VB.net

OneCompiler's VB.net online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample VB.net program which takes name as input and prints hello message with your name.

Public Module Program
	Public Sub Main(args() As string)
	 Dim name as String = Console.ReadLine()    ' Reading input from STDIN
   Console.WriteLine("Hello " & name)           ' Writing output to STDOUT
	End Sub
End Module

About VB.net

Visual Basic is a event driven programming language by Microsoft, first released in the year 1991.

Key Features

  • Beginner's friendly language.
  • Simple and object oriented programming language.
  • User friendly language and easy to develop GUI based applications.

Syntax help

Variables

Variable is a name given to the storage area in order to identify them in our programs.

Simple syntax of Variable declaration is as follows

Dim variableName [ As [ New ] dataType ] [ = initializer ]

Variable initialization

variableName = value

Conditional Statements

1. If

If condition-expression Then 
    'code
End If

2. If-else

If(conditional-expression)Then
   'code if the conditional-expression is true 
Else
  'code if the conditional-expression is false 
End If

3. If-else-if ladder

If(conditional-expression)Then
   'code if the above conditional-expression is true 
Else If(conditional-expression) Then
        'code if the above conditional-expression is true 
    Else
        'code if the above conditional-expression is false 
End If

4. Nested-If

If(conditional-expression)Then
   'code if the above conditional-expression is true
   If(conditional-expression)Then
         'code if the above conditional-expression is true 
   End If
End If

5. Select Case

Select [ Case ] expression
   [ Case expressionlist
      'code ]
   [ Case Else
      'code ]
End Select

Loops

1. For..Next

For counter [ As datatype ] = begin To end [ Step step ]
   'code
   [ Continue For ]
   'code
   [ Exit For ]
   'code
Next [ counter ]

2. For..Each

For Each element [ As datatype ] In group
   'code
   [ Continue For ]
   'code
   [ Exit For ]
   'code
Next [ element ]

3. While

While conditional-expression
   'Code 
   [ Continue While ]
   'Code
   [ Exit While ]
   'Code
End While

4. Do-while

Do { While | Until } conditional-expression
   'Code
   [ Continue Do ]
   'Code
   [ Exit Do ]
   'Code
Loop
Do
   'Code
   [ Continue Do ]
   'Code
   [ Exit Do ]
   'Code
Loop { While | Until } conditional-expression

Procedures

Procedure is a sub-routine which contains set of statements. Usually Procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.

Procedures are of two types.

1. Functions

Functions return a value when they are called.

[accessModifiers] Function functionName [(parameterList)] As returnType
   'code
End Function

2. Sub-Procedures

Sub-procedures are similar to functions but they don't return any value.

Sub ProcedureName (parameterList)
'Code
End Sub