view dcrypt/misc/Bitwise.d @ 24:6428dfd7fede

Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
author Thomas Dixon <reikon@reikon.us>
date Thu, 19 Feb 2009 14:45:13 -0500
parents 4589f8c5eb3c
children 21847420b1ac
line wrap: on
line source

/**
 * This file is part of the dcrypt project.
 *
 * Copyright: Copyright (C) dcrypt contributors 2009. 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));    
    }
}