Example usage for java.util BitSet valueOf

List of usage examples for java.util BitSet valueOf

Introduction

In this page you can find the example usage for java.util BitSet valueOf.

Prototype

public static BitSet valueOf(ByteBuffer bb) 

Source Link

Document

Returns a new bit set containing all the bits in the given byte buffer between its position and limit.

Usage

From source file:uk.co.infinityapps.rehpic.cipherblockmode.CipherBlockChainingMode.java

private byte[] xorCipherAndPlainText(byte[] cipherText, byte[] plainText) {
    final BitSet cipherTextBitSet = BitSet.valueOf(cipherText);
    final BitSet plainTextBitSet = BitSet.valueOf(plainText);
    cipherTextBitSet.xor(plainTextBitSet);
    return BitUtils.bitSetToByteArray(cipherTextBitSet, cipherText.length);
}

From source file:uk.co.infinityapps.rehpic.round.RoundFunctionImpl.java

public byte[] encrypt(byte[] blockData, final byte[][] subKeys) {
    for (byte[] subKey : subKeys) {
        blockData = mixingPermutator.mix(blockData);
        blockData = permutator.shiftLeft(blockData, subKey);
        final BitSet blockBitSet = BitSet.valueOf(blockData);
        blockBitSet.xor(BitSet.valueOf(subKey));
        blockData = substitutionBox.subtitute(BitUtils.bitSetToByteArray(blockBitSet, blockData.length),
                subKey);//from   w w  w.  j a v  a2s .  c  om
    }
    return blockData;
}

From source file:uk.co.infinityapps.rehpic.round.RoundFunctionImpl.java

public byte[] decrypt(byte[] blockData, final byte[][] subKeys) {
    final byte[][] reversedSubKeys = reverseSubKeysForDecryption(subKeys);

    for (byte[] subKey : reversedSubKeys) {
        blockData = substitutionBox.subtitute(blockData, subKey);
        BitSet xorBlockBitSet = BitSet.valueOf(blockData);
        xorBlockBitSet.xor(BitSet.valueOf(subKey));
        blockData = permutator.shiftRight(BitUtils.bitSetToByteArray(xorBlockBitSet, blockData.length), subKey);
        blockData = mixingPermutator.unmix(blockData);
    }//from   w w w.j  a  v a2  s.  c  om
    return blockData;
}