package fugue;

/**
 * Represents a matrix in the GF(2^8) Galois field.
 * @author Martin Zoller
 *
 */
public class GFmatrix {
	
	short[][] data;
	
	void dump(String comment){
		for(int j=0;j0?"":" "+comment));
		}
				
	}
	

	private static short GFadd(short a,short b){
		return (short)(a^b);
	}

	private static short GFmult(short a, short b){
		short p = 0;
		short counter;
		short hi_bit_set;
		for(counter=0;counter<8;counter++){
			if((b & 1) == 1) 
				p ^= a;
			hi_bit_set=(short)(a & 0x80);
			a <<= 1;
			if(hi_bit_set == 0x80) 
				a ^= 0x1b;		
			b >>= 1;
		}
		return (short)(p%256);
	}
	
	public int length(int dim){
		if(dim==0)
			return data.length;
		else
			return data[0].length;
	}
	
	public short element(int col,int row){
		return data[col][row];
	}
	
	void multiplyBy(GFmatrix b){
		short[][] c=new short[b.length(0)][this.length(1)];
		if(this.length(0)!=b.length(1)) //# cols in A = # rows in B
			data=null; //Size mismatch
		for(int i=0;i0;i--){ //Rückwärts von letzter bis 2. Spalte von M
				for(int j=0;j Zeile(N)
			for(int j=0;j Spalte(N)
				N[j][i]=M[i][j];
		return N;
	}
	
	static short[][] GFmatrixAdd(short[][] A,short[][] B){
		if(A.length!=B.length || A[0].length!=B[0].length)
			return null; //size mismatch
		for(int i=0;i

Generated on Fri Sep 24 10:39:12 CEST 2010
Home