⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 purepermutationbif.java

📁 基于人工免疫原理的入侵检测系统框架
💻 JAVA
字号:
/*================= * Copyright (C) 2001  Todd Kaplan  * * Lisys is a program that monitors TCP SYN packets to detect network * traffic anomalies. * * Licensed under the GNU General Public License (GPL), version 2 or * higher.  Please see the COPYING and PATENT files included with the * Lisys distribution, which can be found at: * *   http://www.cs.unm.edu/~judd/lisys/ * * Also, the current text of the GPL can be found at:  * *   http://www.gnu.org/copyleft/gpl.html *  * Note that Lisys has NO WARRANTY! *=================*/package edu.unm.cs.lisys.detection.bif;import edu.unm.cs.lisys.debug.*;import edu.unm.cs.lisys.util.*;import edu.unm.cs.lisys.detection.*;import edu.unm.cs.lisys.detection.bip.*;import java.util.*;import java.io.*;/**========== * PurePermutationBIF.java *   A class that creates filters based on a pure permutation scheme * * Here are the people who have worked on this code in the order they * have worked on it: *   @author Todd Kaplan <kaplan@cs.unm.edu> *   @author Justin Balthrop <judd@cs.unm.edu> *==========*/public class PurePermutationBIF implements BinaryInputFilter, Serializable{    private int[] filter;    /**==========     * main:     *   A test program.     *==========*/    public static void main(String[] args)     {	KnuthRandom random = new KnuthRandom(100);	for (int i = 0; i < 5; i++) {	    BinaryInputFilter bif = (BinaryInputFilter) new PurePermutationBIF();	    bif.constructFilter(random, 49);	    BinaryInputPattern bip = (BinaryInputPattern) new TCPDump49BitBIP();	    bip.constructBinaryString(random);	    	    Debug.standard(bip.toString());	    Debug.standard(bif.toString());	    Debug.standard(bif.filter(bip).toString());	}    }        /**==========     * constructFilter:     *   Constructs a permutation for a number of bits.     *==========*/    public BinaryInputFilter constructFilter(KnuthRandom random, int numBits)    {	int[] filter = new int[numBits];	boolean[] used = new boolean[numBits];			for (int i = 0; i < numBits; i++) {	    int randInt;	    do {			randInt = random.intRange(numBits);	    } while  (used[randInt]);	    filter[i] = randInt;	    used[randInt] = true;	}	this.filter = filter;	return this;    }    /**==========     * filter:     *   Uses the permutation calculated before to permute the pattern     *   and return it.     *==========*/    public BinaryInputPattern filter(BinaryInputPattern bip)    {	BitSet bits = bip.getBinaryString();	int size = bip.getLength();	BitSet filteredBits = new BitSet(size);		for (int i = 0; i < size; i++) {	    int index = filter[i];	    if (bits.get(i) == true)		filteredBits.set(index);	}		// Create a new BIP of this type, set the bits, and return it.	BinaryInputPattern newBip = (BinaryInputPattern) bip.clone();	newBip.setBinaryString(filteredBits);	return newBip;    }        /**==========     * toString:     *   Returns the string representation of the filter     *==========*/    public String toString()    {	StringBuffer sb = new StringBuffer();	sb.append("[");	for (int i = 0; i < filter.length; i++)	    sb.append(filter[i] + " ");		sb.append("]");	return sb.toString();    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -