Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Convert a VB6 program into Java

807606Jun 1 2007 — edited Jun 1 2007
Hello everyone,

I have this small VB6 function needed to be converted properly into Java

This is the VB6 function
Public Function Crypt(ByVal Text As String) As String
    Dim X As Integer
    For X = 1 To Len(Text)
    Crypt = Crypt & Chr(Asc(Mid$(Text, Len(Text) - X + 1, 1)) Xor &HA5)
    Next X
End Function
It is just a function to invert and encrypt a string. And if you run Crypt(Crypt("10108"), it will give you "10108" back (because of the Xor operator)

My java equivalent is
    public static String crypt(String input)
    {
        int i = 0;
        int len = input.length();
        int a5 = 0xa5; // variable used in original VB code for encoding
        String cryptOutput = new String("");
        
        for (i = 0; i < input.length(); i++)
        {
            cryptOutput = cryptOutput + ((char)(((byte) input.charAt(len - i - 1)) ^ ((byte)a5)));
        }
        return cryptOutput;
    }
My java function also work in a sense that crypt(crypt("10108") also gives back "10108", but the my crypt("10108") output is different from the VB6 code Crypt("10108"). And it is important for them to be the same... I've been trying without success in finding out why...
Could someone point out to my why there is a difference? Thank you in advance :)

Could someone
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 29 2007
Added on Jun 1 2007
4 comments
306 views