VB verse Java

Well, I supose that's an attention getter at least. But I have a related problem. I wrote a program a while back in Visual BASIC which did a simple unicode encryption. It took a password and added the value of letters within your password to the value of letters within your message to be encrypted. It then saved it as a sequential text file.

Now, when I went to decrypt these using the same algorythm(except backwards to decrypt) in Java I have serious logic errors. I get unicode values of 65,000 and something and 8,000 and something. Values that should never happen when two ASCII values are added together.

My best guess is that there is repetition in unicode, and some of the low end letters like e, m, and h are also up there in high numbers. And that Visual BASIC starts at the bottom and looks for your character equivalent, and Java looks at the top. This is just my guess. VB decrypts it correctly, not to mention faster.....

Basically, I need an algorythm to convert unicode values to integer values and then back to unicode. And it needs to work beyond 128! I know how to do it for A-z but I need to do it after z!

Thanks

[1167 byte] By [madcompnerda] at [2007-9-28 6:41:55]
# 1
try this: char c = 'x'; int i = (int) c;and vice versa
Sulthana at 2007-7-9 17:53:33 > top of Java-index,Other Topics,Algorithms...
# 2
Ok, I just need a way to read an ASCII file as an ASCII file, and not as unicode.Is there a way to read an ASCII file as ASCII and not unicode, or a way to take a string and make it ASCII instead of unicode?
madcompnerda at 2007-7-9 17:53:33 > top of Java-index,Other Topics,Algorithms...
# 3
Read it as bytes, using an InputStream and not a Reader. Likewise write it as bytes using an OutputStream and not a Writer. And don't ever convert it to chars, or to a String. Bytes only.
DrClapa at 2007-7-9 17:53:33 > top of Java-index,Other Topics,Algorithms...
# 4

I did that, and I get negative numbers and positive numbers. Obviously negative numbers aren't what I want.

I think I may just write a VB program to decrypt it all to regular characters(32-128) and then use Java to enxrypt it again. I think then Java will be able to deal with it. Obviously VB must use ASCII, or some odd unicode character set. Unless it's something wierd in Java. I need to expirament.

madcompnerda at 2007-7-9 17:53:33 > top of Java-index,Other Topics,Algorithms...
# 5
Numbers? What are you talking about? You were talking about letters before, where did the numbers suddenly come from?(And what does "get" mean in that post?)
DrClapa at 2007-7-9 17:53:33 > top of Java-index,Other Topics,Algorithms...
# 6

32-128 are integers, small letters, and capital letters, and punctuation in ASCII and also Unicode.

65 = A

66 = B

See where I'm coming from now? And numbers stored in a text file are quite similar to letters, they use the same method to store the two in text files.

Um by get, I mean that's what I read from the file. If I print out the contents of the array of integers that I read it into I get negative numbers.

madcompnerda at 2007-7-9 17:53:33 > top of Java-index,Other Topics,Algorithms...
# 7

Unicode has 2^32 characters, integers are numbers from -2^31 to 2^31.

When you are converting a Unicode character to an integer, obviously you get negative numbers, too.

If you want to read a text file encoded in ASCII. Try the following:

1) read it as byte array

2)use

String(byte[] bytes, String charsetName)

where charsetName = "US-ASCII"

If you want to write a Unicode text as ASCII, use:

[code]PrintStream(OutputStream out, boolean autoFlush, String encoding)/code]

where encoding = "US-ASCII"

Sulthana at 2007-7-9 17:53:33 > top of Java-index,Other Topics,Algorithms...