1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
5 * org.ibex.crypto.RC4 - By Brian Alliet
6 * Copyright (C) 2004 Brian Alliet
9 package org.ibex.crypto;
11 public class RC4 implements Cipher {
12 private final byte[] s = new byte[256];
15 public RC4(byte[] k) {
16 for(int i=0;i<256;i++) s[i] = (byte)i;
17 for(int i=0,j=0;i<256;i++) {
18 j = (j + (s[i]&0xff) + (k[i%k.length]&0xff))&0xff;
25 public void process(byte[] in, int ip, byte[] out, int op, int len) {
29 for(int i=0;i<len;i++) {
31 y = (y + (s[x]&0xff)) & 0xff;
35 int t = ((s[x]&0xff) + (s[y]&0xff))&0xff;
37 out[op+i] = (byte)((in[ip+i]&0xff)^k);