Olli
Olli

Reputation: 676

XOR encryption with only uppercase

Is there a way to receive only uppercase letters and digits from xor encryption? Or even better only uppercase letters? Or do I have to use something else?

static private byte[] encryption(byte[] input, byte[] key){
    byte[] out = new byte[input.length];
    for(int i = 0; i < input.length; i++){
        out[i] = (byte) (input[i] ^ key[i%key.length]);
    }
    return out;
}

I also want to decrypt it back again

Upvotes: 0

Views: 559

Answers (3)

rossum
rossum

Reputation: 15685

For uppercase and digits, then Base32 is one possibility. Alternatively, use Hex (i.e. Base16) but map the 16 hex digits to the first 16 letters of the alphabet. That will give you uppercase letters only at the expense of some extra programming and a doubled storage requirement. 8 bits of data is 16 bits of hex characters.

Upvotes: 1

Jiri Tousek
Jiri Tousek

Reputation: 12440

You'd have to create a kind of "custom XOR" - map the allowed inputs to first X numbers, XOR, then map them back.

Note that if you only allow uppercase letters in result, you can only allow so many different "letters" on input (the input and output alphabet needs to be same size).

Also note that XOR is very insecure unless used with a one-time pad. If the attacker can guess part of the input, he can XOR it with encrypted text and will see (part of) your password in plain text - all they need is to guess correctly part of input as long as your password.

Upvotes: 2

Kayaman
Kayaman

Reputation: 73558

You can add an additional encoding step after the encryption. If you wish to just receive printable characters and use standard approaches, Base64 encoding can be used.

If you want only uppercase letters or other custom format, you'll need to make your own encoder and decoder.

Upvotes: 0

Related Questions