Back to Cptr427Winter2010
{{{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DES
{
class DesUtility
{
///
/// We are using a 1's based numbering system from the right
///
/// 64-bit unsigned long data
/// a value between 1 and 64
/// a value between 1 and 64
///
public static ulong shiftBit(ulong input, int posIn, int posOut)
{
ulong output = 0;
input >>= posIn - 1;
input &= 1;
input <<= posOut - 1;
output |= input;
return output;
}
public static ulong reverseNumber(ulong input)
{
ulong output = 0;
for (int i = 1; i <= 64; i++)
{
ulong temp = shiftBit(input, i, 65 - i);
output |= temp;
}
return output;
}
///
/// Take the output position to be i and int input position to be
/// permutation[i] to create the output ulong value.
///
///
///
///
public static ulong Permutation(ulong input, int[] permutation)
{
ulong output = 0;
for (int i = 0; i < permutation.Length; i++)
{
output |= shiftBit(input, permutation[i], i + 1);
}
return output;
}
}
}
}}}