473,670 Members | 2,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

a problem with copymem API

i am using the following code

private var1 as Long
private var2 as Long
private var3 as Long

ReDim bytearray(0 To 3)
ReDim bytearray2(0 To 3)

For a = 0 To 3
bytearray(a) = Asc(Mid(DataSou rce, b, 1))
bytearray2(a) = Asc(Mid(DataSou rce2, c, 1))
b = b + 1
c = c + 1
Next a

var1 = IVbytearray(0) & IVbytearray(1) & IVbytearray(2) & IVbytearray(3)
var2 = IVbytearray2(0) & IVbytearray2(1) & IVbytearray2(2) & IVbytearray2(3)

CopyMemory var1, var1 Xor var2, 4
CopyMemory var1, var1 Xor var3, 4

an overflow error is sometimes thrown up in the copymemory api, how do i fix
it?
Feb 14 '07 #1
23 4086
On Thu, 15 Feb 2007 10:27:25 +1100, "Antony Clements"
<an************ *@optusnet.com. auwrote:
>i am using the following code

private var1 as Long
private var2 as Long
private var3 as Long

ReDim bytearray(0 To 3)
ReDim bytearray2(0 To 3)

For a = 0 To 3
bytearray(a) = Asc(Mid(DataSou rce, b, 1))
bytearray2(a) = Asc(Mid(DataSou rce2, c, 1))
b = b + 1
c = c + 1
Next a

var1 = IVbytearray(0) & IVbytearray(1) & IVbytearray(2) & IVbytearray(3)
var2 = IVbytearray2(0) & IVbytearray2(1) & IVbytearray2(2) & IVbytearray2(3)

CopyMemory var1, var1 Xor var2, 4
CopyMemory var1, var1 Xor var3, 4

an overflow error is sometimes thrown up in the copymemory api, how do i fix
it?
I can't make any sense of this code
- you don't use & for building a Long out of Bytes

If you described what you are trying to do, then maybe we can come up
with a suggestion.
Feb 15 '07 #2
i modified the code after i posted this, it no longer throws up an error but
it still doesn't work correctly.

dim var1 var2 and var3 as long

ReDim IVbytearray(0 To 7)
ReDim IVbytearray2(0 To 7)

bytearray() = Mid(stream1, b, 8)
bytearray2() = Mid(stream2, c, 8) 'a messagebox here proves that at this
point, the data held in bytearray() is different than the data held in
bytearray2()

var1 = bytearray()
var2 = bytearray2() 'this is where the problem is as var2 returns the same
value as var1 even though the value in bytearray() is different to the value
in bytearray2().

Call CopyMemory(var1 , var1 Xor var2, 8)
Call CopyMemory(var1 , var1 Xor var3, 8)
now here is the problem. even though the data source for bytearray() and
bytearray2() are different, for some reason or other they both have the same
value. var2 needs to be a value from the second data source. i hope this is
a clear indication of what i am trying to do.

"J French" <er*****@nowher e.ukwrote in message
news:45******** ******@news.bto penworld.com...
On Thu, 15 Feb 2007 10:27:25 +1100, "Antony Clements"
<an************ *@optusnet.com. auwrote:
>>i am using the following code

private var1 as Long
private var2 as Long
private var3 as Long

ReDim bytearray(0 To 3)
ReDim bytearray2(0 To 3)

For a = 0 To 3
bytearray(a) = Asc(Mid(DataSou rce, b, 1))
bytearray2(a) = Asc(Mid(DataSou rce2, c, 1))
b = b + 1
c = c + 1
Next a

var1 = IVbytearray(0) & IVbytearray(1) & IVbytearray(2) & IVbytearray(3)
var2 = IVbytearray2(0) & IVbytearray2(1) & IVbytearray2(2) &
IVbytearray2( 3)

CopyMemory var1, var1 Xor var2, 4
CopyMemory var1, var1 Xor var3, 4

an overflow error is sometimes thrown up in the copymemory api, how do i
fix
it?

I can't make any sense of this code
- you don't use & for building a Long out of Bytes

If you described what you are trying to do, then maybe we can come up
with a suggestion.


