Thread View: borland.public.jbuilder.java.api
4 messages
4 total messages
Started by C.Roum
Mon, 26 May 2003 18:57
XOR
Author: C.Roum
Date: Mon, 26 May 2003 18:57
Date: Mon, 26 May 2003 18:57
20 lines
1526 bytes
1526 bytes
Hi,
I'm new to Java. I have an encrypted string which was encrypted with Delphi
routines and saved to my database.
I'm trying to decrypt it by using Java.
I encrypted that string by XOR with an array of bytes. lets say byte[] =
{1,2,3}. How can i decrypt it?
I tried sth like this:
int[] myKey = {1, 2, 3};
byte[] myEncryptedBytes = myEncryptedStr.getBytes();
for (int Index = 1; Index <= EncryptedBytes.length; Index++) {
myDecryptedBytes[Index - 1] = ((myEncryptedBytes[Index - 1] & 0xff) ^
myKey[Index % 3]);
}
how can i convet byte[] myDecryptedBytes to String? So that i can compare it
with my check string.
thanks,
Re: XOR
Author: Kevin Dean
Date: Tue, 27 May 2003 02:02
Date: Tue, 27 May 2003 02:02
40 lines
2195 bytes
2195 bytes
String s = new String(myDecryptedBytes);
--
Check out our latest white papers at
http://www.datadevelopment.com/papers/index.html
BladeNET Scores With Borland Enterprise Tools
Team Development with JBuilder and Borland Enterprise Server
Dolphin Data Development Ltd.
http://www.datadevelopment.com/
"C.Roum" <croum@edumail.com> wrote in message
news:3ed2640b@newsgroups.borland.com...
> Hi,
> I'm new to Java. I have an encrypted string which was encrypted with
Delphi
> routines and saved to my database.
> I'm trying to decrypt it by using Java.
> I encrypted that string by XOR with an array of bytes. lets say byte[] =
> {1,2,3}. How can i decrypt it?
> I tried sth like this:
>
> int[] myKey = {1, 2, 3};
> byte[] myEncryptedBytes = myEncryptedStr.getBytes();
>
> for (int Index = 1; Index <= EncryptedBytes.length; Index++) {
> myDecryptedBytes[Index - 1] = ((myEncryptedBytes[Index - 1] & 0xff)
^
> myKey[Index % 3]);
> }
>
> how can i convet byte[] myDecryptedBytes to String? So that i can compare
it
> with my check string.
>
> thanks,
>
>
>
Re: XOR
Author: C.Roum
Date: Tue, 27 May 2003 07:53
Date: Tue, 27 May 2003 07:53
17 lines
1611 bytes
1611 bytes
Hi,
I'm trying to decrypt sth like:
for (int Index = 1; Index <= EncryptedBytes.length; Index++) {
myDecryptedBytes[Index - 1] = ((myEncryptedBytes[Index - 1] & 0xff)
but i get "Error #: 355 : possible loss of precision: int, required: byte"
error.
actually myKey values are greater than 128 and I couldnt define myKey values
as byte[].
java's byte is -128 to +128. Delphi's byte is 0..256. I think problem arises
from that point.
How can i decrypt a String which is UTF8 encoded by using XOR with a key
values which are greater than 128? Then finally decrypted array should be
converted to String.
Is it possible?
Re: XOR
Author: Kevin Dean
Date: Tue, 27 May 2003 13:47
Date: Tue, 27 May 2003 13:47
42 lines
2448 bytes
2448 bytes
If you're doing pure bit manipulation, there shouldn't be any sign problems.
However, because all operations are of type int, you can just cast the
result back to byte as follows:
for (int Index = 1; Index <= EncryptedBytes.length; Index++) {
myDecryptedBytes[Index - 1] = (byte)((myEncryptedBytes[Index - 1] &
0xff);
--
Check out our latest white papers at
http://www.datadevelopment.com/papers/index.html
BladeNET Scores With Borland Enterprise Tools
Team Development with JBuilder and Borland Enterprise Server
Dolphin Data Development Ltd.
http://www.datadevelopment.com/
"C.Roum" <croum@edumail.com> wrote in message
news:3ed31980@newsgroups.borland.com...
> Hi,
>
> I'm trying to decrypt sth like:
> for (int Index = 1; Index <= EncryptedBytes.length; Index++) {
> myDecryptedBytes[Index - 1] = ((myEncryptedBytes[Index - 1] &
0xff)
>
> but i get "Error #: 355 : possible loss of precision: int, required: byte"
> error.
>
> actually myKey values are greater than 128 and I couldnt define myKey
values
> as byte[].
> java's byte is -128 to +128. Delphi's byte is 0..256. I think problem
arises
> from that point.
> How can i decrypt a String which is UTF8 encoded by using XOR with a key
> values which are greater than 128? Then finally decrypted array should be
> converted to String.
> Is it possible?
>
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads