I am writing a small file encryption app that will encrypt abd decrypt files in TDES. These files will be read from and sent to an existing server with it's own encrytion/decryption app to handle it's side of the file processing. The developer of that system has given me the key and IV values as raw byte values. All the examples that I can find convert strings to the byte arrays for the key and the IV. How do I use the supplied raw byte values instead?
I have a DEM file(Digital Elevattion Model File) and I am trying to open the file,where we have Latitude and Longitude values inside the DEM file.And, Now I have opened the file using Filestream and Read the file using BinaryReader.But, I am having a trobule in getting the values of Latitude and Longitude.I am getting Byte values randomly as 1,202,31,271 etc.But, we dont have latitude and longitude values more than 180,and also I am not getting 16 bit UInt values.For example, the values should be like Latitude 20.00416666666667 and Longitude 39.99583333333333.So,read the correct Byte values of the DEM file.The code I have used till now is:
Dim fs As FileStream = New FileStream("C:UsersadminDesktopHeader and DEM fileE020N40.DEM", FileMode.Open, FileAccess.Read) Dim rd As New BinaryReader(fs) Dim convertDB As UInt16 For i = 0 To rd.BaseStream.Length
I'm trying to convert old code to VB in VS2005. The code I'm working on is used to store values in a string, which will then be handed to a proprietary scramble function. This function is a given in this case. I've already switched from a string to an array of bytes in my .NET code.
The old code (VBA) was using a string value to store the data, example function for Double value: Private Function DoubleToStr(ByVal value As Double) As String Dim Bytes(7) As Byte ' 0-7 Double is 8 bytes Dim n As Long CopyMemory(Bytes(0), value, 8) DoubleToStr = "" For n = 0 To UBound(Bytes) DoubleToStr = DoubleToStr & Chr(Bytes(n)) Next n End Function
The code basically copies the memory contents (using API call CopyMemory) of the memory (held by the double variable) to the memory held by a byte array. It then reads the byte array and converts it into a string. Workarounds could be to convert a bool or long to a string, though that would be expensive in terms of memory/storage eg. 1234564787 would be 10 bytes in a string where as a long is only 4 bytes (factor 2.5 increase).
How to retain the original precision? Converting it to a string would result in endless numbers. Another problem (at least I think it could be) is that in VBA the variables are rather simple, but in .NET they are all objects, so how to retrieve the actual memory location of the value? let alone garbage collection moving stuff around. How to get those variables stored in my byte array?
I am having some major problems with byte arrays. First off the bigger array I have the more values go missing, I originally wanted to make a huge array and just dump like a 100mb chunk of memory in it but when I did that every byte in the array returned 0. So I experimented a bit and found 4kb to be the biggest chunk size to reliably not return 0.. ok I figured I'll just loop the 4kb and glue them back together later but no such luck, after being combined into the main array the bigger the number gets the more values that should be there just aren't.
Here's a code sample: Dim retval(4095) As Byte Dim combval(RLen) As Byte For i = 0 To RLen - 4095 Step 4096 ReadProcessMemory(ProcAccess, i, retval, 4096, 0) retval.CopyTo(combval, i) Next i WriteLine(combval(321603964)) WriteLine(ReadMemory(321603964, 1)(0))
So with the last 2 lines if I pull up some smaller number like 8 digits or so it reports back no problem but anything slightly bigger like the number i have written in there right now is just 0. After some additional research I discovered that the reason why 4kb is the max size I can reliably get is coz that's the size memory chunks are made of, "page" as they call it. Why the memory reading drops off at higher addresses alltho I suspect it has something to do with the way memory is structured and I am just not hitting the startpoint of a page anymore due to an offset or something somewhere.
How would I convert the two individual byte values (in hex) to a decimal value representing the concatenated hex values? For example, if I have the
Dim byte1 As Byte = &H99 Dim byte2 As Byte = &H99
' I want the decimal representation of the hex value "9999" ' (byte1.ToString + byte2.ToString) which should be "39321" Currently I use the following code:
Dim decVal as integer decVal = Val("&H" + Hex$(byte1).ToString + Hex$(byte2).ToString)
However, when I use this, the value (decVal) comes out to "-26215"
I need to convert hex values aa 01 00 17 f4 2f (as contained in byte array FrameData) to display in a label control as AA:01:00:17:F4:2F
HexDump(FrameData(2)) converts the aa (which has been converted to Decimal 170) into 31 37 30 !
similarly I need to convert hex data ('02 00' contained in byte array FrameData) as 0x0200."0x" & FrameData(1) + FrameData(2) displays the data as 0x20. How would I convert the '02 00' hex data to display as 0x0200?
I've got a problem saving asci Values to File as Byte. I must save hex values to file, for this case i used the following line: fs.WriteByte(&H2D) This works fine, but i need to do this autmaticly. My Sourcestring is 2995030. Tried to do something like &H(Hex(str)), but this failed.
How would I copy/convert a string containing an ascii representation of hex values in to a byte array containing the actual hex values? For example, I have a variable containing the hex values delimited by spaces (I can change the delimiter):
I have a device with upon serial communication , it send the data as HEX values , (eg, C020042ABD0F91A103E400F929EBC) . I use the following code to get data from the serial port.
Dim fStream As New FileStream(sFileName, FileMode.CreateNew) ' creates new file Dim bw As New BinaryWriter(fStream) System.Threading.Thread.Sleep(1500) ComTd.Read(data, 1, bCount)
I have a device with upon serial communication, it send the data as HEX values, (e.g., C020042ABD0F91A103E400F929EBC). I use the following code to get data from the serial port.
Dim fStream As New FileStream(sFileName, FileMode.CreateNew) ' creates new file Dim bw As New BinaryWriter(fStream) System.Threading.Thread.Sleep(1500) ComTd.Read(data, 1, bCount) Dim bCount As Integer = 4119 ' it is the size of the chunk not block size Dim data(bCount) As Byte [Code] .....
I need to read signed and unsigned 8 bit, 16 bit and 32 bit values from a file stream which may be little-endian or big-endian (it happens to be a tiff file which carries the byte order indicator at the start).I initially started by writing my own functions to read the values and was able to do so for unsigned values. e.g.
Public Function ReadUInt32() As UInt32 Dim b(4) As Byte input.Read(b, 0, 4)
[code]....
But then I started looking at signed values and my brain broke.As an alternative, I found the IO.BinaryReader which will let me read signed values directly but doesn't seem to have any way to indicate that the data is big-endian or little-endian.Is there a nice way of handling this? Failing that, can someone tell me how to convert multiple bytes into signed values (in both byte orders)?
I'm creating an emulator for a device to simulate wave forms. My challenge is that when I try to convert the output of the following code, I can't convert the Math.Sin's double output into byte values that lend themselves to the byte array format required by an existing graphing control as listed at bottom below. I''m not sure how to handle this when the sin function creates negative values but the byte values will need to be positive and basically 'shifted up' so that anything over 127 is negative. (0 - 255) unsigned. BitConverter.GetBytes has been suggested but THIS is the result of that attempt.
I create my algorthm and its finished but there is a problem, it encrypte all text and all text in a file but after decryption when i open my file (a video file)the player show all information about file(duration,size and ect) currectly but it dont play that my program encrypt and decrypt byte by byte and place a asci code in bytes(0 to 255)
I just converted the following code from c# to vb.net. It is functional and works correctly with my company's firmware/devices. My next challenge. Previous serialport code used much more readable structs which where then converted (after building a packet) into byte() automatically as part of the serialport encoding. (this is my understanding)How could I
1. morph byte arrays 'ToSocket' and 'ToMTP' below into structs and
2. convert into byte array for Socket.BeginSend(byte(),.....) to stream out to remote devices?
Is it possible in VB to truncate a larger data type ( an int with a value greater than 255) to a smaller one, say a Byte (which only goes up to 255) in a way such that the 8LSBs of the integer are copied to the newly created byte. I have tried this using CType with the following code, however it does not work.
Dim TestByte As Byte = CType(Test, Byte) Where the variable "Test" is an integer with a value of 419. This code always results in the Overflow exception.
I have 2 byte arrays. I want to merge these two byte array into 1 byte array.Usually, I just create a new byte array with length = byte array #1 + byte array #2. Then copy byte array #1 and #2 to the new byte array.do I have more efficient way to merge 2 byte array using VB.NET and .Net 4?
I would like to create a function so that I can pass a string and it will return me the binary value, I will use this later in other parts of the script but I am getting an error that I don't understand.
Private Function ConvertToMD5(ByVal OldPassword As String) As Byte Dim NewPassword As String = "" 'The string we wish to encrypt
[code]....
On the "Return hashedDataBytes I get "Value of type '1-dimensional array of Byte' cannot be converted to 'Byte'"
I have a byte array that I convert into a string like so Dim byt As Byte() = New Byte(255) {} s = New String(Encoding.ASCII.GetChars(byte))My question is when I look at the string in a debuger its clearly a normal string but when I compare it to what I know its supposed to be it doesnt equal. So i did a quick check and for some reason its return a string thats the length of 256 characters. So i did a s.trim and it still is 256 characters long.
I would like to know how to convert a unisgned byte to signed byte
Atm I got this
a Function readSignedByte() As SByte '-128/127 Dim b As SByte
[Code]....
it doesn't work one that well works for numbers positive over 127 if lets say ReadByte() has 128 it would give overflow error which I don't want it to give I would like it to overflow the number to negivate value aka its signed value.
given my code below, I'm trying to figure out how to create an array of 1 byte containing 7 bits. So the byte in the array would contain 0111111 to correspond to mData_Out's boolean values. How would I change the following code? [Code]
I am trying to write some code to get a kinect for windows sample running, which is originally written in C#. I get stuck with translating the following C# code to VB.NET:
byte intensity = (byte)(~(realDepth >> 4));
What is the VB.NET equivalent for the code above? how to translate the "~" code sign.
if a byte value can go up to 255 and two bytes are used to determine the length of packet payload data, how would I convert the two bytes to create one integer value?
State.buffer[13] = 5 and State.buffer[14] = 67 Dim PacketLengthHigh As Integer = state.buffer(13) Dim PacketLengthLow As Integer = state.buffer(14)
I don't understand that error that occurs on the second line of code below. I'm trying to skip over the first 18 bytes of a byte array that I'm accessing from a c# dll into a local vb.net byte array
I am trying to Convert a data field stored as IMAGE ( SQL Server 2000) using Java to a byte array using VB.NET Java uses signed numbers for a Byte array where as VB dosent. Can somone point me to how I can covert java byte array to VB byte array?