Feb 15 '07 #3
Antony Clements wrote:
i modified the code after i posted this, it no longer throws up an error but
it still doesn't work correctly.

dim var1 var2 and var3 as long

ReDim IVbytearray(0 To 7)
ReDim IVbytearray2(0 To 7)
These are redundant as they are replaced in the next block.
bytearray() = Mid(stream1, b, 8)
bytearray2() = Mid(stream2, c, 8) 'a messagebox here proves that at this
point, the data held in bytearray() is different than the data held in
bytearray2()
This copies a UNICODE string into the byte array.
This will be 16 bytes, every other one being a null character.

If you want each character as an item in the array, then you want:
bytearray = StrConv(string, vbFromUnicode)
var1 = bytearray()
var2 = bytearray2() 'this is where the problem is as var2 returns the same
value as var1 even though the value in bytearray() is different to the value
in bytearray2().
From the code below, you can't join them up like this.
You will need to do the arithmetic manually (shifting and adding) or
copymemory from the byte array to a long.
Bear in mind that you can only fit 4 bytes in a long...
Call CopyMemory(var1 , var1 Xor var2, 8)
Call CopyMemory(var1 , var1 Xor var3, 8)
Be VERY careful as longs are still only 4 bytes.
you WILL be corrupting memory with this code.
now here is the problem. even though the data source for bytearray() and
bytearray2() are different, for some reason or other they both have the same
value. var2 needs to be a value from the second data source. i hope this is
a clear indication of what i am trying to do.
It still doesn't explain what you have and what results you want at the
end...

--
Dean Earley (de*********@ic ode.co.uk)
i-Catcher Development Team

iCode Systems
Feb 15 '07 #4
Dean Earley wrote:
Antony Clements wrote:
>bytearray() = Mid(stream1, b, 8)
bytearray2() = Mid(stream2, c, 8) 'a messagebox here proves that at
this point, the data held in bytearray() is different than the data
held in bytearray2()

This copies a UNICODE string into the byte array.
This will be 16 bytes, every other one being a null character.

If you want each character as an item in the array, then you want:
bytearray = StrConv(string, vbFromUnicode)
This does assume a normal ANSI string. It will be longer if you have non
ANSI data in your string

--
Dean Earley (de*********@ic ode.co.uk)
i-Catcher Development Team

iCode Systems
Feb 15 '07 #5
if stream1 has a value of 1a2b3c4d i want bytearray() to return the asc
value of the string. the only way i know how to do this is take each
character convert to ascii and then place in a string and then place the
string in bytearray(). i'm looking for a simpler way. var1 and var2 are
always returning the value of 1306840 regardless. bytearray() will return
1a2b3c4d. i am copying the bytearray variables to long variables. the
problem will be solved once var1 and var2 are correct values.

"Dean Earley" <de*********@ic ode.co.ukwrote in message
news:45******** *************** @news.zen.co.uk ...
Antony Clements wrote:
>i modified the code after i posted this, it no longer throws up an error
but it still doesn't work correctly.

dim var1 var2 and var3 as long

ReDim IVbytearray(0 To 7)
ReDim IVbytearray2(0 To 7)

These are redundant as they are replaced in the next block.
>bytearray() = Mid(stream1, b, 8)
bytearray2() = Mid(stream2, c, 8) 'a messagebox here proves that at this
point, the data held in bytearray() is different than the data held in
bytearray2()

This copies a UNICODE string into the byte array.
This will be 16 bytes, every other one being a null character.

If you want each character as an item in the array, then you want:
bytearray = StrConv(string, vbFromUnicode)
>var1 = bytearray()
var2 = bytearray2() 'this is where the problem is as var2 returns the
same value as var1 even though the value in bytearray() is different to
the value in bytearray2().

From the code below, you can't join them up like this.
You will need to do the arithmetic manually (shifting and adding) or
copymemory from the byte array to a long.
Bear in mind that you can only fit 4 bytes in a long...
>Call CopyMemory(var1 , var1 Xor var2, 8)
Call CopyMemory(var1 , var1 Xor var3, 8)

Be VERY careful as longs are still only 4 bytes.
you WILL be corrupting memory with this code.
>now here is the problem. even though the data source for bytearray() and
bytearray2() are different, for some reason or other they both have the
same value. var2 needs to be a value from the second data source. i hope
this is a clear indication of what i am trying to do.

It still doesn't explain what you have and what results you want at the
end...

--
Dean Earley (de*********@ic ode.co.uk)
i-Catcher Development Team

iCode Systems

Feb 15 '07 #6
the data is from the full ascii range
"Dean Earley" <de*********@ic ode.co.ukwrote in message
news:45******** **************@ news.zen.co.uk. ..
Dean Earley wrote:
>Antony Clements wrote:
>>bytearray() = Mid(stream1, b, 8)
bytearray2( ) = Mid(stream2, c, 8) 'a messagebox here proves that at this
point, the data held in bytearray() is different than the data held in
bytearray2( )

This copies a UNICODE string into the byte array.
This will be 16 bytes, every other one being a null character.

If you want each character as an item in the array, then you want:
bytearray = StrConv(string, vbFromUnicode)

This does assume a normal ANSI string. It will be longer if you have non
ANSI data in your string

--
Dean Earley (de*********@ic ode.co.uk)
i-Catcher Development Team

iCode Systems

Feb 15 '07 #7
i eralilse what i said i'm trying to do is quite vague. the purpose of the
code is the core of a stream cipher where they key is defined as

key = var1 xor var2 xor var3 where var3 is (2147483647 * rnd). what happens
next is cipherbyte = chr((messagebyt e xor key) mod 256)
>Call CopyMemory(var1 , var1 Xor var2, 8)
Call CopyMemory(var1 , var1 Xor var3, 8)
does actually work as written.

the problem is that var1 and var2 are always the same constant no matter
what the source is.

"Dean Earley" <de*********@ic ode.co.ukwrote in message
news:45******** *************** @news.zen.co.uk ...
Antony Clements wrote:
>i modified the code after i posted this, it no longer throws up an error
but it still doesn't work correctly.

dim var1 var2 and var3 as long

ReDim IVbytearray(0 To 7)
ReDim IVbytearray2(0 To 7)

These are redundant as they are replaced in the next block.
>bytearray() = Mid(stream1, b, 8)
bytearray2() = Mid(stream2, c, 8) 'a messagebox here proves that at this
point, the data held in bytearray() is different than the data held in
bytearray2()

This copies a UNICODE string into the byte array.
This will be 16 bytes, every other one being a null character.

If you want each character as an item in the array, then you want:
bytearray = StrConv(string, vbFromUnicode)
>var1 = bytearray()
var2 = bytearray2() 'this is where the problem is as var2 returns the
same value as var1 even though the value in bytearray() is different to
the value in bytearray2().

From the code below, you can't join them up like this.
You will need to do the arithmetic manually (shifting and adding) or
copymemory from the byte array to a long.
Bear in mind that you can only fit 4 bytes in a long...
>Call CopyMemory(var1 , var1 Xor var2, 8)
Call CopyMemory(var1 , var1 Xor var3, 8)

Be VERY careful as longs are still only 4 bytes.
you WILL be corrupting memory with this code.
>now here is the problem. even though the data source for bytearray() and
bytearray2() are different, for some reason or other they both have the
same value. var2 needs to be a value from the second data source. i hope
this is a clear indication of what i am trying to do.

It still doesn't explain what you have and what results you want at the
end...

--
Dean Earley (de*********@ic ode.co.uk)
i-Catcher Development Team

iCode Systems

Feb 16 '07 #8
On Fri, 16 Feb 2007 09:46:04 +1100, "Antony Clements"
<an************ *@optusnet.com. auwrote:
>if stream1 has a value of 1a2b3c4d i want bytearray() to return the asc
value of the string. the only way i know how to do this is take each
character convert to ascii and then place in a string and then place the
string in bytearray(). i'm looking for a simpler way. var1 and var2 are
always returning the value of 1306840 regardless. bytearray() will return
1a2b3c4d. i am copying the bytearray variables to long variables. the
problem will be solved once var1 and var2 are correct values.
I still don't follow what you are trying to do.

