All pastes #446929 Raw Edit

Something

public java v1 · immutable
·published 2007-04-18 19:05 UTC
rendered paste body
/** * The key stream uses the key for mutatation and secrecy in RC4. *  * @author Ståle Pettersen * */public class KeyStream {			/** Pseudo code **/	 	//	for  i = 0 to 255 do	//	S[i] = i;	//	T[i] = K[i mod keylen];	//	//		//	j = 0;	//	for  i = 0 to 255 do	//	  j = (j + S[i] + T[i]) mod 256;	//	  Swap (S[i], S[j]);	//		public int[] intializeSVector(int[] k) {				int s[] = new int[256];		int t[] = new int[256];		/** Intialization of S and T **/		System.out.println("Intialization of T:");		for(int i = 0; i < 256; i++) {			s[i] = i;			t[i] = k[i % k.length ];			System.out.print(i+"=["+t[i]+"".toString()+"],");		}		System.out.println();				/** Intial Permutation of S **/		System.out.println("Intial Permuatation of S:");		int j = 0;		for(int i = 0; i < 256; i++) {			j = (j + s[i] + t[i]) % 256;			int temp = s[j]; s[j] = s[i]; s[i] = temp; 		// Swap s[i] with s[j] || swap( s[i], s[j] )			System.out.print(i+"=["+s[i]+"".toString()+"],");		}		System.out.println();				return s;	}		/** Pseudo code **/	 	//		i, j = 0;	//		while (true)	//		  i = (i + 1) mod 256;	//		  j = (j + S[i]) mod 256;	//		  Swap (S[i], S[j]);	//		  t = (S[i] + S[j]) mod 256;	//		  k = S[t];		 	public void createKeyStream(int[] s) {		int k;  // Key stream		int counter = 0; // We only want 256 bytes of key stream		int i = 0;		int j = 0;		int t = 0;		System.out.println("Key stream:");		while(true) {									i = (i + 1) % 256;			j = (j + s[i]) % 256;			int temp = s[j]; s[j] = s[i]; s[i] = temp; // Swap s[i] with s[j]			t = ( s[i] + s[j]) % 256;			k = s[t];			System.out.print(counter+"=["+k+"],");			if(counter == 255) {								break;			}			counter++;		}		System.out.println("\nFinished making 256 bytes of key stream");	}}