wokier / gwt-crypto

Automatically exported from code.google.com/p/gwt-crypto
8 stars 1 forks source link

Can't decrypt not english text #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use in plain text letters = Ö Ä (German)
2. Encrypt value.
3. Decrypt value and instead of Ö Ä we have ???

What is the expected output? What do you see instead?
we must have a correct value with letters ÖÄ

What version of the product are you using? On what operating system?
version 1.0.1. Windows XP SP2.

Please provide any additional information below.
key = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
German letters
plain text = öää
cipher text = 77fbac9cc68a8557
decrypt value = ?¦¦

Original issue reported on code.google.com by stsefane...@gmail.com on 3 Sep 2009 at 10:57

GoogleCodeExporter commented 9 years ago
Quick Fix for good job.

package com.googlecode.gwt.crypto.util;

public class Str {
    private static int[] delta;

    public static byte[] toBytes(char[] inputChars) {
        byte[] out = new byte[inputChars.length];
        delta = new int[inputChars.length];
    for (int i = 0; i < inputChars.length; i++) {
        out[i] = (byte) inputChars[i];
            delta[i] = (int) inputChars[i] - out[i];
    }
    return out;
    }

    public static char[] toChars(byte[] in) {
    char[] out = new char[in.length];
    for (int i = 0; i < in.length; i++) {
            if (i < delta.length) {
                out[i] = (char) (in[i] + delta[i]);
            } else {
                out[i] = (char) in[i];
            }
        }
        return out;
    }
}

Original comment by stsefane...@gmail.com on 7 Sep 2009 at 11:17

GoogleCodeExporter commented 9 years ago
Thanks for your fix!

Checked it in, as well as a test that should keep this from happening again.

Original comment by moor...@gmail.com on 4 Oct 2009 at 3:52