It looks as if you want to compute some sort of 32 bit number from an
8 character String.
Feb 16 '07 #9
Antony Clements wrote:
if stream1 has a value of 1a2b3c4d i want bytearray() to return the asc
value of the string. the only way i know how to do this is take each
character convert to ascii and then place in a string and then place the
string in bytearray().
As I said...
If you want each character as an item in the array, then you want:
bytearray = StrConv(string, vbFromUnicode)
From a string of "1a2b3c4d", this will give you an 8 item array
containing: 49, 97, 50, 98, 51, 99, 52, 100,

IF however, you want the 32bit equivalent of that hex encoded string (if
it is hex) then you will need to manually split it on every two
characters and pass it through val("&H" & hexvalue) and store each part
in the array.

--
Dean Earley (de*********@ic ode.co.uk)
i-Catcher Development Team

iCode Systems
Feb 16 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8567
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the column below. The viewer can select states from the drop down lists above the other two columns as well. If the viewer selects only one, only one column fills. If the viewer selects two states, two columns fill. Etc. I could, if appropriate, have...
0
3075
by: FreeStyle | last post by:
Hi everybody, I'm using phpMyAdmin 2.2.6 with EasyPHP v.1.6.0.0 I wrote a php script which uses a username (added in the mysql base with phpMyAdmin). This user has no privileges. But in the script, I have the following request for the same username : INSERT TO table (...) VALUES (....) And it's working !!! The user can insert new rows with the php script to the database and he has no privileges. How it can be possible ?
3
6571
by: Marcus | last post by:
I'm really confused with something I never had any problems with before... I have a form with a textbox called password. On the second page that $password is posted to, if I test isset($password) after a submit, it always evaluates to true, regardless of whether or not anything was entered into the textbox... echoing the value simply echoes its contents, which is an empty string. If I test for simply if($password), however, that does...
2
4240
by: fartsniff | last post by:
hello all, here is a preg_match routine that i am using. basically, $image is set in some code above, and it can be either st-1.gif or sb-1.gif (actually it randomly picks them from about 100 gifs). then it processes them based off of which image type it selected, either the st- 's or the sb- 's.
2
8520
by: Fredrik Jonson | last post by:
Hello, I'm writing a newsletter poster for a website. I have some html news items which I want to turn into plain text and prettify before emailing it. Now, i have found wordwrap and strip_tags so the only problem remaining is the links. Below you see what I like to see, but I haven't got a clue how to get there.
0
2192
by: Aldo Polli | last post by:
Hi, I have this error when I start apache2 with php4 Syntax error on line 233 of /mypath/apache2/conf/httpd.conf: Cannot load /mypath/apache2/modules/libphp4.so into server: dynamic linker: /mypath/apache2/bin/httpd: relocation error: symbol not found: ap_pass_brigade; referenced from: /mypath/apache2/modules/libphp4.so I compile apache 2.0.46 with
2
6089
by: Marcus | last post by:
I am having some problems with trying to perform calculations on time fields. Say I have a start time and an end time, 1:00:00 and 2:30:00 (on a 24 hour scale, not 12). I want to find the difference in minutes, divide this result by a predefined size of interval, and make a loop that runs this many times. For example, with an interval size of 15 minutes, it will return 6 blocks... I have this all working fine, but am getting stuck on...
1
3419
by: phpkid | last post by:
Howdy I've been given conflicting answers about search engines picking up urls like: http://mysite.com/index.php?var1=1&var2=2&var3=3 Do search engines pick up these urls? I've been considering converting a site of mine to PHP-Nuke, but if the individual modules aren't picked up in search engines I'm not going to do it. Thanks phpKid
1
5780
by: Randell D. | last post by:
Folks, I have a string that *could* contain any character - I want it to call a function that will allow me to pass the variable, and then return it cleaned of anything except alphanumeric, dots, dashes and commas... How would I do this? I have a feeling preg_replace is what I need to use but regular expressions have always been over my head. I do know the syntax though (taken from a previous posting made some weeks ago) that I've been...
0
8469
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8814
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7419
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5684
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2800
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2042
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.