view dcrypt/misc/Bitwise.d @ 23:4589f8c5eb3c

Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
author Thomas Dixon <reikon@reikon.us>
date Sat, 14 Feb 2009 19:58:20 -0500
parents
children 6428dfd7fede
line wrap: on
line source

/**
 * This file is part of the dcrypt project.
 *
 * Copyright: Copyright (C) dcrypt contributors 2008. All rights reserved.
 * License:   MIT
 * Authors:   Thomas Dixon
 */

module dcrypt.misc.Bitwise;

/** Common bitwise operations */
struct Bitwise {
    
    static uint rotateLeft(uint x, int y) {
        return (x << y) | (x >> (32-y));
    }
    
    static uint rotateLeft(uint x, uint y) {
        return (x << y) | (x >> (32u-y));
    }
    
    static ulong rotateLeft(ulong x, int y) {
        return (x << y) | (x >> (64-y));
    }
    
    static ulong rotateLeft(ulong x, uint y) {
        return (x << y) | (x >> (64u-y));
    }
    
    static uint rotateRight(uint x, int y) {
        return (x >> y) | (x << (32-y));  
    }
    
    static uint rotateRight(uint x, uint y) {
        return (x >> y) | (x << (32u-y));    
    }
    
    static ulong rotateRight(ulong x, int y) {
        return (x >> y) | (x << (64-y));    
    }
    
    static ulong rotateRight(ulong x, uint y) {
        return (x >> y) | (x << (64u-y));    
    }
}